FREQUENCIES: Reimplement FORMAT=LIMIT feature.
authorBen Pfaff <blp@cs.stanford.edu>
Wed, 24 Jun 2015 03:12:44 +0000 (20:12 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Wed, 24 Jun 2015 03:12:44 +0000 (20:12 -0700)
When the FREQUENCIES input parser was rewritten, this feature was
mistakenly omitted.  This commit fixes the problem.

Reported by Douglas Ferguson.

src/language/stats/frequencies.c
tests/language/stats/frequencies.at

index cd131f514b29afc3c2cdfdcc16bda2f5a882b2f7..8fb96b0d57e2316d59ecda71099d317d189e10db 100644 (file)
@@ -214,7 +214,7 @@ struct frq_proc
     int n_percentiles, n_show_percentiles;
 
     /* Frequency table display. */
-    int max_categories;         /* Maximum categories to show. */
+    long int max_categories;         /* Maximum categories to show. */
     int sort;                   /* FRQ_AVALUE or FRQ_DVALUE
                                    or FRQ_AFREQ or FRQ_DFREQ. */
 
@@ -614,7 +614,7 @@ cmd_frequencies (struct lexer *lexer, struct dataset *ds)
 
   frq.n_stats = 4;
 
-  frq.max_categories = INT_MAX;
+  frq.max_categories = LONG_MAX;
 
   frq.percentiles = NULL;
   frq.n_percentiles = 0;
@@ -803,6 +803,18 @@ cmd_frequencies (struct lexer *lexer, struct dataset *ds)
                {
                  frq.max_categories = 0;
                }
+              else if (lex_match_id (lexer, "LIMIT"))
+                {
+                  if (!lex_force_match (lexer, T_LPAREN)
+                      || !lex_force_int (lexer))
+                    goto error;
+
+                  frq.max_categories = lex_integer (lexer);
+                  lex_get (lexer);
+
+                  if (!lex_force_match (lexer, T_RPAREN))
+                    goto error;
+                }
              else if (lex_match_id (lexer, "AVALUE"))
                {
                  frq.sort = FRQ_AVALUE;
index ff54e8e9cf1b56a32c14356abadd09f02dc80405..0d6433c5b938c7eb25bdea3a3bb2367b987d6b4d 100644 (file)
@@ -81,6 +81,29 @@ Total,,4,100.0,100.0,
 ])
 AT_CLEANUP
 
+# Test that the LIMIT specification works.
+AT_SETUP([FREQUENCIES with LIMIT])
+AT_DATA([frequencies.sps],
+  [data list free /v1 v2.
+begin data.
+0 1
+2 5
+4 3
+3 5
+end data.
+
+frequencies v1 v2/statistics=none/FORMAT=LIMIT(3).
+])
+AT_CHECK([pspp -O format=csv frequencies.sps], [0], [dnl
+Table: v2
+Value Label,Value,Frequency,Percent,Valid Percent,Cum Percent
+,1.00,1,25.00,25.00,25.00
+,3.00,1,25.00,25.00,50.00
+,5.00,2,50.00,50.00,100.00
+Total,,4,100.0,100.0,
+])
+AT_CLEANUP
+
 # Tests for a bug where PSPP would crash when a FREQUENCIES command
 # was used with the HTML output driver.
 AT_SETUP([FREQUENCIES HTML output crash])