Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove unused type definitions.
[simgrid.git] / src / xbt / dict_test.cpp
index 6cd12ea..5facbd8 100644 (file)
@@ -10,6 +10,7 @@
 #include "simgrid/Exception.hpp"
 #include <cstdio>
 #include <cstring>
+#include <random>
 
 #include "catch.hpp"
 
@@ -86,11 +87,7 @@ static void traverse(xbt_dict_t head)
   int i = 0;
 
   xbt_dict_foreach (head, cursor, key, data) {
-    if (not key || not data || strcmp(key, data)) {
-      INFO("Seen #" << ++i << ": " << STR(key) << "->" << STR(data));
-    } else {
-      INFO("Seen #" << ++i << ": " << STR(key));
-    }
+    INFO("Seen #" << ++i << ": " << STR(key) << "->" << STR(data));
     REQUIRE((key && data && strcmp(key, data) == 0)); //  key != value
   }
 }
@@ -282,29 +279,25 @@ TEST_CASE("xbt::dict: dict data container", "dict")
     search_ext(head, "null", nullptr);
 
     INFO("Check whether I see it while traversing...");
-    {
-      xbt_dict_cursor_t cursor = nullptr;
-      char* key;
-      int found = 0;
-      char* data;
-
-      xbt_dict_foreach (head, cursor, key, data) {
-        if (not key || not data || strcmp(key, data)) {
-          INFO("Seen: " << STR(key) << "->" << STR(data));
-        } else {
-          INFO("Seen: " << STR(key));
-        }
-        if (key && strcmp(key, "null") == 0)
-          found = 1;
-      }
-      REQUIRE(found); // the key 'null', associated to nullptr is not found
+    xbt_dict_cursor_t cursor = nullptr;
+    char* key;
+    bool found = false;
+    char* data;
+
+    xbt_dict_foreach (head, cursor, key, data) {
+      INFO("Seen: " << STR(key) << "->" << STR(data));
+      if (key && strcmp(key, "null") == 0)
+        found = true;
     }
+    REQUIRE(found); // the key 'null', associated to nullptr is not found
+
     xbt_dict_free(&head);
   }
 
   SECTION("Crash test")
   {
-    srand((unsigned int)time(nullptr));
+    std::random_device rd;
+    std::default_random_engine rnd_engine(rd());
 
     for (int i = 0; i < 10; i++) {
       INFO("CRASH test number " << i + 1 << " (" << 10 - i - 1 << " to go)");
@@ -317,7 +310,7 @@ TEST_CASE("xbt::dict: dict data container", "dict")
 
         do {
           for (int k = 0; k < SIZEOFKEY - 1; k++) {
-            key[k] = rand() % ('z' - 'a') + 'a';
+            key[k] = rnd_engine() % ('z' - 'a') + 'a';
           }
           key[SIZEOFKEY - 1] = '\0';
           data               = (char*)xbt_dict_get_or_null(head, key);