Replace more uses of 'cnt' by 'n'.
[pspp] / tests / data / datasheet-test.c
index c46c268376c77031baff7e6c06fa14a44808bd65..f0384853e60ccde412a3633f08ca40dd0a698b9a 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 2007, 2009 Free Software Foundation, Inc.
+   Copyright (C) 2007, 2009, 2010, 2014 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -19,6 +19,7 @@
 #include <data/datasheet.h>
 
 #include <ctype.h>
+#include <float.h>
 #include <stdlib.h>
 #include <stdint.h>
 #include <string.h>
@@ -41,7 +42,6 @@
 #include "error.h"
 #include "minmax.h"
 #include "progname.h"
-#include "xalloc.h"
 
 /* lazy_casereader callback function to instantiate a casereader
    from the datasheet. */
@@ -117,15 +117,15 @@ check_datasheet_casereader (struct mc *mc, struct casereader *reader,
   if (!check_caseproto (mc, proto, casereader_get_proto (reader),
                         "casereader"))
     return;
-  else if (casereader_get_case_cnt (reader) != n_rows)
+  else if (casereader_get_n_cases (reader) != n_rows)
     {
-      if (casereader_get_case_cnt (reader) == CASENUMBER_MAX
+      if (casereader_get_n_cases (reader) == CASENUMBER_MAX
           && casereader_count_cases (reader) == n_rows)
         mc_error (mc, "datasheet casereader has unknown case count");
       else
         mc_error (mc, "casereader row count (%lu) does not match "
                   "expected (%zu)",
-                  (unsigned long int) casereader_get_case_cnt (reader),
+                  (unsigned long int) casereader_get_n_cases (reader),
                   n_rows);
     }
   else
@@ -153,15 +153,16 @@ check_datasheet_casereader (struct mc *mc, struct casereader *reader,
                 {
                   if (width == 0)
                     mc_error (mc, "element %zu,%zu (of %zu,%zu) differs: "
-                              "%g != %g",
+                              "%.*g != %.*g",
                               row, col, n_rows, n_columns,
-                              case_num_idx (c, col), array[row][col].f);
+                              DBL_DIG + 1, case_num_idx (c, col),
+                              DBL_DIG + 1, array[row][col].f);
                   else
                     mc_error (mc, "element %zu,%zu (of %zu,%zu) differs: "
                               "'%.*s' != '%.*s'",
                               row, col, n_rows, n_columns,
                               width, case_str_idx (c, col),
-                              width, value_str (&array[row][col], width));
+                              width, array[row][col].s);
                 }
             }
 
@@ -217,14 +218,14 @@ check_datasheet (struct mc *mc, struct datasheet *ds,
               {
                 if (width == 0)
                   mc_error (mc, "element %zu,%zu (of %zu,%zu) differs: "
-                            "%g != %g", row, col, n_rows, n_columns,
-                            v.f, av->f);
+                            "%.*g != %.*g", row, col, n_rows, n_columns,
+                            DBL_DIG + 1, v.f, DBL_DIG + 1, av->f);
                 else
                   mc_error (mc, "element %zu,%zu (of %zu,%zu) differs: "
                             "'%.*s' != '%.*s'",
                             row, col, n_rows, n_columns,
-                            width, value_str (&v, width),
-                            width, value_str (av, width));
+                            width, v.s,
+                            width, v.s);
                 difference = true;
               }
             value_destroy (&v, width);
@@ -247,7 +248,7 @@ check_datasheet (struct mc *mc, struct datasheet *ds,
                   if (width == 0)
                     ds_put_format (&s, " %g", v->f);
                   else
-                    ds_put_format (&s, " '%.*s'", width, value_str (v, width));
+                    ds_put_format (&s, " '%.*s'", width, v->s);
                 }
               mc_error (mc, "%s", ds_cstr (&s));
             }
@@ -268,8 +269,7 @@ check_datasheet (struct mc *mc, struct datasheet *ds,
                   if (width == 0)
                     ds_put_format (&s, " %g", v.f);
                   else
-                    ds_put_format (&s, " '%.*s'",
-                                   width, value_str (&v, width));
+                    ds_put_format (&s, " '%.*s'", width, v.s);
                 }
               mc_error (mc, "%s", ds_cstr (&s));
             }
@@ -405,12 +405,11 @@ value_from_param (union value *value, int width, unsigned int idx)
   else
     {
       unsigned int hash = hash_int (idx, 0);
-      uint8_t *string = value_str_rw (value, width);
       int offset;
 
       assert (width < 32);
       for (offset = 0; offset < width; offset++)
-        string[offset] = "ABCDEFGHIJ"[(hash >> offset) % 10];
+        value->s[offset] = "ABCDEFGHIJ"[(hash >> offset) % 10];
     }
 }
 
@@ -424,9 +423,12 @@ datasheet_mc_init (struct mc *mc)
   if (params->backing_rows == 0 && params->n_backing_cols == 0)
     {
       /* Create unbacked datasheet. */
+      struct caseproto *proto;
       ds = datasheet_create (NULL);
       mc_name_operation (mc, "empty datasheet");
-      check_datasheet (mc, ds, NULL, 0, caseproto_create ());
+      proto = caseproto_create ();
+      check_datasheet (mc, ds, NULL, 0, proto);
+      caseproto_unref (proto);
     }
   else
     {
@@ -482,9 +484,9 @@ struct resize_cb_aux
   };
 
 static void
-resize_cb (const union value *old_value, union value *new_value, void *aux_)
+resize_cb (const union value *old_value, union value *new_value, const void *aux_)
 {
-  struct resize_cb_aux *aux = aux_;
+  const struct resize_cb_aux *aux = aux_;
 
   value_from_param (new_value, aux->new_width,
                     value_hash (old_value, aux->old_width, 0));
@@ -502,7 +504,7 @@ datasheet_mc_mutate (struct mc *mc, const void *ods_)
   const struct caseproto *oproto = datasheet_get_proto (ods);
   size_t n_columns = datasheet_get_n_columns (ods);
   size_t n_rows = datasheet_get_n_rows (ods);
-  size_t pos, new_pos, cnt, width_idx;
+  size_t pos, new_pos, n, width_idx;
 
   extract_data (ods, odata);
 
@@ -587,7 +589,7 @@ datasheet_mc_mutate (struct mc *mc, const void *ods_)
   /* Delete all possible numbers of columns from all possible
      positions. */
   for (pos = 0; pos < n_columns; pos++)
-    for (cnt = 1; cnt < n_columns - pos; cnt++)
+    for (n = 1; n < n_columns - pos; n++)
       if (mc_include_state (mc))
         {
           struct caseproto *proto;
@@ -596,17 +598,17 @@ datasheet_mc_mutate (struct mc *mc, const void *ods_)
 
           mc_name_operation (mc, "delete %zu columns at %zu "
                              "(from %zu to %zu columns)",
-                             cnt, pos, n_columns, n_columns - cnt);
+                             n, pos, n_columns, n_columns - n);
           clone_model (ods, odata, &ds, data);
 
-          datasheet_delete_columns (ds, pos, cnt);
-          proto = caseproto_remove_widths (caseproto_ref (oproto), pos, cnt);
+          datasheet_delete_columns (ds, pos, n);
+          proto = caseproto_remove_widths (caseproto_ref (oproto), pos, n);
 
           for (i = 0; i < n_rows; i++)
             {
-              for (j = pos; j < pos + cnt; j++)
+              for (j = pos; j < pos + n; j++)
                 value_destroy (&data[i][j], caseproto_get_width (oproto, j));
-              remove_range (&data[i], n_columns, sizeof *data[i], pos, cnt);
+              remove_range (&data[i], n_columns, sizeof *data[i], pos, n);
             }
 
           check_datasheet (mc, ds, data, n_rows, proto);
@@ -617,8 +619,8 @@ datasheet_mc_mutate (struct mc *mc, const void *ods_)
   /* Move all possible numbers of columns from all possible
      existing positions to all possible new positions. */
   for (pos = 0; pos < n_columns; pos++)
-    for (cnt = 1; cnt < n_columns - pos; cnt++)
-      for (new_pos = 0; new_pos < n_columns - cnt; new_pos++)
+    for (n = 1; n < n_columns - pos; n++)
+      for (new_pos = 0; new_pos < n_columns - n; new_pos++)
         if (mc_include_state (mc))
           {
             struct caseproto *proto;
@@ -627,15 +629,15 @@ datasheet_mc_mutate (struct mc *mc, const void *ods_)
 
             clone_model (ods, odata, &ds, data);
             mc_name_operation (mc, "move %zu columns (of %zu) from %zu to %zu",
-                               cnt, n_columns, pos, new_pos);
+                               n, n_columns, pos, new_pos);
 
-            datasheet_move_columns (ds, pos, new_pos, cnt);
+            datasheet_move_columns (ds, pos, new_pos, n);
 
             for (i = 0; i < n_rows; i++)
               move_range (&data[i], n_columns, sizeof data[i][0],
-                          pos, new_pos, cnt);
+                          pos, new_pos, n);
             proto = caseproto_move_widths (caseproto_ref (oproto),
-                                           pos, new_pos, cnt);
+                                           pos, new_pos, n);
 
             check_datasheet (mc, ds, data, n_rows, proto);
             release_data (n_rows, proto, data);
@@ -645,7 +647,7 @@ datasheet_mc_mutate (struct mc *mc, const void *ods_)
   /* Insert all possible numbers of rows in all possible
      positions. */
   for (pos = 0; pos <= n_rows; pos++)
-    for (cnt = 1; cnt <= params->max_rows - n_rows; cnt++)
+    for (n = 1; n <= params->max_rows - n_rows; n++)
       if (mc_include_state (mc))
         {
           struct datasheet *ds;
@@ -655,9 +657,9 @@ datasheet_mc_mutate (struct mc *mc, const void *ods_)
           clone_model (ods, odata, &ds, data);
           mc_name_operation (mc, "insert %zu rows at %zu "
                              "(from %zu to %zu rows)",
-                             cnt, pos, n_rows, n_rows + cnt);
+                             n, pos, n_rows, n_rows + n);
 
-          for (i = 0; i < cnt; i++)
+          for (i = 0; i < n; i++)
             {
               c[i] = case_create (oproto);
               for (j = 0; j < n_columns; j++)
@@ -666,8 +668,8 @@ datasheet_mc_mutate (struct mc *mc, const void *ods_)
                                   params->next_value++);
             }
 
-          insert_range (data, n_rows, sizeof data[pos], pos, cnt);
-          for (i = 0; i < cnt; i++)
+          insert_range (data, n_rows, sizeof data[pos], pos, n);
+          for (i = 0; i < n; i++)
             for (j = 0; j < n_columns; j++)
               {
                 int width = caseproto_get_width (oproto, j);
@@ -675,17 +677,17 @@ datasheet_mc_mutate (struct mc *mc, const void *ods_)
                 value_copy (&data[i + pos][j], case_data_idx (c[i], j), width);
               }
 
-          if (!datasheet_insert_rows (ds, pos, c, cnt))
+          if (!datasheet_insert_rows (ds, pos, c, n))
             mc_error (mc, "datasheet_insert_rows failed");
 
-          check_datasheet (mc, ds, data, n_rows + cnt, oproto);
-          release_data (n_rows + cnt, oproto, data);
+          check_datasheet (mc, ds, data, n_rows + n, oproto);
+          release_data (n_rows + n, oproto, data);
         }
 
   /* Delete all possible numbers of rows from all possible
      positions. */
   for (pos = 0; pos < n_rows; pos++)
-    for (cnt = 1; cnt < n_rows - pos; cnt++)
+    for (n = 1; n < n_rows - pos; n++)
       if (mc_include_state (mc))
         {
           struct datasheet *ds;
@@ -693,34 +695,34 @@ datasheet_mc_mutate (struct mc *mc, const void *ods_)
           clone_model (ods, odata, &ds, data);
           mc_name_operation (mc, "delete %zu rows at %zu "
                              "(from %zu to %zu rows)",
-                             cnt, pos, n_rows, n_rows - cnt);
+                             n, pos, n_rows, n_rows - n);
 
-          datasheet_delete_rows (ds, pos, cnt);
+          datasheet_delete_rows (ds, pos, n);
 
-          release_data (cnt, oproto, &data[pos]);
-          remove_range (&data[0], n_rows, sizeof data[0], pos, cnt);
+          release_data (n, oproto, &data[pos]);
+          remove_range (&data[0], n_rows, sizeof data[0], pos, n);
 
-          check_datasheet (mc, ds, data, n_rows - cnt, oproto);
-          release_data (n_rows - cnt, oproto, data);
+          check_datasheet (mc, ds, data, n_rows - n, oproto);
+          release_data (n_rows - n, oproto, data);
         }
 
   /* Move all possible numbers of rows from all possible existing
      positions to all possible new positions. */
   for (pos = 0; pos < n_rows; pos++)
-    for (cnt = 1; cnt < n_rows - pos; cnt++)
-      for (new_pos = 0; new_pos < n_rows - cnt; new_pos++)
+    for (n = 1; n < n_rows - pos; n++)
+      for (new_pos = 0; new_pos < n_rows - n; new_pos++)
         if (mc_include_state (mc))
           {
             struct datasheet *ds;
 
             clone_model (ods, odata, &ds, data);
             mc_name_operation (mc, "move %zu rows (of %zu) from %zu to %zu",
-                               cnt, n_rows, pos, new_pos);
+                               n, n_rows, pos, new_pos);
 
-            datasheet_move_rows (ds, pos, new_pos, cnt);
+            datasheet_move_rows (ds, pos, new_pos, n);
 
             move_range (&data[0], n_rows, sizeof data[0],
-                        pos, new_pos, cnt);
+                        pos, new_pos, n);
 
             check_datasheet (mc, ds, data, n_rows, oproto);
             release_data (n_rows, oproto, data);
@@ -748,7 +750,7 @@ enum
     N_DATASHEET_OPTIONS
   };
 
-static struct argv_option datasheet_argv_options[N_DATASHEET_OPTIONS] =
+static const struct argv_option datasheet_argv_options[N_DATASHEET_OPTIONS] =
   {
     {"max-rows", 0, required_argument, OPT_MAX_ROWS},
     {"max-columns", 0, required_argument, OPT_MAX_COLUMNS},
@@ -853,10 +855,9 @@ usage (void)
           "                       other values are string widths (0,1,11)\n",
           program_name, program_name);
   mc_options_usage ();
-  fputs ("\nOther options:\n"
-         "  --help               Display this help message\n"
-         "\nReport bugs to <bug-gnu-pspp@gnu.org>\n",
-         stdout);
+  printf ("\nOther options:\n"
+          "  --help               Display this help message\n"
+          "\nReport bugs to <%s>\n", PACKAGE_BUGREPORT);
   exit (0);
 }
 
@@ -890,7 +891,7 @@ main (int argc, char *argv[])
   params.n_widths = 3;
   params.next_value = 1;
 
-  /* Parse comand line. */
+  /* Parse command line. */
   parser = argv_parser_create ();
   options = mc_options_create ();
   mc_options_register_argv_parser (options, parser);