Add ability for reverse iteration to tower code, and corresponding
[pspp-builds.git] / tests / libpspp / tower-test.c
index f78fb8920700b50d2e77cca2dd86e0d4b69adaa3..a59760c80a89bfd13c0e5e273f5282d6e54428e6 100644 (file)
@@ -32,6 +32,7 @@
 
 #include <assert.h>
 #include <limits.h>
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -289,6 +290,15 @@ check_tower (struct tower *t,
       check (tower_node_to_block (node)->x == blocks[i].x);
     }
   check (i == block_cnt);
+
+  for (node = tower_last (t), i = block_cnt - 1;
+       node != NULL;
+       node = tower_prev (t, node), i--) 
+    {
+      check (tower_node_get_height (node) == blocks[i].height);
+      check (tower_node_to_block (node)->x == blocks[i].x);
+    }
+  check (i == SIZE_MAX);
 }
 \f
 /* Tests inserting all possible sets of block heights into a