start writing tests
authorBen Pfaff <blp@cs.stanford.edu>
Sat, 30 Jul 2022 18:40:38 +0000 (11:40 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Sat, 30 Jul 2022 18:40:38 +0000 (11:40 -0700)
src/data/dataset.c
src/language/stats/ctables.c
tests/language/stats/ctables.at

index 2516fa3d1f8ebda27a892ce99d3dfba8e8e14a49..41b467a0ae7a85cf79cb91967dff915ab9b919ac 100644 (file)
@@ -1150,6 +1150,8 @@ measure_guesser_run (struct measure_guesser *mg,
   measure_guesser_commit (mg);
 }
 \f
+/* A transformation for guessing measurement levels. */
+
 static enum trns_result
 mg_trns_proc (void *mg_, struct ccase **c, casenumber case_nr UNUSED)
 {
index 69c505c48624ec5ad096b09c67a1ed88a53ceb71..e043105ccb6d58f288179d7c0d0ddb5bd00c0f87 100644 (file)
@@ -4719,7 +4719,12 @@ ctables_check_label_position (struct ctables_table *t, enum pivot_axis_type a)
     return true;
 
   const struct ctables_nest *n0 = &stack->nests[0];
-  assert (n0->n > 0);
+  if (n0->n == 0)
+    {
+      assert (stack->n == 1);
+      return true;
+    }
+
   const struct variable *v0 = n0->vars[n0->n - 1];
   struct ctables_categories *c0 = t->categories[var_get_dict_index (v0)];
   t->clabels_example = v0;
@@ -4896,6 +4901,10 @@ ctables_prepare_table (struct ctables_table *t)
         struct ctables_nest *nest = xmalloc (sizeof *nest);
         *nest = (struct ctables_nest) { .n = 0 };
         t->stacks[a] = (struct ctables_stack) { .nests = nest, .n = 1 };
+
+        /* There's no point in moving labels away from an axis that has no
+           labels, so avoid dealing with the special cases around that. */
+        t->label_axis[a] = a;
       }
 
   struct ctables_stack *stack = &t->stacks[t->summary_axis];
@@ -6246,7 +6255,7 @@ cmd_ctables (struct lexer *lexer, struct dataset *ds)
           if (!ct->e_weight)
             goto error;
         }
-      else if (lex_match_id (lexer, " HIDESMALLCOUNTS"))
+      else if (lex_match_id (lexer, "HIDESMALLCOUNTS"))
         {
           if (lex_match_id (lexer, "COUNT"))
             {
@@ -6443,46 +6452,45 @@ cmd_ctables (struct lexer *lexer, struct dataset *ds)
             }
           else if (lex_match_id (lexer, "CLABELS"))
             {
-              while (lex_token (lexer) != T_SLASH && lex_token (lexer) != T_ENDCMD)
+              if (lex_match_id (lexer, "AUTO"))
                 {
-                  if (lex_match_id (lexer, "AUTO"))
-                    {
-                      t->label_axis[PIVOT_AXIS_ROW] = PIVOT_AXIS_ROW;
-                      t->label_axis[PIVOT_AXIS_COLUMN] = PIVOT_AXIS_COLUMN;
-                    }
-                  else if (lex_match_id (lexer, "ROWLABELS"))
-                    {
-                      lex_match (lexer, T_EQUALS);
-                      if (lex_match_id (lexer, "OPPOSITE"))
-                        t->label_axis[PIVOT_AXIS_ROW] = PIVOT_AXIS_COLUMN;
-                      else if (lex_match_id (lexer, "LAYER"))
-                        t->label_axis[PIVOT_AXIS_ROW] = PIVOT_AXIS_LAYER;
-                      else
-                        {
-                          lex_error_expecting (lexer, "OPPOSITE", "LAYER");
-                          goto error;
-                        }
-                    }
-                  else if (lex_match_id (lexer, "COLLABELS"))
+                  t->label_axis[PIVOT_AXIS_ROW] = PIVOT_AXIS_ROW;
+                  t->label_axis[PIVOT_AXIS_COLUMN] = PIVOT_AXIS_COLUMN;
+                }
+              else if (lex_match_id (lexer, "ROWLABELS"))
+                {
+                  lex_match (lexer, T_EQUALS);
+                  t->label_axis[PIVOT_AXIS_COLUMN] = PIVOT_AXIS_COLUMN;
+                  if (lex_match_id (lexer, "OPPOSITE"))
+                    t->label_axis[PIVOT_AXIS_ROW] = PIVOT_AXIS_COLUMN;
+                  else if (lex_match_id (lexer, "LAYER"))
+                    t->label_axis[PIVOT_AXIS_ROW] = PIVOT_AXIS_LAYER;
+                  else
                     {
-                      lex_match (lexer, T_EQUALS);
-                      if (lex_match_id (lexer, "OPPOSITE"))
-                        t->label_axis[PIVOT_AXIS_COLUMN] = PIVOT_AXIS_ROW;
-                      else if (lex_match_id (lexer, "LAYER"))
-                        t->label_axis[PIVOT_AXIS_COLUMN] = PIVOT_AXIS_LAYER;
-                      else
-                        {
-                          lex_error_expecting (lexer, "OPPOSITE", "LAYER");
-                          goto error;
-                        }
+                      lex_error_expecting (lexer, "OPPOSITE", "LAYER");
+                      goto error;
                     }
+                }
+              else if (lex_match_id (lexer, "COLLABELS"))
+                {
+                  lex_match (lexer, T_EQUALS);
+                  t->label_axis[PIVOT_AXIS_ROW] = PIVOT_AXIS_ROW;
+                  if (lex_match_id (lexer, "OPPOSITE"))
+                    t->label_axis[PIVOT_AXIS_COLUMN] = PIVOT_AXIS_ROW;
+                  else if (lex_match_id (lexer, "LAYER"))
+                    t->label_axis[PIVOT_AXIS_COLUMN] = PIVOT_AXIS_LAYER;
                   else
                     {
-                      lex_error_expecting (lexer, "AUTO", "ROWLABELS",
-                                           "COLLABELS");
+                      lex_error_expecting (lexer, "OPPOSITE", "LAYER");
                       goto error;
                     }
                 }
+              else
+                {
+                  lex_error_expecting (lexer, "AUTO", "ROWLABELS",
+                                       "COLLABELS");
+                  goto error;
+                }
             }
           else if (lex_match_id (lexer, "CRITERIA"))
             {
index b1a497db3c69ce58de7c78a3d945125371ef3c73..23a41edc6091cbb5b986236c15d9c546c4778539 100644 (file)
@@ -73,18 +73,48 @@ dnl +--------------------------+----+------+----+------+
 
 
 
-# AT_SETUP([CTABLES parsing])
-# AT_DATA([ctables.sps],
-# [[DATA LIST LIST NOTABLE /x y z.
-# CTABLES /TABLE=(x + y) > z.
-# CTABLES /TABLE=(x[c] + y[c]) > z.
-# CTABLES /TABLE=(x + y) > z[c].
-# CTABLES /TABLE=x BY y BY z.
-# CTABLES /TABLE=x[c] [ROWPCT.COUNT] > y[c].
-# CTABLES /TABLE=x[c] > y[c] [ROWPCT.COUNT].
-# ]])
-# AT_CHECK([pspp ctables.sps])
-# AT_CLEANUP
+AT_SETUP([CTABLES parsing])
+AT_CHECK([ln $top_srcdir/examples/nhtsa.sav . || cp $top_srcdir/examples/nhtsa.sav .])
+AT_DATA([ctables.sps],
+[[GET 'nhtsa.sav'.
+CTABLES
+    /FORMAT MINCOLWIDTH=10 MAXCOLWIDTH=20 UNITS=POINTS EMPTY=ZERO MISSING="x"
+    /FORMAT MINCOLWIDTH=DEFAULT MAXCOLWIDTH=DEFAULT UNITS=INCHES EMPTY=BLANK MISSING="."
+    /FORMAT UNITS=CM EMPTY="(-)"
+    /VLABELS VARIABLES=qn1 DISPLAY=DEFAULT
+    /VLABELS VARIABLES=qn17 DISPLAY=NAME
+    /VLABELS VARIABLES=qns3a DISPLAY=LABEL
+    /VLABELS VARIABLES=qnd1 DISPLAY=BOTH
+    /VLABELS VARIABLES=qn20 DISPLAY=NONE
+    /MRSETS COUNTDUPLICATES=NO
+    /MRSETS COUNTDUPLICATES=YES
+    /SMISSING VARIABLE
+    /SMISSING LISTWISE
+    /WEIGHT VARIABLE=qns3a
+    /HIDESMALLCOUNTS
+    /HIDESMALLCOUNTS COUNT=10
+    /TABLE qnd1
+    /SLABELS POSITION=COLUMN VISIBLE=YES
+    /SLABELS VISIBLE=NO POSITION=ROW
+    /SLABELS POSITION=LAYER
+    /CLABELS AUTO
+    /CLABELS ROWLABELS=OPPOSITE
+    /CLABELS ROWLABELS=LAYER
+    /CLABELS COLLABELS=OPPOSITE
+    /CLABELS COLLABELS=LAYER
+    /CRITERIA CILEVEL=50
+    /CATEGORIES VARIABLES=qn1 qn17
+                ORDER=A KEY=VALUE MISSING=INCLUDE TOTAL=YES LABEL="xyzzy"
+               POSITION=BEFORE EMPTY=INCLUDE.
+]])
+AT_CHECK([pspp ctables.sps -O box=unicode -O width=80], [0], [dnl
+            Custom Tables
+Mean
+╭───────────────────────────────┬──╮
+│qnd1 D1. AGE: What is your age?│49│
+╰───────────────────────────────┴──╯
+])
+AT_CLEANUP
 
 AT_SETUP([CTABLES one categorical variable])
 AT_CHECK([ln $top_srcdir/examples/nhtsa.sav . || cp $top_srcdir/examples/nhtsa.sav .])