A few basic tests pass.
authorBen Pfaff <blp@cs.stanford.edu>
Mon, 17 Jan 2022 06:28:32 +0000 (22:28 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 13 Mar 2022 23:56:02 +0000 (16:56 -0700)
src/language/stats/ctables.c
tests/language/stats/ctables.at

index af53a6b6c53643a9d577a0b06a01d43e5db06880..6b6b46a035239564d3a54c43d353a9bcf06c84f1 100644 (file)
@@ -1925,7 +1925,8 @@ ctables_summary_add (union ctables_summary *s,
     case CTSF_LAYERPCT_SUM:
     case CTSF_LAYERROWPCT_SUM:
     case CTSF_LAYERCOLPCT_SUM:
-      moments1_add (s->moments, value->f, weight);
+      if (!var_is_value_missing (var, value))
+        moments1_add (s->moments, value->f, weight);
       break;
 
     case CTSF_MEDIAN:
@@ -2678,13 +2679,11 @@ ctables_table_output (struct ctables *ct, struct ctables_table *t)
           if (new_subtable)
             {
               n_levels = 0;
-              printf ("%s levels:", pivot_axis_type_to_string (a));
               for (size_t k = 0; k < nest->n; k++)
                 {
                   enum ctables_vlabel vlabel = ct->vlabels[var_get_dict_index (nest->vars[k])];
                   if (vlabel != CTVL_NONE)
                     {
-                      printf (" var(%s)", var_get_name (nest->vars[k]));
                       levels[n_levels++] = (struct ctables_level) {
                         .type = CTL_VAR,
                         .var_idx = k,
@@ -2694,7 +2693,6 @@ ctables_table_output (struct ctables *ct, struct ctables_table *t)
                   if (nest->scale_idx != k
                       && (k != nest->n - 1 || t->label_axis[a] == a))
                     {
-                      printf (" category(%s)", var_get_name (nest->vars[k]));
                       levels[n_levels++] = (struct ctables_level) {
                         .type = CTL_CATEGORY,
                         .var_idx = k,
@@ -2704,13 +2702,11 @@ ctables_table_output (struct ctables *ct, struct ctables_table *t)
 
               if (a == t->slabels_axis && a == t->summary_axis)
                 {
-                  printf (" summary");
                   levels[n_levels++] = (struct ctables_level) {
                     .type = CTL_SUMMARY,
                     .var_idx = SIZE_MAX,
                   };
                 }
-              printf ("\n");
             }
 
           size_t n_common = 0;
index 72aac4bf850cda12edb10066ba1fb9b8e848e5c7..e8b5981b101e704dba609e51030b189465fdffe7 100644 (file)
@@ -11,4 +11,82 @@ CTABLES /TABLE=x[c] [ROWPCT.COUNT] > y[c].
 CTABLES /TABLE=x[c] > y[c] [ROWPCT.COUNT].
 ]])
 AT_CHECK([pspp ctables.sps])
-AT_CLEANUP
\ No newline at end of file
+AT_CLEANUP
+
+AT_SETUP([CTABLES one categorical variable])
+AT_CHECK([ln $top_srcdir/examples/nhtsa.sav . || cp $top_srcdir/examples/nhtsa.sav .])
+AT_DATA([ctables.sps],
+[[GET 'nhtsa.sav'.
+CTABLES /TABLE QN1.
+CTABLES /TABLE BY QN1.
+CTABLES /TABLE BY BY QN1.
+]])
+AT_CHECK([pspp ctables.sps -O box=unicode -O width=80], [0], [dnl
+                                  Custom Tables
+╭────────────────────────────────────────────────────────────────────────┬─────╮
+│                                                                        │Count│
+├────────────────────────────────────────────────────────────────────────┼─────┤
+│ 1. How often do you usually drive a car or other  Every day            │ 4667│
+│motor vehicle?                                     Several days a week  │ 1274│
+│                                                   Once a week or less  │  361│
+│                                                   Only certain times a │  130│
+│                                                   year                 │     │
+│                                                   Never                │  540│
+╰────────────────────────────────────────────────────────────────────────┴─────╯
+
+                                  Custom Tables
+╭──────────────────────────────────────────────────────────────────────────────╮
+│        1. How often do you usually drive a car or other motor vehicle?       │
+├─────────┬──────────────────┬──────────────────┬────────────────────────┬─────┤
+│         │  Several days a  │  Once a week or  │  Only certain times a  │     │
+│Every day│       week       │       less       │          year          │Never│
+├─────────┼──────────────────┼──────────────────┼────────────────────────┼─────┤
+│  Count  │       Count      │       Count      │          Count         │Count│
+├─────────┼──────────────────┼──────────────────┼────────────────────────┼─────┤
+│     4667│              1274│               361│                     130│  540│
+╰─────────┴──────────────────┴──────────────────┴────────────────────────┴─────╯
+
+Custom Tables
+Every day
+╭─────╮
+│Count│
+├─────┤
+│ 4667│
+╰─────╯
+])
+AT_CLEANUP
+
+AT_SETUP([CTABLES one scale variable])
+AT_CHECK([ln $top_srcdir/examples/nhtsa.sav . || cp $top_srcdir/examples/nhtsa.sav .])
+AT_DATA([ctables.sps],
+[[GET 'nhtsa.sav'.
+CTABLES /TABLE QND1[COUNT, MEAN, STDDEV, MINIMUM, MAXIMUM].
+CTABLES /TABLE BY QND1.
+CTABLES /TABLE BY BY QND1.
+]])
+AT_CHECK([pspp ctables.sps -O box=unicode -O width=80], [0], [dnl
+                            Custom Tables
+╭──────────────────────────┬─────┬────┬─────────────┬───────┬───────╮
+│                          │Count│Mean│Std Deviation│Minimum│Maximum│
+├──────────────────────────┼─────┼────┼─────────────┼───────┼───────┤
+│D1. AGE: What is your age?│ 6930│  48│           19│     16│     86│
+╰──────────────────────────┴─────┴────┴─────────────┴───────┴───────╯
+
+        Custom Tables
+╭──────────────────────────╮
+│D1. AGE: What is your age?│
+├──────────────────────────┤
+│           Mean           │
+├──────────────────────────┤
+│                        48│
+╰──────────────────────────╯
+
+Custom Tables
+D1. AGE: What is your age?
+╭────╮
+│Mean│
+├────┤
+│  48│
+╰────╯
+])
+AT_CLEANUP