diff --git a/tests/Math/UInt24.cpp b/tests/Math/UInt24.cpp new file mode 100644 index 0000000..804a9a1 --- /dev/null +++ b/tests/Math/UInt24.cpp @@ -0,0 +1,110 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +#include + +#include "Math/UInt24.hpp" + +using namespace OpenVulkano; + +TEST_CASE("Default constructor", "[UInt24]") +{ + uint24 a; + REQUIRE(static_cast(a) == 0); +} + +TEST_CASE("Integer constructor", "[UInt24]") +{ + uint24 a(0x123456); + REQUIRE(static_cast(a) == 0x123456); + + uint24 b(-1); + REQUIRE(static_cast(b) == 0xffffff); +} + +TEST_CASE("Copy constructor", "[UInt24]") +{ + uint24 a(0x123456); + uint24 b(a); + REQUIRE(static_cast(b) == 0x123456); +} + +TEST_CASE("Assignment operator", "[UInt24]") +{ + uint24 a; + a = 0x123456; + REQUIRE(static_cast(a) == 0x123456); + + uint24 b; + b = a; + REQUIRE(static_cast(b) == 0x123456); +} + +TEST_CASE("Arithmetic operators", "[UInt24]") +{ + uint24 a(0x10); + uint24 b(0x20); + + REQUIRE(static_cast(a + b) == 0x30); + REQUIRE(static_cast(b - a) == 0x10); + REQUIRE(static_cast(a * b) == 0x200); + REQUIRE(static_cast(b / a) == 2); +} + +TEST_CASE("Compound assignment operators", "[UInt24]") +{ + uint24 a(0x10); + uint24 b(0x20); + + a += b; + REQUIRE(static_cast(a) == 0x30); + + a -= b; + REQUIRE(static_cast(a) == 0x10); + + a *= b; + REQUIRE(static_cast(a) == 0x200); + + a /= b; + REQUIRE(static_cast(a) == 0x10); +} + +TEST_CASE("Comparison operators", "[UInt24]") +{ + uint24 a(0x100000); + uint24 b(0x200000); + + REQUIRE(a < b); + REQUIRE(b > a); + REQUIRE(a <= b); + REQUIRE(b >= a); + REQUIRE(a != b); + + uint24 c(0x100000); + REQUIRE(a == c); +} + +TEST_CASE("Shift operators", "[UInt24]") +{ + uint24 a(0x123456); + REQUIRE(static_cast(a << 1) == 0x2468ac); + REQUIRE(static_cast(a >> 1) == 0x91a2b); +} + +TEST_CASE("Boolean operators", "[UInt24]") +{ + uint24 a(0); + uint24 b(1); + + REQUIRE(!a); + REQUIRE(b); +} + +TEST_CASE("Negation", "[UInt24]") +{ + uint24 a(0x123456); + REQUIRE(static_cast(-a) == 0xedcbaa); +} \ No newline at end of file