Kajetan Johannes Hammerle 2 meses atrás
pai
commit
fadee0adc3
5 arquivos alterados com 94 adições e 129 exclusões
  1. 1 0
      CMakeLists.txt
  2. 0 93
      old/MathTests.cpp
  3. 1 0
      test/Main.cpp
  4. 92 0
      test/modules/MathTests.cpp
  5. 0 36
      test/modules/UtilityTests.cpp

+ 1 - 0
CMakeLists.txt

@@ -54,6 +54,7 @@ set(SRC_TESTS
     "test/modules/ListTests.cpp"
     "test/modules/UniquePointerTests.cpp"
     "test/modules/VectorTests.cpp"
+    "test/modules/MathTests.cpp"
 )
 
 set(SRC_PERFORMANCE

+ 0 - 93
old/MathTests.cpp

@@ -1,93 +0,0 @@
-#include "../Tests.hpp"
-#include "core/math/Math.hpp"
-
-constexpr float eps = 0.0001f;
-
-namespace CMath = Core::Math;
-
-static void testInterpolate() {
-    CORE_TEST_FLOAT(7.5f, CMath::interpolate(5.0f, 10.0f, 0.5f), eps);
-    CORE_TEST_FLOAT(-2.0, CMath::interpolate(-10.0f, 10.0f, 0.4f), eps);
-    CORE_TEST_FLOAT(10.0f, CMath::interpolate(-3.0f, 10.0f, 1.0f), eps);
-    CORE_TEST_FLOAT(7.0f, CMath::interpolate(7.0f, 10.0f, 0.0f), eps);
-    CORE_TEST_FLOAT(6.0f, CMath::interpolate(0.0f, 10.0f, 0.6f), eps);
-}
-
-static void testIsPowerOf2() {
-    CORE_TEST_TRUE(CMath::isPowerOf2(1));
-    CORE_TEST_TRUE(CMath::isPowerOf2(2));
-    CORE_TEST_FALSE(CMath::isPowerOf2(3));
-    CORE_TEST_TRUE(CMath::isPowerOf2(4));
-    CORE_TEST_FALSE(CMath::isPowerOf2(5));
-    CORE_TEST_FALSE(CMath::isPowerOf2(6));
-    CORE_TEST_FALSE(CMath::isPowerOf2(7));
-    CORE_TEST_TRUE(CMath::isPowerOf2(8));
-    CORE_TEST_FALSE(CMath::isPowerOf2(9));
-    CORE_TEST_FALSE(CMath::isPowerOf2(10));
-    for(int i = 16; i < 30000; i *= 2) {
-        CORE_TEST_TRUE(CMath::isPowerOf2(i));
-        CORE_TEST_FALSE(CMath::isPowerOf2(i + 1));
-        CORE_TEST_FALSE(CMath::isPowerOf2(i + 2));
-        CORE_TEST_FALSE(CMath::isPowerOf2(i + 3));
-    }
-}
-
-static void testRoundUpLog2() {
-    CORE_TEST_EQUAL(0, CMath::roundUpLog2(-5));
-    CORE_TEST_EQUAL(0, CMath::roundUpLog2(0));
-    CORE_TEST_EQUAL(1, CMath::roundUpLog2(1));
-    CORE_TEST_EQUAL(1, CMath::roundUpLog2(2));
-    CORE_TEST_EQUAL(2, CMath::roundUpLog2(3));
-    CORE_TEST_EQUAL(2, CMath::roundUpLog2(4));
-    CORE_TEST_EQUAL(3, CMath::roundUpLog2(5));
-    CORE_TEST_EQUAL(4, CMath::roundUpLog2(10));
-    CORE_TEST_EQUAL(5, CMath::roundUpLog2(20));
-    CORE_TEST_EQUAL(16, CMath::roundUpLog2(35345));
-    CORE_TEST_EQUAL(31, CMath::roundUpLog2(0x7FFFFFFF));
-}
-
-static void testMin() {
-    CORE_TEST_EQUAL(-5, CMath::min(-5));
-    CORE_TEST_EQUAL(-10, CMath::min(-5, 4, 3, 2, -10));
-    CORE_TEST_EQUAL(4, CMath::min(5, 20, 4, 30));
-}
-
-static void testMax() {
-    CORE_TEST_EQUAL(-5, CMath::max(-5));
-    CORE_TEST_EQUAL(4, CMath::max(-5, 4, 3, 2, -10));
-    CORE_TEST_EQUAL(30, CMath::max(5, 20, 4, 30));
-}
-
-static void testClamp() {
-    CORE_TEST_EQUAL(5, CMath::clamp(1, 5, 10));
-    CORE_TEST_EQUAL(7, CMath::clamp(7, 5, 10));
-    CORE_TEST_EQUAL(10, CMath::clamp(20, 5, 10));
-    CORE_TEST_EQUAL(5, CMath::clamp(1, 10, 5));
-    CORE_TEST_EQUAL(7, CMath::clamp(7, 10, 5));
-    CORE_TEST_EQUAL(10, CMath::clamp(20, 10, 5));
-}
-
-static void testRadianToDegree() {
-    CORE_TEST_FLOAT(45.0f, CMath::radianToDegree(CMath::PI * 0.25f), eps);
-    CORE_TEST_FLOAT(90.0f, CMath::radianToDegree(CMath::PI * 0.5f), eps);
-    CORE_TEST_FLOAT(180.0f, CMath::radianToDegree(CMath::PI), eps);
-    CORE_TEST_FLOAT(360.0f, CMath::radianToDegree(CMath::PI * 2.0f), eps);
-}
-
-static void testDegreeToRadian() {
-    CORE_TEST_FLOAT(CMath::PI * 0.25f, CMath::degreeToRadian(45.0f), eps);
-    CORE_TEST_FLOAT(CMath::PI * 0.5f, CMath::degreeToRadian(90.0f), eps);
-    CORE_TEST_FLOAT(CMath::PI, CMath::degreeToRadian(180.0f), eps);
-    CORE_TEST_FLOAT(CMath::PI * 2.0f, CMath::degreeToRadian(360.0f), eps);
-}
-
-void Core::testMath() {
-    testInterpolate();
-    testIsPowerOf2();
-    testRoundUpLog2();
-    testMin();
-    testMax();
-    testClamp();
-    testRadianToDegree();
-    testDegreeToRadian();
-}

+ 1 - 0
test/Main.cpp

@@ -65,6 +65,7 @@ int main(int argAmount, const char** args) {
     testList(light);
     testUniquePointer();
     testVector();
+    testMath();
     // testBitArray();
     // testBox();
     // testBuffer(light);

+ 92 - 0
test/modules/MathTests.cpp

@@ -0,0 +1,92 @@
+#include "../Tests.hpp"
+#include "core/Math.hpp"
+#include "core/Test.hpp"
+
+constexpr float eps = 0.0001f;
+
+static void testInterpolate() {
+    TEST_FLOAT(7.5f, Core::interpolate(5.0f, 10.0f, 0.5f), eps);
+    TEST_FLOAT(-2.0, Core::interpolate(-10.0f, 10.0f, 0.4f), eps);
+    TEST_FLOAT(10.0f, Core::interpolate(-3.0f, 10.0f, 1.0f), eps);
+    TEST_FLOAT(7.0f, Core::interpolate(7.0f, 10.0f, 0.0f), eps);
+    TEST_FLOAT(6.0f, Core::interpolate(0.0f, 10.0f, 0.6f), eps);
+}
+
+static void testIsPowerOf2() {
+    TEST_TRUE(Core::isPowerOf2(1));
+    TEST_TRUE(Core::isPowerOf2(2));
+    TEST_FALSE(Core::isPowerOf2(3));
+    TEST_TRUE(Core::isPowerOf2(4));
+    TEST_FALSE(Core::isPowerOf2(5));
+    TEST_FALSE(Core::isPowerOf2(6));
+    TEST_FALSE(Core::isPowerOf2(7));
+    TEST_TRUE(Core::isPowerOf2(8));
+    TEST_FALSE(Core::isPowerOf2(9));
+    TEST_FALSE(Core::isPowerOf2(10));
+    for(int i = 16; i < 30'000; i *= 2) {
+        TEST_TRUE(Core::isPowerOf2(i));
+        TEST_FALSE(Core::isPowerOf2(i + 1));
+        TEST_FALSE(Core::isPowerOf2(i + 2));
+        TEST_FALSE(Core::isPowerOf2(i + 3));
+    }
+}
+
+static void testRoundUpLog2() {
+    TEST(0, Core::roundUpLog2(-5));
+    TEST(0, Core::roundUpLog2(0));
+    TEST(1, Core::roundUpLog2(1));
+    TEST(1, Core::roundUpLog2(2));
+    TEST(2, Core::roundUpLog2(3));
+    TEST(2, Core::roundUpLog2(4));
+    TEST(3, Core::roundUpLog2(5));
+    TEST(4, Core::roundUpLog2(10));
+    TEST(5, Core::roundUpLog2(20));
+    TEST(16, Core::roundUpLog2(35'345));
+    TEST(31, Core::roundUpLog2(0x7FFF'FFFF));
+}
+
+static void testMin() {
+    TEST(-5, Core::min(-5));
+    TEST(-10, Core::min(-5, 4, 3, 2, -10));
+    TEST(4, Core::min(5, 20, 4, 30));
+}
+
+static void testMax() {
+    TEST(-5, Core::max(-5));
+    TEST(4, Core::max(-5, 4, 3, 2, -10));
+    TEST(30, Core::max(5, 20, 4, 30));
+}
+
+static void testClamp() {
+    TEST(5, Core::clamp(1, 5, 10));
+    TEST(7, Core::clamp(7, 5, 10));
+    TEST(10, Core::clamp(20, 5, 10));
+    TEST(5, Core::clamp(1, 10, 5));
+    TEST(7, Core::clamp(7, 10, 5));
+    TEST(10, Core::clamp(20, 10, 5));
+}
+
+static void testRadianToDegree() {
+    TEST_FLOAT(45.0f, Core::radianToDegree(Core::PI * 0.25f), eps);
+    TEST_FLOAT(90.0f, Core::radianToDegree(Core::PI * 0.5f), eps);
+    TEST_FLOAT(180.0f, Core::radianToDegree(Core::PI), eps);
+    TEST_FLOAT(360.0f, Core::radianToDegree(Core::PI * 2.0f), eps);
+}
+
+static void testDegreeToRadian() {
+    TEST_FLOAT(Core::PI * 0.25f, Core::degreeToRadian(45.0f), eps);
+    TEST_FLOAT(Core::PI * 0.5f, Core::degreeToRadian(90.0f), eps);
+    TEST_FLOAT(Core::PI, Core::degreeToRadian(180.0f), eps);
+    TEST_FLOAT(Core::PI * 2.0f, Core::degreeToRadian(360.0f), eps);
+}
+
+void testMath() {
+    testInterpolate();
+    testIsPowerOf2();
+    testRoundUpLog2();
+    testMin();
+    testMax();
+    testClamp();
+    testRadianToDegree();
+    testDegreeToRadian();
+}

+ 0 - 36
test/modules/UtilityTests.cpp

@@ -6,8 +6,6 @@
 #include "core/ToString.hpp"
 #include "core/Utility.hpp"
 
-static const float eps = 0.0001f;
-
 static void testPopCount() {
     TEST(4, Core::popCount(0xF));
     TEST(0, Core::popCount(0x0));
@@ -53,28 +51,6 @@ static void testZeroAllocate() {
     Core::deallocateRaw(b);
 }
 
-static void testInterpolate() {
-    TEST_FLOAT(7.5f, Core::interpolate(5.0f, 10.0f, 0.5f), eps);
-    TEST_FLOAT(-2.0, Core::interpolate(-10.0f, 10.0f, 0.4f), eps);
-    TEST_FLOAT(10.0f, Core::interpolate(-3.0f, 10.0f, 1.0f), eps);
-    TEST_FLOAT(7.0f, Core::interpolate(7.0f, 10.0f, 0.0f), eps);
-    TEST_FLOAT(6.0f, Core::interpolate(0.0f, 10.0f, 0.6f), eps);
-}
-
-static void testRadianToDegree() {
-    TEST_FLOAT(45.0f, Core::radianToDegree(Core::PI * 0.25f), eps);
-    TEST_FLOAT(90.0f, Core::radianToDegree(Core::PI * 0.5f), eps);
-    TEST_FLOAT(180.0f, Core::radianToDegree(Core::PI), eps);
-    TEST_FLOAT(360.0f, Core::radianToDegree(Core::PI * 2.0f), eps);
-}
-
-static void testDegreeToRadian() {
-    TEST_FLOAT(Core::PI * 0.25f, Core::degreeToRadian(45.0f), eps);
-    TEST_FLOAT(Core::PI * 0.5f, Core::degreeToRadian(90.0f), eps);
-    TEST_FLOAT(Core::PI, Core::degreeToRadian(180.0f), eps);
-    TEST_FLOAT(Core::PI * 2.0f, Core::degreeToRadian(360.0f), eps);
-}
-
 static void testSleep(i64 nanos) {
     i64 time = -Core::getNanos();
     TEST_FALSE(Core::sleepNanos(nanos));
@@ -126,14 +102,6 @@ static void testSort() {
     }
 }
 
-static void testMinMax() {
-    TEST(5, Core::min<int>(5, 7));
-    TEST(7, Core::max<int>(5, 7));
-    TEST(5, Core::clamp<int>(3, 5, 7));
-    TEST(7, Core::clamp<int>(9, 5, 7));
-    TEST(6, Core::clamp<int>(6, 5, 7));
-}
-
 static void testToString() {
     char buffer[512];
     TEST(10, formatBuffer(buffer, sizeof(buffer), "a#a##a", 1.0, 2, 3));
@@ -157,9 +125,6 @@ void testUtility(bool light) {
     testZeroRellocate();
     testMemoryInfoList();
     testZeroAllocate();
-    testInterpolate();
-    testRadianToDegree();
-    testDegreeToRadian();
     testSleep(light ? 5'000'000 : 50'000'000);
     testSleep(light ? 50'000'000 : 1'300'000'000);
     testSleepMillis(light ? 5 : 50);
@@ -167,7 +132,6 @@ void testUtility(bool light) {
     testSwap();
     testFail();
     testSort();
-    testMinMax();
     testToString();
 }