intersecting pcomputes
[pspp] / tests / language / stats / ctables.at
index 26ff5f9de52866d94c6f7c3e1dbd52c64bf31b37..03f14a66aef02c60ef58c3087b5e5426a796364c 100644 (file)
@@ -13,12 +13,7 @@ dnl   * THRU (numeric ranges)
 dnl   * OTHERNM
 dnl - Date/time variables and values
 dnl - Test PCOMPUTE:
-dnl   * PCOMPUTE for more than one kind of summary (e.g. [COUNT, ROWPCT]).
-dnl   * MISSING, OTHERNM
-dnl   * multi-dimensional (multiple CCT_POSTCOMPUTE in one cell)
 dnl   * dates
-dnl - PPROPERTIES:
-dnl   * )LABEL[N].
 dnl - Summary functions:
 dnl   * U-prefix for unweighted summaries.
 dnl   * areaPCT.SUM and UareaPCT.SUM functions.
@@ -1612,40 +1607,202 @@ AT_CHECK([pspp ctables.sps -O box=unicode -O width=120], [0], [dnl
 AT_CLEANUP
 
 AT_SETUP([CTABLES PCOMPUTE])
+AT_KEYWORDS([postcompute])
 AT_CHECK([ln $top_srcdir/examples/nhtsa.sav . || cp $top_srcdir/examples/nhtsa.sav .])
 AT_DATA([ctables.sps],
 [[GET 'nhtsa.sav'.
 CTABLES
     /PCOMPUTE &x=EXPR([3] + [4])
     /PCOMPUTE &y=EXPR([4] + [5])
-    /PPROPERTIES &x LABEL='3+4' HIDESOURCECATS=YES FORMAT=COUNT F8.2
-    /PPROPERTIES &y LABEL='4+5'
-    /TABLE=qn105ba BY qns1
-    /CATEGORIES VARIABLES=qns1 [1, 2, SUBTOTAL, 3, 4, 5, &x, &y, SUBTOTAL]
+    /PPROPERTIES &x LABEL='3+4' FORMAT=COUNT F8.2
+    /PPROPERTIES &y LABEL=')LABEL[5]+)LABEL[6]'
+    /TABLE=qn105ba [COUNT, ROWPCT] BY qns1
+    /CATEGORIES VARIABLES=qns1 [1, 2, SUBTOTAL, 3, 4, 5, &x, &y, SUBTOTAL] TOTAL=YES
+
+* Adding HIDESOURCECATS=YES for one PPROPERTIES.
+CTABLES
+    /PCOMPUTE &x=EXPR([3] + [4])
+    /PCOMPUTE &y=EXPR([4] + [5])
+    /PPROPERTIES &x LABEL='3+4' FORMAT=COUNT F8.2
+    /PPROPERTIES &y LABEL=')LABEL[5]+)LABEL[6]' HIDESOURCECATS=YES
+    /TABLE=qn105ba [COUNT, ROWPCT] BY qns1
+    /CATEGORIES VARIABLES=qns1 [1, 2, SUBTOTAL, 3, 4, 5, &x, &y, SUBTOTAL] TOTAL=YES
 ]])
-AT_CHECK([pspp ctables.sps -O box=unicode -O width=120], [0], [dnl
-                                                      Custom Tables
-╭────────────────────────────────────────────────────────┬─────────────────────────────────────────────────────────────╮
-│                                                        │  S1. Including yourself, how many members of this household │
-│                                                        │                     are age 16 or older?                    │
-│                                                        ├───────┬───────┬──────────┬───────┬────────┬──────┬──────────┤
-│                                                        │   1   │   2   │ Subtotal │   5   │   3+4  │  4+5 │ Subtotal │
-│                                                        ├───────┼───────┼──────────┼───────┼────────┼──────┼──────────┤
-│                                                        │ Count │ Count │   Count  │ Count │  Count │ Count│   Count  │
-├────────────────────────────────────────────────────────┼───────┼───────┼──────────┼───────┼────────┼──────┼──────────┤
-│105b. How likely is it that drivers who have Almost     │    147│    246│       393│     11│   81.00│    30│        92│
-│had too much to drink to drive safely will   certain    │       │       │          │       │        │      │          │
-│A. Get stopped by the police?                Very likely│    384│    552│       936│     14│  171.00│    65│       185│
-│                                             Somewhat   │    590│   1249│      1839│     20│  265.00│    92│       285│
-│                                             likely     │       │       │          │       │        │      │          │
-│                                             Somewhat   │    278│    647│       925│      6│  116.00│    38│       122│
-│                                             unlikely   │       │       │          │       │        │      │          │
-│                                             Very       │    141│    290│       431│      4│   59.00│    22│        63│
-│                                             unlikely   │       │       │          │       │        │      │          │
-╰────────────────────────────────────────────────────────┴───────┴───────┴──────────┴───────┴────────┴──────┴──────────╯
+AT_CHECK([pspp ctables.sps -O box=unicode -O width=140], [0], [dnl
+                                                                Custom Tables
+╭───────────────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
+│                   │                    S1. Including yourself, how many members of this household are age 16 or older?                   │
+│                   ├───────────┬───────────┬───────────┬───────────┬──────────┬──────────┬────────────┬──────────┬───────────┬────────────┤
+│                   │     1     │     2     │  Subtotal │     3     │     4    │     5    │     3+4    │    4+5   │  Subtotal │    Total   │
+│                   ├─────┬─────┼─────┬─────┼─────┬─────┼─────┬─────┼─────┬────┼─────┬────┼──────┬─────┼─────┬────┼─────┬─────┼─────┬──────┤
+│                   │     │     │     │     │     │     │     │     │     │ Row│     │ Row│      │     │     │ Row│     │     │     │      │
+│                   │Count│Row %│Count│Row %│Count│Row %│Count│Row %│Count│  % │Count│  % │ Count│Row %│Count│  % │Count│Row %│Count│ Row %│
+├───────────────────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼────┼─────┼────┼──────┼─────┼─────┼────┼─────┼─────┼─────┼──────┤
+│105b. How  Almost  │  147│30.3%│  246│50.7%│  393│81.0%│   62│12.8%│   19│3.9%│   11│2.3%│ 81.00│16.7%│   30│6.2%│   92│19.0%│  485│100.0%│
+│likely is  certain │     │     │     │     │     │     │     │     │     │    │     │    │      │     │     │    │     │     │     │      │
+│it that            │     │     │     │     │     │     │     │     │     │    │     │    │      │     │     │    │     │     │     │      │
+│drivers    Very    │  384│34.3%│  552│49.2%│  936│83.5%│  120│10.7%│   51│4.5%│   14│1.2%│171.00│15.3%│   65│5.8%│  185│16.5%│ 1121│100.0%│
+│who have   likely  │     │     │     │     │     │     │     │     │     │    │     │    │      │     │     │    │     │     │     │      │
+│had too            │     │     │     │     │     │     │     │     │     │    │     │    │      │     │     │    │     │     │     │      │
+│much to    Somewhat│  590│27.8%│ 1249│58.8%│ 1839│86.6%│  193│ 9.1%│   72│3.4%│   20│ .9%│265.00│12.5%│   92│4.3%│  285│13.4%│ 2124│100.0%│
+│drink to   likely  │     │     │     │     │     │     │     │     │     │    │     │    │      │     │     │    │     │     │     │      │
+│drive              │     │     │     │     │     │     │     │     │     │    │     │    │      │     │     │    │     │     │     │      │
+│safely     Somewhat│  278│26.6%│  647│61.8%│  925│88.3%│   84│ 8.0%│   32│3.1%│    6│ .6%│116.00│11.1%│   38│3.6%│  122│11.7%│ 1047│100.0%│
+│will A.    unlikely│     │     │     │     │     │     │     │     │     │    │     │    │      │     │     │    │     │     │     │      │
+│Get                │     │     │     │     │     │     │     │     │     │    │     │    │      │     │     │    │     │     │     │      │
+│stopped by Very    │  141│28.5%│  290│58.7%│  431│87.2%│   41│ 8.3%│   18│3.6%│    4│ .8%│ 59.00│11.9%│   22│4.5%│   63│12.8%│  494│100.0%│
+│the        unlikely│     │     │     │     │     │     │     │     │     │    │     │    │      │     │     │    │     │     │     │      │
+│police?            │     │     │     │     │     │     │     │     │     │    │     │    │      │     │     │    │     │     │     │      │
+╰───────────────────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴────┴─────┴────┴──────┴─────┴─────┴────┴─────┴─────┴─────┴──────╯
+
+                                                                Custom Tables
+╭─────────────────────────────────────────┬────────────────────────────────────────────────────────────────────────────────────────────────╮
+│                                         │         S1. Including yourself, how many members of this household are age 16 or older?        │
+│                                         ├───────────┬───────────┬───────────┬───────────┬────────────┬──────────┬───────────┬────────────┤
+│                                         │     1     │     2     │  Subtotal │     3     │     3+4    │    4+5   │  Subtotal │    Total   │
+│                                         ├─────┬─────┼─────┬─────┼─────┬─────┼─────┬─────┼──────┬─────┼─────┬────┼─────┬─────┼─────┬──────┤
+│                                         │     │     │     │     │     │     │     │     │      │     │     │ Row│     │     │     │      │
+│                                         │Count│Row %│Count│Row %│Count│Row %│Count│Row %│ Count│Row %│Count│  % │Count│Row %│Count│ Row %│
+├─────────────────────────────────────────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼──────┼─────┼─────┼────┼─────┼─────┼─────┼──────┤
+│105b. How likely is it that    Almost    │  147│30.3%│  246│50.7%│  393│81.0%│   62│12.8%│ 81.00│16.7%│   30│6.2%│   92│19.0%│  485│100.0%│
+│drivers who have had too much  certain   │     │     │     │     │     │     │     │     │      │     │     │    │     │     │     │      │
+│to drink to drive safely will  Very      │  384│34.3%│  552│49.2%│  936│83.5%│  120│10.7%│171.00│15.3%│   65│5.8%│  185│16.5%│ 1121│100.0%│
+│A. Get stopped by the police?  likely    │     │     │     │     │     │     │     │     │      │     │     │    │     │     │     │      │
+│                               Somewhat  │  590│27.8%│ 1249│58.8%│ 1839│86.6%│  193│ 9.1%│265.00│12.5%│   92│4.3%│  285│13.4%│ 2124│100.0%│
+│                               likely    │     │     │     │     │     │     │     │     │      │     │     │    │     │     │     │      │
+│                               Somewhat  │  278│26.6%│  647│61.8%│  925│88.3%│   84│ 8.0%│116.00│11.1%│   38│3.6%│  122│11.7%│ 1047│100.0%│
+│                               unlikely  │     │     │     │     │     │     │     │     │      │     │     │    │     │     │     │      │
+│                               Very      │  141│28.5%│  290│58.7%│  431│87.2%│   41│ 8.3%│ 59.00│11.9%│   22│4.5%│   63│12.8%│  494│100.0%│
+│                               unlikely  │     │     │     │     │     │     │     │     │      │     │     │    │     │     │     │      │
+╰─────────────────────────────────────────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴──────┴─────┴─────┴────┴─────┴─────┴─────┴──────╯
+])
+AT_CLEANUP
+
+AT_SETUP([CTABLES PCOMPUTE - OTHERNM and MISSING])
+AT_KEYWORDS([postcompute])
+AT_CHECK([ln $top_srcdir/examples/nhtsa.sav . || cp $top_srcdir/examples/nhtsa.sav .])
+AT_DATA([ctables.sps],
+[[GET 'nhtsa.sav'.
+CTABLES
+    /PCOMPUTE &x=EXPR(OTHERNM)
+    /PCOMPUTE &y=EXPR(MISSING)
+    /PPROPERTIES &x LABEL='Drivers'
+    /PPROPERTIES &y LABEL='Missing Values 2'
+    /TABLE=qn1 BY qns3a
+    /CATEGORIES VARIABLES=qn1 [OTHERNM, 5, &x, SUBTOTAL='Valid Values', MISSING, SUBTOTAL='Missing Values', &y]
+]])
+AT_CHECK([pspp ctables.sps -O box=unicode -O width=140], [0], [dnl
+                                              Custom Tables
+╭──────────────────────────────────────────────────────────────────────────────────────────┬────────────╮
+│                                                                                          │S3a. GENDER:│
+│                                                                                          ├─────┬──────┤
+│                                                                                          │ Male│Female│
+│                                                                                          ├─────┼──────┤
+│                                                                                          │Count│ Count│
+├──────────────────────────────────────────────────────────────────────────────────────────┼─────┼──────┤
+│ 1. How often do you usually drive a car or other motor vehicle? Every day                │ 2305│  2362│
+│                                                                 Several days a week      │  440│   834│
+│                                                                 Once a week or less      │  125│   236│
+│                                                                 Only certain times a year│   58│    72│
+│                                                                 Never                    │  192│   348│
+│                                                                 Drivers                  │ 2928│  3504│
+│                                                                 Valid Values             │ 3120│  3852│
+│                                                                 Don't know               │    3│     5│
+│                                                                 Refused                  │    9│    10│
+│                                                                 Missing Values           │   12│    15│
+│                                                                 Missing Values 2         │   12│    15│
+╰──────────────────────────────────────────────────────────────────────────────────────────┴─────┴──────╯
 ])
 AT_CLEANUP
 
+AT_SETUP([CTABLES PCOMPUTE - THRU])
+AT_KEYWORDS([postcompute])
+AT_CHECK([ln $top_srcdir/examples/nhtsa.sav . || cp $top_srcdir/examples/nhtsa.sav .])
+AT_DATA([ctables.sps],
+[[GET 'nhtsa.sav'.
+CTABLES
+    /PCOMPUTE &x=EXPR([1 THRU 2])
+    /PCOMPUTE &y=EXPR([3 THRU 4])
+    /PCOMPUTE &z=EXPR([5] + MISSING)
+    /PPROPERTIES &x LABEL='Frequent Drivers'
+    /PPROPERTIES &y LABEL='Infrequent Drivers'
+    /PPROPERTIES &z LABEL='Not Drivers or Missing'
+    /TABLE=qn1 BY qns3a
+    /CATEGORIES VARIABLES=qn1 [1 THRU 2, &x, 3 THRU 4, &y, SUBTOTAL='Drivers', 5, MISSING, &z]
+]])
+AT_CHECK([pspp ctables.sps -O box=unicode -O width=140], [0], [dnl
+                                              Custom Tables
+╭──────────────────────────────────────────────────────────────────────────────────────────┬────────────╮
+│                                                                                          │S3a. GENDER:│
+│                                                                                          ├─────┬──────┤
+│                                                                                          │ Male│Female│
+│                                                                                          ├─────┼──────┤
+│                                                                                          │Count│ Count│
+├──────────────────────────────────────────────────────────────────────────────────────────┼─────┼──────┤
+│ 1. How often do you usually drive a car or other motor vehicle? Every day                │ 2305│  2362│
+│                                                                 Several days a week      │  440│   834│
+│                                                                 Frequent Drivers         │ 2745│  3196│
+│                                                                 Once a week or less      │  125│   236│
+│                                                                 Only certain times a year│   58│    72│
+│                                                                 Infrequent Drivers       │  183│   308│
+│                                                                 Drivers                  │ 2928│  3504│
+│                                                                 Never                    │  192│   348│
+│                                                                 Don't know               │    3│     5│
+│                                                                 Refused                  │    9│    10│
+│                                                                 Not Drivers or Missing   │  204│   363│
+╰──────────────────────────────────────────────────────────────────────────────────────────┴─────┴──────╯
+])
+AT_CLEANUP
+
+dnl I'm not sure that this is the correct behavior (see
+dnl https://mail.gnu.org/archive/html/pspp-users/2022-07/msg00002.html)
+dnl but at least this test will notify us if the behavior changes.
+AT_SETUP([CTABLES intersecting PCOMPUTEs])
+AT_KEYWORDS([PCOMPUTE postcompute])
+AT_DATA([ctables.sps],
+[[DATA LIST LIST NOTABLE/x y z.
+WEIGHT by z.
+FORMATS ALL (F1.0).
+VARIABLE LEVEL x y (NOMINAL).
+BEGIN DATA.
+1 4 5
+1 5 2
+1 6 9
+2 4 2
+2 5 3
+2 6 4
+3 4 1
+3 5 6
+3 6 1
+END DATA.
+
+CTABLES
+    /PCOMPUTE &a = EXPR([1] + [2])
+    /PCOMPUTE &b = EXPR([2] + [3])
+    /PCOMPUTE &c = EXPR([4] * [5])
+    /PCOMPUTE &d = EXPR([5] * [6])
+    /TABLE x BY y
+    /CATEGORIES VARIABLES=x [1, &a, 2, &b, 3]
+    /CATEGORIES VARIABLES=y [4, &c, 5, &d, 6].
+]])
+AT_CHECK([pspp ctables.sps -O box=unicode], [0],
+[[                   Custom Tables
+╭───────────┬─────────────────────────────────────╮
+│           │                  y                  │
+│           ├─────┬─────────┬─────┬─────────┬─────┤
+│           │  4  │[4] * [5]│  5  │[5] * [6]│  6  │
+│           ├─────┼─────────┼─────┼─────────┼─────┤
+│           │Count│  Count  │Count│  Count  │Count│
+├───────────┼─────┼─────────┼─────┼─────────┼─────┤
+│x 1        │    5│       10│    2│       18│    9│
+│  [1] + [2]│    7│        .│    5│        .│   13│
+│  2        │    2│        6│    3│       12│    4│
+│  [2] + [3]│    3│        .│    9│        .│    5│
+│  3        │    1│        6│    6│        6│    1│
+╰───────────┴─────┴─────────┴─────┴─────────┴─────╯
+]])
+AT_CLEANUP
+
 AT_SETUP([CTABLES CLABELS])
 AT_CHECK([ln $top_srcdir/examples/nhtsa.sav . || cp $top_srcdir/examples/nhtsa.sav .])
 AT_DATA([ctables.sps],
@@ -1656,7 +1813,6 @@ CTABLES /TABLE AgeGroup BY qns3a /CLABELS COLLABELS=OPPOSITE.
 CTABLES /TABLE AgeGroup BY qns3a /CLABELS ROWLABELS=LAYER.
 CTABLES /TABLE AgeGroup BY qns3a /CLABELS COLLABELS=LAYER.
 ]])
-pwd
 AT_CHECK([pspp ctables.sps --table-look="$builddir"/all-layers.stt -O box=unicode -O width=120], [0], [dnl
              Custom Tables
 ╭───────────────────────┬────────────╮
@@ -3230,16 +3386,91 @@ AT_CHECK([pspp ctables.sps -O box=unicode -O width=120], [0], [dnl
 AT_CLEANUP
 
 
-AT_SETUP([CTABLES scale summary functions - assertion failure])
+AT_SETUP([CTABLES hidden scale VLABELS])
 AT_CHECK([ln $top_srcdir/examples/nhtsa.sav . || cp $top_srcdir/examples/nhtsa.sav .])
 AT_DATA([ctables.sps],
 [[GET 'nhtsa.sav'.
+CTABLES
+    /TABLE region BY qn19a + qn35
+    /SLABELS POSITION=ROW.
 CTABLES
     /VLABELS VARIABLE=qn19a DISPLAY=NONE
-    /TABLE region BY qn19a
-    /CATEGORIES VARIABLES=qn19a TOTAL=YES MISSING=INCLUDE
+    /TABLE region BY qn19a + qn35
+    /SLABELS POSITION=ROW.
+CTABLES
+    /VLABELS VARIABLE=qn35 DISPLAY=NONE
+    /TABLE region BY qn19a + qn35
+    /SLABELS POSITION=ROW.
+
+* This one in particular caused a crash because no categories were
+  created on the column axis, so passing in 0 for the index was still
+  too big for that number of categories.  It was fixed by creating a
+  name-only category for each variable despite the "NONE" request,
+  then hiding the entire dimension's labels if all its labels were
+  set to "NONE".
+CTABLES
+    /VLABELS VARIABLE=qn19a qn35 DISPLAY=NONE
+    /TABLE region BY qn19a + qn35
     /SLABELS POSITION=ROW.
 ]])
-AT_CHECK([pspp ctables.sps -O box=unicode -O width=120], [0], [])
+AT_CHECK([pspp ctables.sps -O box=unicode], [0], [dnl
+                                 Custom Tables
+╭──────────────┬────────────────────────────┬─────────────────────────────────╮
+│              │ 19a. About how old were you│ 35. In the past thirty days, how│
+│              │   when you first starting  │   many times have you driven a  │
+│              │    drinking alcohol, not   │  motor vehicle WITHIN TWO HOURS │
+│              │  counting small tastes or  │     AFTER drinking alcoholic    │
+│              │      sips of alcohol.      │            beverages?           │
+├──────────────┼────────────────────────────┼─────────────────────────────────┤
+│Region NE Mean│                       19.33│                                2│
+│      ╶───────┼────────────────────────────┼─────────────────────────────────┤
+│       MW Mean│                       19.83│                                2│
+│      ╶───────┼────────────────────────────┼─────────────────────────────────┤
+│       S  Mean│                       20.29│                                2│
+│      ╶───────┼────────────────────────────┼─────────────────────────────────┤
+│       W  Mean│                       19.87│                                2│
+╰──────────────┴────────────────────────────┴─────────────────────────────────╯
+
+                                 Custom Tables
+╭──────────────┬─────┬────────────────────────────────────────────────────────╮
+│              │     │  35. In the past thirty days, how many times have you  │
+│              │     │ driven a motor vehicle WITHIN TWO HOURS AFTER drinking │
+│              │QN19A│                  alcoholic beverages?                  │
+├──────────────┼─────┼────────────────────────────────────────────────────────┤
+│Region NE Mean│19.33│                                                       2│
+│      ╶───────┼─────┼────────────────────────────────────────────────────────┤
+│       MW Mean│19.83│                                                       2│
+│      ╶───────┼─────┼────────────────────────────────────────────────────────┤
+│       S  Mean│20.29│                                                       2│
+│      ╶───────┼─────┼────────────────────────────────────────────────────────┤
+│       W  Mean│19.87│                                                       2│
+╰──────────────┴─────┴────────────────────────────────────────────────────────╯
+
+                                 Custom Tables
+╭──────────────┬─────────────────────────────────────────────────────────┬────╮
+│              │   19a. About how old were you when you first starting   │    │
+│              │  drinking alcohol, not counting small tastes or sips of │    │
+│              │                         alcohol.                        │qn35│
+├──────────────┼─────────────────────────────────────────────────────────┼────┤
+│Region NE Mean│                                                    19.33│   2│
+│      ╶───────┼─────────────────────────────────────────────────────────┼────┤
+│       MW Mean│                                                    19.83│   2│
+│      ╶───────┼─────────────────────────────────────────────────────────┼────┤
+│       S  Mean│                                                    20.29│   2│
+│      ╶───────┼─────────────────────────────────────────────────────────┼────┤
+│       W  Mean│                                                    19.87│   2│
+╰──────────────┴─────────────────────────────────────────────────────────┴────╯
+
+      Custom Tables
+╭──────────────┬───────╮
+│Region NE Mean│19.33 2│
+│      ╶───────┼───────┤
+│       MW Mean│19.83 2│
+│      ╶───────┼───────┤
+│       S  Mean│20.29 2│
+│      ╶───────┼───────┤
+│       W  Mean│19.87 2│
+╰──────────────┴───────╯
+])
 AT_CLEANUP