Tests for UInt24

This commit is contained in:
Vladyslav Baranovskyi
2024-11-10 19:46:44 +02:00
parent 9f39ecbe80
commit 373a6acd77

110
tests/Math/UInt24.cpp Normal file
View File

@@ -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 <catch2/catch_all.hpp>
#include "Math/UInt24.hpp"
using namespace OpenVulkano;
TEST_CASE("Default constructor", "[UInt24]")
{
uint24 a;
REQUIRE(static_cast<int>(a) == 0);
}
TEST_CASE("Integer constructor", "[UInt24]")
{
uint24 a(0x123456);
REQUIRE(static_cast<int>(a) == 0x123456);
uint24 b(-1);
REQUIRE(static_cast<int>(b) == 0xffffff);
}
TEST_CASE("Copy constructor", "[UInt24]")
{
uint24 a(0x123456);
uint24 b(a);
REQUIRE(static_cast<int>(b) == 0x123456);
}
TEST_CASE("Assignment operator", "[UInt24]")
{
uint24 a;
a = 0x123456;
REQUIRE(static_cast<int>(a) == 0x123456);
uint24 b;
b = a;
REQUIRE(static_cast<int>(b) == 0x123456);
}
TEST_CASE("Arithmetic operators", "[UInt24]")
{
uint24 a(0x10);
uint24 b(0x20);
REQUIRE(static_cast<int>(a + b) == 0x30);
REQUIRE(static_cast<int>(b - a) == 0x10);
REQUIRE(static_cast<int>(a * b) == 0x200);
REQUIRE(static_cast<int>(b / a) == 2);
}
TEST_CASE("Compound assignment operators", "[UInt24]")
{
uint24 a(0x10);
uint24 b(0x20);
a += b;
REQUIRE(static_cast<int>(a) == 0x30);
a -= b;
REQUIRE(static_cast<int>(a) == 0x10);
a *= b;
REQUIRE(static_cast<int>(a) == 0x200);
a /= b;
REQUIRE(static_cast<int>(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<int>(a << 1) == 0x2468ac);
REQUIRE(static_cast<int>(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<int>(-a) == 0xedcbaa);
}