Sfoglia il codice sorgente

examples: savl_test: turn on count keeping and test it

ambrop7 13 anni fa
parent
commit
efc9caf88e
2 ha cambiato i file con 7 aggiunte e 1 eliminazioni
  1. 4 0
      examples/savl_test.c
  2. 3 1
      examples/savl_test_tree.h

+ 4 - 0
examples/savl_test.c

@@ -28,6 +28,7 @@
  */
 
 #include <stdlib.h>
+#include <limits.h>
 
 #include <misc/debug.h>
 #include <misc/balloc.h>
@@ -92,6 +93,7 @@ int main (int argc, char **argv)
         }
     }
     printf("Inserted %d entries\n", inserted);
+    ASSERT_FORCE(MyTree_Count(&tree, 0) == inserted)
     verify(&tree);
     
     printf("Removing random entries...\n");
@@ -107,6 +109,7 @@ int main (int argc, char **argv)
         }
     }
     printf("Removed %d entries\n", removed1);
+    ASSERT_FORCE(MyTree_Count(&tree, 0) == inserted - removed1)
     verify(&tree);
     
     printf("Removing remaining...\n");
@@ -121,6 +124,7 @@ int main (int argc, char **argv)
     printf("Removed %d entries\n", removed2);
     ASSERT_FORCE(MyTree_IsEmpty(&tree))
     ASSERT_FORCE(removed1 + removed2 == inserted)
+    ASSERT_FORCE(MyTree_Count(&tree, 0) == 0)
     verify(&tree);
     
     BFree(nodes);

+ 3 - 1
examples/savl_test_tree.h

@@ -1,7 +1,9 @@
 #define SAVL_PARAM_NAME MyTree
-#define SAVL_PARAM_FEATURE_COUNTS 0
+#define SAVL_PARAM_FEATURE_COUNTS 1
 #define SAVL_PARAM_FEATURE_NOKEYS 1
 #define SAVL_PARAM_TYPE_ENTRY struct mynode
 #define SAVL_PARAM_TYPE_ARG int
+#define SAVL_PARAM_TYPE_COUNT int
+#define SAVL_PARAM_VALUE_COUNT_MAX INT_MAX
 #define SAVL_PARAM_FUN_COMPARE_ENTRIES(arg, entry1, entry2) B_COMPARE((entry1)->num, (entry2)->num)
 #define SAVL_PARAM_MEMBER_NODE tree_node