From 19289bf1b5426af28b7dbc7ec8a243317e4fb129 Mon Sep 17 00:00:00 2001 From: Vladyslav Baranovskyi Date: Tue, 8 Oct 2024 12:37:23 +0300 Subject: [PATCH] tests file for int24 --- tests/Math/Int24.cpp | 110 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 tests/Math/Int24.cpp diff --git a/tests/Math/Int24.cpp b/tests/Math/Int24.cpp new file mode 100644 index 0000000..28da207 --- /dev/null +++ b/tests/Math/Int24.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/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); +} \ No newline at end of file