aboutsummaryrefslogtreecommitdiff
path: root/zencore/intmath.cpp
diff options
context:
space:
mode:
authorMartin Ridgers <[email protected]>2021-09-14 14:25:46 +0200
committerMartin Ridgers <[email protected]>2021-09-14 15:44:00 +0200
commit22e1bfb58064637186b3112af4668c80f3492a86 (patch)
treef795962857781ec0ed1a7c31fc9acb631d87315d /zencore/intmath.cpp
parentDefine _CRT_SECURE_NO_WARNINGS (diff)
downloadzen-22e1bfb58064637186b3112af4668c80f3492a86.tar.xz
zen-22e1bfb58064637186b3112af4668c80f3492a86.zip
Added test case for some of intmath.h's functions
Diffstat (limited to 'zencore/intmath.cpp')
-rw-r--r--zencore/intmath.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/zencore/intmath.cpp b/zencore/intmath.cpp
new file mode 100644
index 000000000..4039a3b39
--- /dev/null
+++ b/zencore/intmath.cpp
@@ -0,0 +1,56 @@
+// Copyright Epic Games, Inc. All Rights Reserved.
+
+#include <zencore/intmath.h>
+
+#include <doctest/doctest.h>
+
+namespace zen {
+
+//////////////////////////////////////////////////////////////////////////
+//
+// Testing related code follows...
+//
+
+void
+intmath_forcelink()
+{
+}
+
+TEST_CASE("intmath")
+{
+ CHECK(FloorLog2(0x00) == 0);
+ CHECK(FloorLog2(0x01) == 0);
+ CHECK(FloorLog2(0x0f) == 3);
+ CHECK(FloorLog2(0x10) == 4);
+ CHECK(FloorLog2(0x11) == 4);
+ CHECK(FloorLog2(0x12) == 4);
+ CHECK(FloorLog2(0x22) == 5);
+ CHECK(FloorLog2(0x0001'0000) == 16);
+ CHECK(FloorLog2(0x0001'000f) == 16);
+ CHECK(FloorLog2(0x8000'0000) == 31);
+
+ CHECK(FloorLog2_64(0x00ull) == 0);
+ CHECK(FloorLog2_64(0x01ull) == 0);
+ CHECK(FloorLog2_64(0x0full) == 3);
+ CHECK(FloorLog2_64(0x10ull) == 4);
+ CHECK(FloorLog2_64(0x11ull) == 4);
+ CHECK(FloorLog2_64(0x0001'0000ull) == 16);
+ CHECK(FloorLog2_64(0x0001'000full) == 16);
+ CHECK(FloorLog2_64(0x8000'0000ull) == 31);
+ CHECK(FloorLog2_64(0x0000'0001'0000'0000ull) == 32);
+ CHECK(FloorLog2_64(0x8000'0000'0000'0000ull) == 63);
+
+ CHECK(CountLeadingZeros64(0x8000'0000'0000'0000ull) == 0);
+ CHECK(CountLeadingZeros64(0x0000'0000'0000'0000ull) == 64);
+ CHECK(CountLeadingZeros64(0x0000'0000'0000'0001ull) == 63);
+ CHECK(CountLeadingZeros64(0x0000'0000'8000'0000ull) == 32);
+ CHECK(CountLeadingZeros64(0x0000'0001'0000'0000ull) == 31);
+
+ CHECK(CountTrailingZeros64(0x8000'0000'0000'0000ull) == 63);
+ CHECK(CountTrailingZeros64(0x0000'0000'0000'0000ull) == 64);
+ CHECK(CountTrailingZeros64(0x0000'0000'0000'0001ull) == 0);
+ CHECK(CountTrailingZeros64(0x0000'0000'8000'0000ull) == 31);
+ CHECK(CountTrailingZeros64(0x0000'0001'0000'0000ull) == 32);
+}
+
+} // namespace zen