/* * 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/Int24.hpp" using namespace OpenVulkano; TEST_CASE("Default constructor", "[Int24]") { int24 a; REQUIRE(static_cast(a) == 0); } TEST_CASE("Integer constructor", "[Int24]") { int24 a(0x123456); REQUIRE(static_cast(a) == 0x123456); int24 b(-1); REQUIRE(static_cast(b) == -1); } TEST_CASE("Copy constructor", "[Int24]") { int24 a(0x123456); int24 b(a); REQUIRE(static_cast(b) == 0x123456); } TEST_CASE("Assignment operator", "[Int24]") { int24 a; a = 0x123456; REQUIRE(static_cast(a) == 0x123456); int24 b; b = a; REQUIRE(static_cast(b) == 0x123456); } TEST_CASE("Arithmetic operators", "[Int24]") { int24 a(0x10); int24 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", "[Int24]") { int24 a(0x10); int24 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", "[Int24]") { int24 a(0x100000); int24 b(0x200000); REQUIRE(a < b); REQUIRE(b > a); REQUIRE(a <= b); REQUIRE(b >= a); REQUIRE(a != b); int24 c(0x100000); REQUIRE(a == c); } TEST_CASE("Shift operators", "[Int24]") { int24 a(0x123456); REQUIRE(static_cast(a << 1) == 0x2468ac); REQUIRE(static_cast(a >> 1) == 0x91a2b); } TEST_CASE("Boolean operators", "[Int24]") { int24 a(0); int24 b(1); REQUIRE(!a); REQUIRE(b); } TEST_CASE("Negation", "[Int24]") { int24 a(0x123456); REQUIRE(static_cast(-a) == -0x123456); }