Browse Source

test cleanup

Kajetan Johannes Hammerle 1 year ago
parent
commit
dac677d3d1
4 changed files with 40 additions and 57 deletions
  1. 2 4
      tests/ArrayListTests.cpp
  2. 4 4
      tests/ArrayStringTests.cpp
  3. 34 37
      tests/HashMapTests.cpp
  4. 0 12
      utils/HashCode.h

+ 2 - 4
tests/ArrayListTests.cpp

@@ -50,16 +50,14 @@ static void testClear(Core::Test& test) {
 static void testOverflow(Core::Test& test) {
     IntList list;
     for(int i = 0; i < 20; i++) {
-        test.checkEqual(false, list.add(i),
-                        "add returns false without overflow");
+        test.checkFalse(list.add(i), "add returns false without overflow");
     }
     for(int i = 0; i < 1000000; i++) {
-        test.checkEqual(true, list.add(i), "add returns true with overflow");
+        test.checkTrue(list.add(i), "add returns true with overflow");
     }
     for(int i = 0; i < list.getLength(); i++) {
         test.checkEqual(i, list[i], "still contains values after overflow");
     }
-    test.checkEqual(true, true, "survives overflow");
 }
 
 static void testCopy(Core::Test& test) {

+ 4 - 4
tests/ArrayStringTests.cpp

@@ -260,10 +260,10 @@ static void testAsHashMapKey(Core::Test& test) {
     int* c = map.search(build(test, "baum123"));
     int* d = map.search(build(test, "423hifd"));
 
-    test.checkEqual(true, a != nullptr, "strings works as hash key 1");
-    test.checkEqual(true, b != nullptr, "strings works as hash key 2");
-    test.checkEqual(true, c != nullptr, "strings works as hash key 3");
-    test.checkEqual(true, d == nullptr, "strings works as hash key 4");
+    test.checkTrue(a != nullptr, "strings works as hash key 1");
+    test.checkTrue(b != nullptr, "strings works as hash key 2");
+    test.checkTrue(c != nullptr, "strings works as hash key 3");
+    test.checkTrue(d == nullptr, "strings works as hash key 4");
 
     if(a != nullptr && b != nullptr && c != nullptr) {
         test.checkEqual(3, *a, "strings works as hash key 1");

+ 34 - 37
tests/HashMapTests.cpp

@@ -17,7 +17,7 @@ static void testAdd(Core::Test& test) {
     IntMap map;
     test.checkFalse(map.add(5, 4), "add works 1");
     int* value = map.search(5);
-    test.checkEqual(true, value != nullptr, "contains added value");
+    test.checkTrue(value != nullptr, "contains added value");
     if(value != nullptr) {
         test.checkEqual(4, *value, "search finds added value");
     }
@@ -28,15 +28,15 @@ static void testMultipleAdd(Core::Test& test) {
     test.checkFalse(map.add(5, 4), "add works 2");
     test.checkFalse(map.add(10, 3), "add works 3");
     test.checkFalse(map.add(15, 2), "add works 4");
-    test.checkEqual(true, map.contains(5), "contains added value 1");
-    test.checkEqual(true, map.contains(10), "contains added value 2");
-    test.checkEqual(true, map.contains(15), "contains added value 3");
+    test.checkTrue(map.contains(5), "contains added value 1");
+    test.checkTrue(map.contains(10), "contains added value 2");
+    test.checkTrue(map.contains(15), "contains added value 3");
     int* a = map.search(5);
     int* b = map.search(10);
     int* c = map.search(15);
-    test.checkEqual(true, a != nullptr, "contains added value 1");
-    test.checkEqual(true, b != nullptr, "contains added value 2");
-    test.checkEqual(true, c != nullptr, "contains added value 3");
+    test.checkTrue(a != nullptr, "contains added value 1");
+    test.checkTrue(b != nullptr, "contains added value 2");
+    test.checkTrue(c != nullptr, "contains added value 3");
     if(a != nullptr && b != nullptr && c != nullptr) {
         test.checkEqual(4, *a, "search finds added value 1");
         test.checkEqual(3, *b, "search finds added value 2");
@@ -46,17 +46,17 @@ static void testMultipleAdd(Core::Test& test) {
 
 static void testSearch(Core::Test& test) {
     IntMap map;
-    test.checkEqual(true, nullptr == map.search(6),
-                    "search does not find missing key");
+    test.checkTrue(nullptr == map.search(6),
+                   "search does not find missing key");
 }
 
 static void testAddReplace(Core::Test& test) {
     IntMap map;
     test.checkFalse(map.add(5, 4), "add works 5");
     test.checkFalse(map.add(5, 10), "add works 6");
-    test.checkEqual(true, map.contains(5), "contains replaced value");
+    test.checkTrue(map.contains(5), "contains replaced value");
     int* a = map.search(5);
-    test.checkEqual(true, a != nullptr, "contains replaced value");
+    test.checkTrue(a != nullptr, "contains replaced value");
     if(a != nullptr) {
         test.checkEqual(10, *a, "search finds replaced value");
     }
@@ -67,10 +67,8 @@ static void testClear(Core::Test& test) {
     test.checkFalse(map.add(5, 4), "add works 7");
     test.checkFalse(map.add(4, 10), "add works 8");
     map.clear();
-    test.checkEqual(false, map.contains(5),
-                    "does not contain cleared values 1");
-    test.checkEqual(false, map.contains(4),
-                    "does not contain cleared values 2");
+    test.checkFalse(map.contains(5), "does not contain cleared values 1");
+    test.checkFalse(map.contains(4), "does not contain cleared values 2");
 }
 
 static void testOverflow(Core::Test& test) {
@@ -81,7 +79,6 @@ static void testOverflow(Core::Test& test) {
     for(int i = 0; i < 1000000; i++) {
         test.checkTrue(map.contains(i), "still contains values after overflow");
     }
-    test.checkTrue(true, "survives overflow");
 }
 
 struct A {
@@ -121,9 +118,9 @@ static void testEmplace(Core::Test& test) {
     A* b = map.search(3);
     A* c = map.search(20);
 
-    test.checkEqual(true, a != nullptr, "contains emplaced value 1");
-    test.checkEqual(true, b != nullptr, "contains emplaced value 2");
-    test.checkEqual(true, c != nullptr, "contains emplaced value 3");
+    test.checkTrue(a != nullptr, "contains emplaced value 1");
+    test.checkTrue(b != nullptr, "contains emplaced value 2");
+    test.checkTrue(c != nullptr, "contains emplaced value 3");
 
     if(a != nullptr && b != nullptr && c != nullptr) {
         test.checkEqual(A(3, 4), *a, "contains emplaced value 1");
@@ -131,11 +128,11 @@ static void testEmplace(Core::Test& test) {
         test.checkEqual(A(5, 6), *c, "contains emplaced value 3");
     }
 
-    test.checkEqual(false, r1, "emplacing returns correct value 1");
-    test.checkEqual(false, r2, "emplacing returns correct value 2");
-    test.checkEqual(false, r3, "emplacing returns correct value 3");
-    test.checkEqual(true, r4, "emplacing returns correct value 4");
-    test.checkEqual(true, r5, "emplacing returns correct value 5");
+    test.checkFalse(r1, "emplacing returns correct value 1");
+    test.checkFalse(r2, "emplacing returns correct value 2");
+    test.checkFalse(r3, "emplacing returns correct value 3");
+    test.checkTrue(r4, "emplacing returns correct value 4");
+    test.checkTrue(r5, "emplacing returns correct value 5");
 }
 
 static void testToString1(Core::Test& test) {
@@ -169,8 +166,8 @@ static void testCopy(Core::Test& test) {
     int* a[6] = {map.search(1),  map.search(2),  map.search(3),
                  copy.search(1), copy.search(2), copy.search(3)};
     for(int i = 0; i < 3; i++) {
-        test.checkEqual(true, a[i] != nullptr && a[i + 3] != nullptr,
-                        "copy has same values");
+        test.checkTrue(a[i] != nullptr && a[i + 3] != nullptr,
+                       "copy has same values");
         if(a[i] != nullptr && a[i + 3] != nullptr) {
             test.checkEqual(*(a[i]), *(a[i + 3]), "copy has same values");
         }
@@ -188,9 +185,9 @@ static void testMove(Core::Test& test) {
     int* b = move.search(2);
     int* c = move.search(3);
 
-    test.checkEqual(true, a != nullptr, "move moves values 1");
-    test.checkEqual(true, b != nullptr, "move moves values 2");
-    test.checkEqual(true, c != nullptr, "move moves values 3");
+    test.checkTrue(a != nullptr, "move moves values 1");
+    test.checkTrue(b != nullptr, "move moves values 2");
+    test.checkTrue(c != nullptr, "move moves values 3");
 
     if(a != nullptr && b != nullptr && c != nullptr) {
         test.checkEqual(3, *a, "move moves values 1");
@@ -212,9 +209,9 @@ static void testMoveAssignment(Core::Test& test) {
     int* b = move.search(2);
     int* c = move.search(3);
 
-    test.checkEqual(true, a != nullptr, "move moves values 1");
-    test.checkEqual(true, b != nullptr, "move moves values 2");
-    test.checkEqual(true, c != nullptr, "move moves values 3");
+    test.checkTrue(a != nullptr, "move moves values 1");
+    test.checkTrue(b != nullptr, "move moves values 2");
+    test.checkTrue(c != nullptr, "move moves values 3");
 
     if(a != nullptr && b != nullptr && c != nullptr) {
         test.checkEqual(3, *a, "move moves values 1");
@@ -236,12 +233,12 @@ static void testRemove(Core::Test& test) {
     int* b = map.search(2);
     int* c = map.search(3);
 
-    test.checkEqual(true, a != nullptr, "move moves values 1");
-    test.checkEqual(true, b == nullptr, "move moves values 2");
-    test.checkEqual(true, c != nullptr, "move moves values 3");
+    test.checkTrue(a != nullptr, "move moves values 1");
+    test.checkTrue(b == nullptr, "move moves values 2");
+    test.checkTrue(c != nullptr, "move moves values 3");
 
-    test.checkEqual(true, remove1, "remove returns true");
-    test.checkEqual(false, remove2, "remove returns false");
+    test.checkTrue(remove1, "remove returns true");
+    test.checkFalse(remove2, "remove returns false");
 
     if(a != nullptr && c != nullptr) {
         test.checkEqual(3, *a, "move moves values 1");

+ 0 - 12
utils/HashCode.h

@@ -9,18 +9,6 @@ namespace Core {
         return key.hashCode();
     }
 
-    /*inline u32 hashCode(int key) {
-        static_assert(sizeof(key) == sizeof(u32),
-                      "unwanted loose of precision in hash");
-        return static_cast<u32>(key);
-    }
-
-    inline u32 hashCode(unsigned int key) {
-        static_assert(sizeof(key) == sizeof(u32),
-                      "unwanted loose of precision in hash");
-        return key;
-    }*/
-
     u32 hashCode(char key);
     u32 hashCode(signed char key);
     u32 hashCode(signed short key);