Add list of unimplemented features.
[pspp] / tests / libpspp / range-map-test.c
index b6a1b493220c208c8e0f87d28ca8231a89606801..5ac611f77aac84194134dad6826f22f6f26eb442 100644 (file)
@@ -73,18 +73,18 @@ swap (int *a, int *b)
   *b = t;
 }
 
   *b = t;
 }
 
-/* Reverses the order of the CNT integers starting at VALUES. */
+/* Reverses the order of the N integers starting at VALUES. */
 static void
 static void
-reverse (int *values, size_t cnt)
+reverse (int *values, size_t n)
 {
   size_t i = 0;
 {
   size_t i = 0;
-  size_t j = cnt;
+  size_t j = n;
 
   while (j > i)
     swap (&values[i++], &values[--j]);
 }
 
 
   while (j > i)
     swap (&values[i++], &values[--j]);
 }
 
-/* Arranges the CNT blocks in VALUES into the lexicographically
+/* Arranges the N blocks in VALUES into the lexicographically
    next greater permutation.  Returns true if successful.
    If VALUES is already the lexicographically greatest
    permutation of its blocks (i.e. ordered from greatest to
    next greater permutation.  Returns true if successful.
    If VALUES is already the lexicographically greatest
    permutation of its blocks (i.e. ordered from greatest to
@@ -92,26 +92,26 @@ reverse (int *values, size_t cnt)
    permutation (i.e. ordered from smallest to largest) and
    returns false. */
 static bool
    permutation (i.e. ordered from smallest to largest) and
    returns false. */
 static bool
-next_permutation (int *values, size_t cnt)
+next_permutation (int *values, size_t n)
 {
 {
-  if (cnt > 0)
+  if (n > 0)
     {
     {
-      size_t i = cnt - 1;
+      size_t i = n - 1;
       while (i != 0)
         {
           i--;
           if (values[i] < values[i + 1])
             {
               size_t j;
       while (i != 0)
         {
           i--;
           if (values[i] < values[i + 1])
             {
               size_t j;
-              for (j = cnt - 1; values[i] >= values[j]; j--)
+              for (j = n - 1; values[i] >= values[j]; j--)
                 continue;
               swap (values + i, values + j);
                 continue;
               swap (values + i, values + j);
-              reverse (values + (i + 1), cnt - (i + 1));
+              reverse (values + (i + 1), n - (i + 1));
               return true;
             }
         }
 
               return true;
             }
         }
 
-      reverse (values, cnt);
+      reverse (values, n);
     }
 
   return false;
     }
 
   return false;
@@ -124,7 +124,7 @@ factorial (unsigned int n)
   unsigned int value = 1;
   /* Disallow N values that overflow on 32-bit machines. */
   assert (n <= 12);
   unsigned int value = 1;
   /* Disallow N values that overflow on 32-bit machines. */
   assert (n <= 12);
-  for (; n > 1; )
+  for (; n > 1;)
     value *= n--;
   return value;
 }
     value *= n--;
   return value;
 }
@@ -244,23 +244,23 @@ compare_expected_element (const void *a_, const void *b_)
   return a->start < b->start ? -1 : a->start > b->start;
 }
 
   return a->start < b->start ? -1 : a->start > b->start;
 }
 
-/* Checks that RM contains the ELEM_CNT elements described by
+/* Checks that RM contains the ELEM_N elements described by
    ELEMENTS[]. */
 static void
 check_range_map (struct range_map *rm,
    ELEMENTS[]. */
 static void
 check_range_map (struct range_map *rm,
-                 struct expected_element elements[], size_t elem_cnt)
+                 struct expected_element elements[], size_t n_elems)
 {
   struct expected_element *sorted;
   struct range_map_node *node;
   size_t i;
 
 {
   struct expected_element *sorted;
   struct range_map_node *node;
   size_t i;
 
-  sorted = xnmalloc (elem_cnt, sizeof *sorted);
-  memcpy (sorted, elements, elem_cnt * sizeof *elements);
-  qsort (sorted, elem_cnt, sizeof *sorted, compare_expected_element);
+  sorted = xnmalloc (n_elems, sizeof *sorted);
+  memcpy (sorted, elements, n_elems * sizeof *elements);
+  qsort (sorted, n_elems, sizeof *sorted, compare_expected_element);
 
 
-  check (range_map_is_empty (rm) == (elem_cnt == 0));
+  check (range_map_is_empty (rm) == (n_elems == 0));
 
 
-  for (i = 0; i < elem_cnt; i++)
+  for (i = 0; i < n_elems; i++)
     {
       struct expected_element *e = &sorted[i];
       unsigned long int position;
     {
       struct expected_element *e = &sorted[i];
       unsigned long int position;
@@ -282,7 +282,7 @@ check_range_map (struct range_map *rm,
          range_map_lookup doesn't find any there. */
       if (e->start > 0 && (i == 0 || e[-1].end < e->start))
         check (range_map_lookup (rm, e->start - 1) == NULL);
          range_map_lookup doesn't find any there. */
       if (e->start > 0 && (i == 0 || e[-1].end < e->start))
         check (range_map_lookup (rm, e->start - 1) == NULL);
-      if (i == elem_cnt - 1 || e->end < e[1].start)
+      if (i == n_elems - 1 || e->end < e[1].start)
         check (range_map_lookup (rm, e->end) == NULL);
     }
 
         check (range_map_lookup (rm, e->end) == NULL);
     }
 
@@ -294,7 +294,7 @@ check_range_map (struct range_map *rm,
       struct expected_element *e = &sorted[i];
       check (range_map_node_to_element (node)->x == e->x);
     }
       struct expected_element *e = &sorted[i];
       check (range_map_node_to_element (node)->x == e->x);
     }
-  check (i == elem_cnt);
+  check (i == n_elems);
 
   free (sorted);
 }
 
   free (sorted);
 }
@@ -306,41 +306,41 @@ static void
 test_insert (void)
 {
   const int max_range = 7;
 test_insert (void)
 {
   const int max_range = 7;
-  int cnt;
+  int n;
 
 
-  for (cnt = 1; cnt <= max_range; cnt++)
+  for (n = 1; n <= max_range; n++)
     {
     {
-      unsigned int composition_cnt;
+      unsigned int n_compositions;
       struct expected_element *expected;
       int *widths;
       struct expected_element *expected;
       int *widths;
-      int elem_cnt;
+      int n_elems;
       int *order;
       struct element *elements;
 
       int *order;
       struct element *elements;
 
-      expected = xnmalloc (cnt, sizeof *expected);
-      widths = xnmalloc (cnt, sizeof *widths);
-      order = xnmalloc (cnt, sizeof *order);
-      elements = xnmalloc (cnt, sizeof *elements);
+      expected = xnmalloc (n, sizeof *expected);
+      widths = xnmalloc (n, sizeof *widths);
+      order = xnmalloc (n, sizeof *order);
+      elements = xnmalloc (n, sizeof *elements);
 
 
-      elem_cnt = 0;
-      composition_cnt = 0;
-      while (next_composition (cnt, &elem_cnt, widths))
+      n_elems = 0;
+      n_compositions = 0;
+      while (next_composition (n, &n_elems, widths))
         {
           int i, j;
         {
           int i, j;
-          unsigned int permutation_cnt;
+          unsigned int n_permutations;
 
 
-          for (i = 0; i < elem_cnt; i++)
+          for (i = 0; i < n_elems; i++)
             order[i] = i;
 
             order[i] = i;
 
-          permutation_cnt = 0;
-          while (permutation_cnt == 0 || next_permutation (order, elem_cnt))
+          n_permutations = 0;
+          while (n_permutations == 0 || next_permutation (order, n_elems))
             {
               struct range_map rm;
 
             {
               struct range_map rm;
 
-              /* Inserts the elem_cnt elements with the given
+              /* Inserts the n_elems elements with the given
                  widths[] into T in the order given by order[]. */
               range_map_init (&rm);
                  widths[] into T in the order given by order[]. */
               range_map_init (&rm);
-              for (i = 0; i < elem_cnt; i++)
+              for (i = 0; i < n_elems; i++)
                 {
                   unsigned long int start, end;
                   int idx;
                 {
                   unsigned long int start, end;
                   int idx;
@@ -364,13 +364,13 @@ test_insert (void)
                   expected[i].end = end;
                   check_range_map (&rm, expected, i + 1);
                 }
                   expected[i].end = end;
                   check_range_map (&rm, expected, i + 1);
                 }
-              permutation_cnt++;
+              n_permutations++;
             }
             }
-          check (permutation_cnt == factorial (elem_cnt));
+          check (n_permutations == factorial (n_elems));
 
 
-          composition_cnt++;
+          n_compositions++;
         }
         }
-      check (composition_cnt == 1 << (cnt - 1));
+      check (n_compositions == 1 << (n - 1));
 
       free (expected);
       free (widths);
 
       free (expected);
       free (widths);
@@ -385,34 +385,34 @@ static void
 test_delete (int gap)
 {
   const int max_range = 7;
 test_delete (int gap)
 {
   const int max_range = 7;
-  int cnt;
+  int n;
 
 
-  for (cnt = 1; cnt <= max_range; cnt++)
+  for (n = 1; n <= max_range; n++)
     {
     {
-      unsigned int composition_cnt;
+      unsigned int n_compositions;
       struct expected_element *expected;
       int *widths;
       struct expected_element *expected;
       int *widths;
-      int elem_cnt;
+      int n_elems;
       int *order;
       struct element *elements;
 
       int *order;
       struct element *elements;
 
-      expected = xnmalloc (cnt, sizeof *expected);
-      widths = xnmalloc (cnt, sizeof *widths);
-      order = xnmalloc (cnt, sizeof *order);
-      elements = xnmalloc (cnt, sizeof *elements);
+      expected = xnmalloc (n, sizeof *expected);
+      widths = xnmalloc (n, sizeof *widths);
+      order = xnmalloc (n, sizeof *order);
+      elements = xnmalloc (n, sizeof *elements);
 
 
-      elem_cnt = 0;
-      composition_cnt = 0;
-      while (next_composition (cnt, &elem_cnt, widths))
+      n_elems = 0;
+      n_compositions = 0;
+      while (next_composition (n, &n_elems, widths))
         {
           int i, j;
         {
           int i, j;
-          unsigned int permutation_cnt;
+          unsigned int n_permutations;
 
 
-          for (i = 0; i < elem_cnt; i++)
+          for (i = 0; i < n_elems; i++)
             order[i] = i;
 
             order[i] = i;
 
-          permutation_cnt = 0;
-          while (permutation_cnt == 0 || next_permutation (order, elem_cnt))
+          n_permutations = 0;
+          while (n_permutations == 0 || next_permutation (order, n_elems))
             {
               struct range_map rm;
               unsigned long int start;
             {
               struct range_map rm;
               unsigned long int start;
@@ -420,7 +420,7 @@ test_delete (int gap)
               /* Insert all the elements. */
               range_map_init (&rm);
               start = 0;
               /* Insert all the elements. */
               range_map_init (&rm);
               start = 0;
-              for (i = 0; i < elem_cnt; i++)
+              for (i = 0; i < n_elems; i++)
                 {
                   int width = widths[i] > gap ? widths[i] - gap : widths[i];
                   unsigned long int end = start + width;
                 {
                   int width = widths[i] > gap ? widths[i] - gap : widths[i];
                   unsigned long int end = start + width;
@@ -431,7 +431,7 @@ test_delete (int gap)
 
                   for (j = 0; ; j++)
                     {
 
                   for (j = 0; ; j++)
                     {
-                      assert (j < elem_cnt);
+                      assert (j < n_elems);
                       if (order[j] == i)
                         {
                           expected[j].x = i;
                       if (order[j] == i)
                         {
                           expected[j].x = i;
@@ -443,22 +443,22 @@ test_delete (int gap)
 
                   start += widths[i];
                 }
 
                   start += widths[i];
                 }
-              check_range_map (&rm, expected, elem_cnt);
+              check_range_map (&rm, expected, n_elems);
 
               /* Delete the elements in the specified order. */
 
               /* Delete the elements in the specified order. */
-              for (i = 0; i < elem_cnt; i++)
+              for (i = 0; i < n_elems; i++)
                 {
                   range_map_delete (&rm, &elements[order[i]].node);
                 {
                   range_map_delete (&rm, &elements[order[i]].node);
-                  check_range_map (&rm, expected + i + 1, elem_cnt - i - 1);
+                  check_range_map (&rm, expected + i + 1, n_elems - i - 1);
                 }
 
                 }
 
-              permutation_cnt++;
+              n_permutations++;
             }
             }
-          check (permutation_cnt == factorial (elem_cnt));
+          check (n_permutations == factorial (n_elems));
 
 
-          composition_cnt++;
+          n_compositions++;
         }
         }
-      check (composition_cnt == 1 << (cnt - 1));
+      check (n_compositions == 1 << (n - 1));
 
       free (expected);
       free (widths);
 
       free (expected);
       free (widths);