dnl PSPP - a program for statistical analysis.
dnl Copyright (C) 2017 Free Software Foundation, Inc.
dnl
dnl This program is free software: you can redistribute it and/or modify
dnl it under the terms of the GNU General Public License as published by
dnl the Free Software Foundation, either version 3 of the License, or
dnl (at your option) any later version.
dnl
dnl This program is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
dnl GNU General Public License for more details.
dnl
dnl You should have received a copy of the GNU General Public License
dnl along with this program.  If not, see <http://www.gnu.org/licenses/>.
dnl
AT_BANNER([T-TEST])

AT_SETUP([T-TEST /PAIRS])
AT_DATA([t-test.sps], [dnl
data list list /ID * A * B *.
begin data.
1 2.0 3.0
2 1.0 2.0
3 2.0 4.5
4 2.0 4.5
5 3.0 6.0
end data.

t-test /PAIRS a with b (PAIRED).
])

AT_CHECK([pspp -o pspp.csv -o pspp.txt t-test.sps])
AT_CHECK([cat pspp.csv], [0], [dnl
Table: Reading free-form data from INLINE.
Variable,Format
ID,F8.0
A,F8.0
B,F8.0

Table: Paired Sample Statistics
,,N,Mean,Std. Deviation,S.E. Mean
Pair 1,A,5,2.00,.71,.32
,B,5,4.00,1.54,.69

Table: Paired Samples Correlations
,,N,Correlation,Sig.
Pair 1,A & B,5,.918,.028

Table: Paired Samples Test
,,Paired Differences,,,,,t,df,Sig. (2-tailed)
,,Mean,Std. Deviation,S.E. Mean,95% Confidence Interval of the Difference,,,,
,,,,,Lower,Upper,,,
Pair 1,A - B,-2.00,.94,.42,-3.16,-.84,-4.78,4,.009
])
AT_CLEANUP


AT_SETUP([T-TEST /PAIRS with duplicate variables in list])

AT_DATA([ref.sps], [dnl
data list list /id * a * b * c * d *.
begin data.
1 2.0 3.0 4.0 4.0
2 1.0 2.0 5.1 3.9
3 2.0 4.5 5.2 3.8
4 2.0 4.5 5.3 3.7
56 3.0 6.0 5.9 3.6
end data.

t-test /PAIRS a c a with b d c (PAIRED).
])

AT_DATA([expout], [dnl
Table: Reading free-form data from INLINE.
Variable,Format
id,F8.0
a,F8.0
b,F8.0
c,F8.0
d,F8.0

Table: Paired Sample Statistics
,,N,Mean,Std. Deviation,S.E. Mean
Pair 1,a,5,2.00,.71,.32
,b,5,4.00,1.54,.69
Pair 2,c,5,5.10,.69,.31
,d,5,3.80,.16,.07
Pair 3,a,5,2.00,.71,.32
,c,5,5.10,.69,.31

Table: Paired Samples Correlations
,,N,Correlation,Sig.
Pair 1,a & b,5,.918,.028
Pair 2,c & d,5,-.918,.028
Pair 3,a & c,5,.410,.493

Table: Paired Samples Test
,,Paired Differences,,,,,t,df,Sig. (2-tailed)
,,Mean,Std. Deviation,S.E. Mean,95% Confidence Interval of the Difference,,,,
,,,,,Lower,Upper,,,
Pair 1,a - b,-2.00,.94,.42,-3.16,-.84,-4.78,4,.009
Pair 2,c - d,1.30,.84,.37,.26,2.34,3.47,4,.025
Pair 3,a - c,-3.10,.76,.34,-4.04,-2.16,-9.14,4,.001
])

AT_CHECK([pspp -o ref.csv ref.sps])
AT_CHECK([cat ref.csv], [0], [expout])
AT_CLEANUP

AT_SETUP([T-TEST /PAIRS with per-analysis missing values])

AT_DATA([ref.sps], [dnl
data list list /id * a * b * c * d *.
begin data.
1 2.0 3.0 4.0 4.0
2 1.0 2.0 5.1 3.9
3 2.0 4.5 5.2 3.8
4 2.0 4.5 5.3 3.7
56 3.0 6.0 5.9 3.6
end data.

t-test /PAIRS a c with b d (PAIRED).
])

AT_DATA([expout], [dnl
Table: Reading free-form data from INLINE.
Variable,Format
id,F8.0
a,F8.0
b,F8.0
c,F8.0
d,F8.0

Table: Paired Sample Statistics
,,N,Mean,Std. Deviation,S.E. Mean
Pair 1,a,5,2.00,.71,.32
,b,5,4.00,1.54,.69
Pair 2,c,5,5.10,.69,.31
,d,5,3.80,.16,.07

Table: Paired Samples Correlations
,,N,Correlation,Sig.
Pair 1,a & b,5,.918,.028
Pair 2,c & d,5,-.918,.028

Table: Paired Samples Test
,,Paired Differences,,,,,t,df,Sig. (2-tailed)
,,Mean,Std. Deviation,S.E. Mean,95% Confidence Interval of the Difference,,,,
,,,,,Lower,Upper,,,
Pair 1,a - b,-2.00,.94,.42,-3.16,-.84,-4.78,4,.009
Pair 2,c - d,1.30,.84,.37,.26,2.34,3.47,4,.025
])

AT_CHECK([pspp -o ref.csv ref.sps])
AT_CHECK([cat ref.csv], [0], [expout])
AT_DATA([missing.sps], [dnl
data list list /id * a * b * c * d *.
begin data.
1 2.0 3.0 4.0 4.0
2 1.0 2.0 5.1 3.9
3 2.0 4.5 5.2 3.8
4 2.0 4.5 5.3 3.7
5 3.0 6.0 5.9 .
6 3.0  .  5.9 3.6
end data.


t-test /MISSING=analysis /PAIRS a c with b d (PAIRED) /CRITERIA=CI(0.95).
])

AT_CHECK([pspp -o missing.csv missing.sps])
AT_CHECK([cat missing.csv], [0], [expout])
AT_CLEANUP

AT_SETUP([T-TEST /PAIRS with listwise missing values])
AT_DATA([ref.sps], [dnl
data list list /id * a * b * c * d *.
begin data.
1 2.0 3.0 4.0 4.0
2 1.0 2.0 5.1 3.9
3 2.0 4.5 5.2 3.8
4 2.0 4.5 5.3 3.7
5 3.0 6.0 5.9 3.6
end data.

t-test /PAIRS a b with c d (PAIRED).
])

AT_DATA([expout], [dnl
Table: Reading free-form data from INLINE.
Variable,Format
id,F8.0
a,F8.0
b,F8.0
c,F8.0
d,F8.0

Table: Paired Sample Statistics
,,N,Mean,Std. Deviation,S.E. Mean
Pair 1,a,5,2.00,.71,.32
,c,5,5.10,.69,.31
Pair 2,b,5,4.00,1.54,.69
,d,5,3.80,.16,.07

Table: Paired Samples Correlations
,,N,Correlation,Sig.
Pair 1,a & c,5,.410,.493
Pair 2,b & d,5,-.872,.054

Table: Paired Samples Test
,,Paired Differences,,,,,t,df,Sig. (2-tailed)
,,Mean,Std. Deviation,S.E. Mean,95% Confidence Interval of the Difference,,,,
,,,,,Lower,Upper,,,
Pair 1,a - c,-3.10,.76,.34,-4.04,-2.16,-9.14,4,.001
Pair 2,b - d,.20,1.68,.75,-1.89,2.29,.27,4,.803
])

AT_CHECK([pspp -o ref.csv ref.sps])

AT_CHECK([cat ref.csv], [0], [expout])

AT_DATA([missing.sps], [dnl
data list list /id * a * b * c * d *.
begin data.
1 2.0 3.0 4.0 4.0
2 1.0 2.0 5.1 3.9
3 2.0 4.5 5.2 3.8
4 2.0 4.5 5.3 3.7
5 3.0 6.0 5.9 3.6
6 3.0 6.0 5.9  .
end data.


t-test /MISSING=listwise /PAIRS a b with c d (PAIRED).
])
AT_CHECK([pspp -o missing.csv missing.sps])
AT_CHECK([cat missing.csv], [0], [expout])
AT_CLEANUP


dnl Tests for a bug in the paired samples T test when weighted
dnl Thanks to Douglas Bonett for reporting this.
AT_SETUP([T-TEST weighted paired bug])
AT_DATA([t-test.sps], [dnl
DATA LIST notable LIST /x y w *.
BEGIN DATA.
1 1 255
1 2 43
1 3 216
2 1 3
2 2 1
2 3 12
END DATA.

WEIGHT BY w.

T-TEST
        PAIRS =  y WITH  x (PAIRED)
        /MISSING=ANALYSIS
        /CRITERIA=CI(0.95).
])

AT_CHECK([pspp -o pspp.csv -o pspp.txt t-test.sps])
AT_CHECK([cat pspp.csv], [0], [dnl
Table: Paired Sample Statistics
,,N,Mean,Std. Deviation,S.E. Mean
Pair 1,y,530.00,1.94,.96,.04
,x,530.00,1.03,.17,.01

Table: Paired Samples Correlations
,,N,Correlation,Sig.
Pair 1,y & x,530.00,.114,.008

Table: Paired Samples Test
,,Paired Differences,,,,,t,df,Sig. (2-tailed)
,,Mean,Std. Deviation,S.E. Mean,95% Confidence Interval of the Difference,,,,
,,,,,Lower,Upper,,,
Pair 1,y - x,.91,.95,.04,.83,.99,22.07,529.00,.000
])
AT_CLEANUP


dnl Tests for a bug in the paired samples T test.
dnl Thanks to Mike Griffiths for reporting this problem.
AT_SETUP([T-TEST /PAIRS bug])
AT_DATA([t-test.sps], [dnl
set format f8.3.
data list list /A * B *.
begin data.
11 2
1  1
1  1
end data.

t-test pairs = a with b (paired).
])
AT_CHECK([pspp -o pspp.csv t-test.sps])
AT_CHECK([cat pspp.csv], [0], [dnl
Table: Reading free-form data from INLINE.
Variable,Format
A,F8.0
B,F8.0

Table: Paired Sample Statistics
,,N,Mean,Std. Deviation,S.E. Mean
Pair 1,A,3,4.333,5.774,3.333
,B,3,1.333,.577,.333

Table: Paired Samples Correlations
,,N,Correlation,Sig.
Pair 1,A & B,3,1.000,.000

Table: Paired Samples Test
,,Paired Differences,,,,,t,df,Sig. (2-tailed)
,,Mean,Std. Deviation,S.E. Mean,95% Confidence Interval of the Difference,,,,
,,,,,Lower,Upper,,,
Pair 1,A - B,3.000,5.196,3.000,-9.908,15.908,1.000,2,.423
])
AT_CLEANUP

AT_SETUP([T-TEST /GROUPS])
AT_DATA([t-test.sps], [dnl
data list list /ID * INDEP * DEP1 * DEP2 *.
begin data.
1  1.1 1 3
2  1.1 2 4
3  1.1 2 4
4  1.1 2 4
5  1.1 3 5
6  2.1 3 1
7  2.1 4 2
8  2.1 4 2
9  2.1 4 2
10 2.1 5 3
11 3.1 2 2
end data.

* Note that the last case should be IGNORED since it doesn't have a
  dependent variable of either 1.1 or 2.1.

t-test /GROUPS=indep(1.1,2.1) /var=dep1 dep2.
])

AT_CHECK([pspp -o pspp.csv -o pspp.txt t-test.sps])
AT_CHECK([cat pspp.csv], [0], [dnl
Table: Reading free-form data from INLINE.
Variable,Format
ID,F8.0
INDEP,F8.0
DEP1,F8.0
DEP2,F8.0

Table: Group Statistics
,Group,N,Mean,Std. Deviation,S.E. Mean
DEP1,1.10,5,2.00,.71,.32
,2.10,5,4.00,.71,.32
DEP2,1.10,5,4.00,.71,.32
,2.10,5,2.00,.71,.32

Table: Independent Samples Test
,,Levene's Test for Equality of Variances,,T-Test for Equality of Means,,,,,,
,,F,Sig.,t,df,Sig. (2-tailed),Mean Difference,Std. Error Difference,95% Confidence Interval of the Difference,
,,,,,,,,,Lower,Upper
DEP1,Equal variances assumed,.00,1.000,-4.47,8.00,.002,-2.00,.45,-3.03,-.97
,Equal variances not assumed,,,-4.47,8.00,.002,-2.00,.45,-3.03,-.97
DEP2,Equal variances assumed,.00,1.000,4.47,8.00,.002,2.00,.45,.97,3.03
,Equal variances not assumed,,,4.47,8.00,.002,2.00,.45,.97,3.03
])
AT_CLEANUP

AT_SETUP([T-TEST /GROUPS with one value for independent variable])
AT_DATA([t-test.sps], [dnl
data list list /INDEP * DEP *.
begin data.
       1        6
       1        6
       1        7
       1        6
       1       13
       1        4
       1        7
       1        9
       1        7
       1       12
       1       11
       2       11
       2        9
       2        8
       2        4
       2       16
       2        9
       2        9
       2        5
       2        4
       2       10
       2       14
end data.
t-test /groups=indep(1.514) /var=dep.
])

AT_CHECK([pspp -o pspp.csv -o pspp.txt t-test.sps])
AT_CHECK([cat pspp.csv], [0], [dnl
Table: Reading free-form data from INLINE.
Variable,Format
INDEP,F8.0
DEP,F8.0

Table: Group Statistics
,Group,N,Mean,Std. Deviation,S.E. Mean
DEP,≥    1.51,11,9.00,3.82,1.15
,<    1.51,11,8.00,2.86,.86

Table: Independent Samples Test
,,Levene's Test for Equality of Variances,,T-Test for Equality of Means,,,,,,
,,F,Sig.,t,df,Sig. (2-tailed),Mean Difference,Std. Error Difference,95% Confidence Interval of the Difference,
,,,,,,,,,Lower,Upper
DEP,Equal variances assumed,.17,.683,.69,20.00,.495,1.00,1.44,-2.00,4.00
,Equal variances not assumed,,,.69,18.54,.496,1.00,1.44,-2.02,4.02
])
AT_CLEANUP

AT_SETUP([T-TEST /GROUPS with per-analysis missing values])
AT_DATA([ref.sps], [dnl
data list list /id * indep * dep1 * dep2 *.
begin data.
1  1.0 3.5 6
2  1.0 2.0 5
3  1.0 2.0 4
4  2.0 3.5 3
56 2.0 3.0 1
end data.

t-test /group=indep /var=dep1, dep2.
])
AT_DATA([expout], [dnl
Table: Reading free-form data from INLINE.
Variable,Format
id,F8.0
indep,F8.0
dep1,F8.0
dep2,F8.0

Table: Group Statistics
,Group,N,Mean,Std. Deviation,S.E. Mean
dep1,1.00,3,2.50,.87,.50
,2.00,2,3.25,.35,.25
dep2,1.00,3,5.00,1.00,.58
,2.00,2,2.00,1.41,1.00

Table: Independent Samples Test
,,Levene's Test for Equality of Variances,,T-Test for Equality of Means,,,,,,
,,F,Sig.,t,df,Sig. (2-tailed),Mean Difference,Std. Error Difference,95% Confidence Interval of the Difference,
,,,,,,,,,Lower,Upper
dep1,Equal variances assumed,3.75,.148,-1.12,3.00,.346,-.75,.67,-2.89,1.39
,Equal variances not assumed,,,-1.34,2.78,.279,-.75,.56,-2.61,1.11
dep2,Equal variances assumed,.60,.495,2.85,3.00,.065,3.00,1.05,-.35,6.35
,Equal variances not assumed,,,2.60,1.68,.144,3.00,1.15,-2.98,8.98
])
AT_CHECK([pspp -o ref.csv ref.sps])
AT_CHECK([cat ref.csv], [0], [expout])
AT_DATA([missing.sps], [dnl
data list list /id * indep * dep1 * dep2.
begin data.
1 1.0 3.5 6
2 1.0 2.0 5
3 1.0 2.0 4
4 2.0 3.5 3
5 2.0 3.0 .
6 2.0 .   1
7  .  3.1 5
end data.

* Note that if the independent variable is missing, then it's implicitly
* listwise missing.

t-test /missing=analysis /group=indep /var=dep1 dep2.
])
AT_CHECK([pspp -o missing.csv missing.sps])
AT_CHECK([cat missing.csv], [0], [expout])
AT_CLEANUP

AT_SETUP([T-TEST /GROUPS with listwise missing values])
AT_DATA([ref.sps], [dnl
data list list /id * indep * dep1 * dep2.
begin data.
1 1.0 3.5 6
2 1.0 2.0 5
3 1.0 2.0 4
4 2.0 3.5 3
5 2.0 3.0 2
6 2.0 4.0 1
end data.

t-test /group=indep /var=dep1 dep2.
])

AT_DATA([expout], [dnl
Table: Reading free-form data from INLINE.
Variable,Format
id,F8.0
indep,F8.0
dep1,F8.0
dep2,F8.0

Table: Group Statistics
,Group,N,Mean,Std. Deviation,S.E. Mean
dep1,1.00,3,2.50,.87,.50
,2.00,3,3.50,.50,.29
dep2,1.00,3,5.00,1.00,.58
,2.00,3,2.00,1.00,.58

Table: Independent Samples Test
,,Levene's Test for Equality of Variances,,T-Test for Equality of Means,,,,,,
,,F,Sig.,t,df,Sig. (2-tailed),Mean Difference,Std. Error Difference,95% Confidence Interval of the Difference,
,,,,,,,,,Lower,Upper
dep1,Equal variances assumed,2.00,.230,-1.73,4.00,.158,-1.00,.58,-2.60,.60
,Equal variances not assumed,,,-1.73,3.20,.176,-1.00,.58,-2.77,.77
dep2,Equal variances assumed,.00,1.000,3.67,4.00,.021,3.00,.82,.73,5.27
,Equal variances not assumed,,,3.67,4.00,.021,3.00,.82,.73,5.27
])

AT_CHECK([pspp -o ref.csv ref.sps])
AT_CHECK([cat ref.csv], [0], [expout])
AT_DATA([missing.sps], [dnl
data list list /id * indep * dep1 * dep2 *.
begin data.
1 1.0 3.5 6
2 1.0 2.0 5
3 1.0 2.0 4
4 2.0 3.5 3
5 2.0 3.0 2
6 2.0 4.0 1
7 2.0 .   0
end data.

t-test /missing=listwise,exclude /group=indep /var=dep1, dep2.
])
AT_CHECK([pspp -o missing.csv missing.sps])
AT_CHECK([cat missing.csv], [0], [expout])
AT_CLEANUP

AT_SETUP([T-TEST /TESTVAL])
AT_DATA([t-test.sps], [dnl
data list list /ID * ABC *.
begin data.
1 3.5
2 2.0
3 2.0
4 3.5
5 3.0
6 4.0
end data.

t-test /testval=2.0 /var=abc.
])
AT_CHECK([pspp -o pspp.csv -o pspp.txt t-test.sps])
AT_CHECK([cat pspp.csv], [0], [dnl
Table: Reading free-form data from INLINE.
Variable,Format
ID,F8.0
ABC,F8.0

Table: One-Sample Statistics
,N,Mean,Std. Deviation,S.E. Mean
ABC,6,3.00,.84,.34

Table: One-Sample Test
,Test Value = 2,,,,,
,t,df,Sig. (2-tailed),Mean Difference,95% Confidence Interval of the Difference,
,,,,,Lower,Upper
ABC,2.93,5,.033,1.00,.12,1.88
])
AT_CLEANUP

AT_SETUP([T-TEST /TESTVAL with per-analysis missing values])
AT_DATA([ref.sps], [dnl
data list list /id * x1 * x2.
begin data.
1 3.5 34
2 2.0 10
3 2.0 23
4 3.5 98
5 3.0 23
67 4.0 8
end data.

t-test /testval=3.0 /var=x1 x2.
])
AT_DATA([expout], [dnl
Table: Reading free-form data from INLINE.
Variable,Format
id,F8.0
x1,F8.0
x2,F8.0

Table: One-Sample Statistics
,N,Mean,Std. Deviation,S.E. Mean
x1,6,3.00,.84,.34
x2,6,32.67,33.40,13.64

Table: One-Sample Test
,Test Value = 3,,,,,
,t,df,Sig. (2-tailed),Mean Difference,95% Confidence Interval of the Difference,
,,,,,Lower,Upper
x1,.00,5,1.000,.00,-.88,.88
x2,2.18,5,.082,29.67,-5.39,64.72
])
AT_CHECK([pspp -o ref.csv ref.sps])
AT_CHECK([cat ref.csv], [0], [expout])
AT_DATA([missing.sps], [dnl
data list list /id * x1 * x2.
begin data.
1 3.5 34
2 2.0 10
3 2.0 23
4 3.5 98
5 3.0 23
6 4.0 .
7  .  8
end data.

t-test /missing=analysis /testval=3.0 /var=x1 x2.
])
AT_CHECK([pspp -o missing.csv missing.sps])
AT_CHECK([cat missing.csv], [0], [expout])
AT_CLEANUP

AT_SETUP([T-TEST /TESTVAL with listwise missing values])
AT_DATA([ref.sps], [dnl
data list list /id * x1 * x2.
begin data.
1 3.5 34
2 2.0 10
3 2.0 23
4 3.5 98
5 3.0 23
end data.

t-test /testval=3.0 /var=x1 x2.
])
AT_DATA([expout], [dnl
Table: Reading free-form data from INLINE.
Variable,Format
id,F8.0
x1,F8.0
x2,F8.0

Table: One-Sample Statistics
,N,Mean,Std. Deviation,S.E. Mean
x1,5,2.80,.76,.34
x2,5,37.60,34.82,15.57

Table: One-Sample Test
,Test Value = 3,,,,,
,t,df,Sig. (2-tailed),Mean Difference,95% Confidence Interval of the Difference,
,,,,,Lower,Upper
x1,-.59,4,.587,-.20,-1.14,.74
x2,2.22,4,.090,34.60,-8.63,77.83
])
AT_CHECK([pspp -o ref.csv ref.sps])
AT_CHECK([cat ref.csv], [0], [expout])
AT_DATA([missing.sps], [dnl
data list list /id * x1 * x2.
begin data.
1 3.5 34
2 2.0 10
3 2.0 23
4 3.5 98
5 3.0 23
6 4.0 99
end data.

MISSING VALUES x2(99).

t-test /missing=listwise /testval=3.0 /var=x1 x2.
])
AT_CHECK([pspp -o missing.csv missing.sps])
AT_CHECK([cat missing.csv], [0], [expout])
AT_CLEANUP

AT_SETUP([T-TEST wih TEMPORARY transformation])
AT_DATA([ref.sps], [dnl
data list list /ind * x * .
begin data.
1 3.5
1 2.0
1 2.0
2 3.5
2 3.0
2 4.0
end data.

t-test /groups=ind(1,2) /var x.
])
AT_DATA([expout], [dnl
Table: Reading free-form data from INLINE.
Variable,Format
ind,F8.0
x,F8.0

Table: Group Statistics
,Group,N,Mean,Std. Deviation,S.E. Mean
x,1.00,3,2.50,.87,.50
,2.00,3,3.50,.50,.29

Table: Independent Samples Test
,,Levene's Test for Equality of Variances,,T-Test for Equality of Means,,,,,,
,,F,Sig.,t,df,Sig. (2-tailed),Mean Difference,Std. Error Difference,95% Confidence Interval of the Difference,
,,,,,,,,,Lower,Upper
x,Equal variances assumed,2.00,.230,-1.73,4.00,.158,-1.00,.58,-2.60,.60
,Equal variances not assumed,,,-1.73,3.20,.176,-1.00,.58,-2.77,.77
])
AT_CHECK([pspp -o ref.csv ref.sps])
AT_CHECK([cat ref.csv], [0], [expout])
AT_DATA([temporary.sps], [dnl
data list list /ind * x * .
begin data.
1 3.5
1 2.0
1 2.0
2 3.5
2 3.0
2 4.0
2 9.0
end data.

TEMPORARY.
SELECT IF x < 7.

t-test /groups=ind(1 2) /var x.
])
AT_CHECK([pspp -o temporary.csv temporary.sps])
AT_CHECK([cat temporary.csv], [0], [expout])
AT_CLEANUP

dnl This is an example from doc/tutorial.texi
dnl So if the results of this have to be changed in any way,
dnl make sure to update that file.
AT_SETUP([T-TEST tutorial example])
cp $top_srcdir/examples/physiology.sav .
AT_DATA([t-test.sps], [dnl
GET FILE='physiology.sav'.
RECODE height (179 = SYSMIS).
T-TEST GROUP=sex(0,1) /VARIABLES=height temperature.
])
AT_CHECK([pspp -o pspp.csv -o pspp.txt t-test.sps])
AT_CHECK([cat pspp.csv], [0], [dnl
Table: Group Statistics
,Group,N,Mean,Std. Deviation,S.E. Mean
Height in millimeters   ,Male,22,1796.49,49.71,10.60
,Female,17,1610.77,25.43,6.17
Internal body temperature in degrees Celcius,Male,22,36.68,1.95,.42
,Female,18,37.43,1.61,.38

Table: Independent Samples Test
,,Levene's Test for Equality of Variances,,T-Test for Equality of Means,,,,,,
,,F,Sig.,t,df,Sig. (2-tailed),Mean Difference,Std. Error Difference,95% Confidence Interval of the Difference,
,,,,,,,,,Lower,Upper
Height in millimeters   ,Equal variances assumed,.97,.331,14.02,37.00,.000,185.72,13.24,158.88,212.55
,Equal variances not assumed,,,15.15,32.71,.000,185.72,12.26,160.76,210.67
Internal body temperature in degrees Celcius,Equal variances assumed,.31,.581,-1.31,38.00,.198,-.75,.57,-1.91,.41
,Equal variances not assumed,,,-1.33,37.99,.190,-.75,.56,-1.89,.39
])
AT_CLEANUP

dnl Tests for a bug which caused T-TEST to crash when given invalid syntax.
AT_SETUP([T-TEST invalid syntax])
AT_DATA([t-test.sps], [dnl
DATA LIST LIST NOTABLE /id * a * .
BEGIN DATA.
1 3.5
2 2.0
3 2.0
4 3.5
5 3.0
6 4.0
END DATA.

T-TEST /testval=2.0 .
T-TEST /groups=id(3) .
])
AT_CHECK([pspp -O format=csv t-test.sps], [1], [dnl
"t-test.sps:11.1-11.21: error: T-TEST: Required subcommand VARIABLES was not specified.
   11 | T-TEST /testval=2.0 .
      | ^~~~~~~~~~~~~~~~~~~~~"

"t-test.sps:12.1-12.22: error: T-TEST: Required subcommand VARIABLES was not specified.
   12 | T-TEST /groups=id(3) .
      | ^~~~~~~~~~~~~~~~~~~~~~"
])
AT_CLEANUP

dnl Tests for bug #11227, exhibited when the independent variable is a string.
AT_SETUP([T-TEST string variable])
AT_DATA([t-test.sps], [dnl
data list list /ID * INDEP (a1) DEP1 * DEP2 *.
begin data.
1  'a' 1 3
2  'a' 2 4
3  'a' 2 4
4  'a' 2 4
5  'a' 3 5
6  'b' 3 1
7  'b' 4 2
8  'b' 4 2
9  'b' 4 2
10 'b' 5 3
11 'c' 2 2
end data.


t-test /GROUPS=indep('a','b') /var=dep1 dep2.
])

AT_CHECK([pspp -o pspp.csv -o pspp.txt t-test.sps])
AT_CHECK([cat pspp.csv], [0], [dnl
Table: Reading free-form data from INLINE.
Variable,Format
ID,F8.0
INDEP,A1
DEP1,F8.0
DEP2,F8.0

Table: Group Statistics
,Group,N,Mean,Std. Deviation,S.E. Mean
DEP1,a,5,2.00,.71,.32
,b,5,4.00,.71,.32
DEP2,a,5,4.00,.71,.32
,b,5,2.00,.71,.32

Table: Independent Samples Test
,,Levene's Test for Equality of Variances,,T-Test for Equality of Means,,,,,,
,,F,Sig.,t,df,Sig. (2-tailed),Mean Difference,Std. Error Difference,95% Confidence Interval of the Difference,
,,,,,,,,,Lower,Upper
DEP1,Equal variances assumed,.00,1.000,-4.47,8.00,.002,-2.00,.45,-3.03,-.97
,Equal variances not assumed,,,-4.47,8.00,.002,-2.00,.45,-3.03,-.97
DEP2,Equal variances assumed,.00,1.000,4.47,8.00,.002,2.00,.45,.97,3.03
,Equal variances not assumed,,,4.47,8.00,.002,2.00,.45,.97,3.03
])
AT_CLEANUP

AT_SETUP([T-TEST string variable, only one value])
AT_DATA([t-test.sps], [dnl
data list list notable /id * indep (a1) dep1 * dep2 *.
begin data.
1  'a' 1 3
2  'a' 2 4
3  'a' 2 4
4  'a' 2 4
5  'a' 3 5
6  'b' 3 1
7  'b' 4 2
8  'b' 4 2
9  'b' 4 2
10 'b' 5 3
11 'c' 2 2
end data.


t-test /GROUPS=indep('a') /var=dep1 dep2.
])
AT_CHECK([pspp -O format=csv t-test.sps], [1], [dnl
"t-test.sps:17.16-17.25: error: T-TEST: When applying GROUPS to a string variable, two values must be specified.
   17 | t-test /GROUPS=indep('a') /var=dep1 dep2.
      |                ^~~~~~~~~~"
])
AT_CLEANUP

dnl Tests for a bug which didn't properly compare string values.
AT_SETUP([T-TEST string variable comparison bug])
AT_DATA([t-test.sps], [dnl
data list list /x * gv (a8).
begin data.
3   One
2   One
3   One
2   One
3   One
4   Two
3.5 Two
3.0 Two
end data.

t-test group=gv('One', 'Two')
	/variables = x.
])

AT_CHECK([pspp -o pspp.csv -o pspp.txt t-test.sps])
AT_CHECK([cat pspp.csv], [0], [dnl
Table: Reading free-form data from INLINE.
Variable,Format
x,F8.0
gv,A8

Table: Group Statistics
,Group,N,Mean,Std. Deviation,S.E. Mean
x,One,5,2.60,.55,.24
,Two,3,3.50,.50,.29

Table: Independent Samples Test
,,Levene's Test for Equality of Variances,,T-Test for Equality of Means,,,,,,
,,F,Sig.,t,df,Sig. (2-tailed),Mean Difference,Std. Error Difference,95% Confidence Interval of the Difference,
,,,,,,,,,Lower,Upper
x,Equal variances assumed,1.13,.329,-2.32,6.00,.060,-.90,.39,-1.85,.05
,Equal variances not assumed,,,-2.38,4.70,.067,-.90,.38,-1.89,.09
])
AT_CLEANUP



dnl Tests for a bug assert failed when the group variables were not of either class
AT_SETUP([T-TEST wrong group])
AT_DATA([t-test-crs.sps], [dnl
data list list /x * g *.
begin data.
1 2
2 2
3 2
4 2
5 2
end data.

t-test /variables = x group=g(1,3).
])

AT_CHECK([pspp t-test-crs.sps], [0],[ignore], [ignore])

AT_CLEANUP



dnl Tests for a bug assert failed when a non-number was passes as the p value
AT_SETUP([T-TEST non number p value])
AT_DATA([t.sps], [dnl
data list list /age d_frage_1 weight height *.
begin data.
1 2 3 1
4 5 6 2
end data.

T-TEST /VARIABLES=age weight height
 /GROUPS=d_frage_1(1,0) /MISSING=ANALYSIS /CRITERIA=CIN(p.95).
])

AT_CHECK([pspp t.sps], [1],[ignore], [ignore])

AT_CLEANUP



dnl Another crash on invalid input
AT_SETUP([T-TEST unterminated string - paired])
AT_DATA([t.sps], [dnl
data list list /id * a * b * c * d *.
begin data.
5 2.0 3.0 4.0 4.0
3 1.0 2.0 5.1 3.9
3 2.0 4.5 5.2(3.8
4 2.0 4.5 5n3 3.7
5 3.0 6.0 5.9 3.6
6 3.4 6.0 5.9  .
end data.


t-test /MISSING=listwise /PAIRS a"b with c d (PA	RED).
]) dnl "

AT_CHECK([pspp t.sps],[1],[ignore],[ignore])

AT_CLEANUP

AT_SETUP([T-TEST syntax errors])
AT_DATA([t-test.sps], [dnl
DATA LIST LIST NOTABLE/x y z * s(a10).
T-TEST TESTVAL=**.
T-TEST GROUPS=**.
T-TEST GROUPS=x(**).
T-TEST GROUPS=x(1,**).
T-TEST GROUPS=x(1,2 **).
T-TEST GROUPS=s('a').
T-TEST VARIABLES=x y PAIRS.
T-TEST PAIRS=**.
T-TEST PAIRS=x WITH **.
T-TEST PAIRS=x WITH y z (PAIRED).
T-TEST PAIRS=x WITH y/VARIABLES.
T-TEST VARIABLES=**.
T-TEST MISSING=**.
T-TEST CRITERIA=**.
T-TEST CRITERIA=CIN**.
T-TEST CRITERIA=CIN(**).
T-TEST CRITERIA=CIN(1 **).
T-TEST **.
T-TEST MISSING=INCLUDE.
T-TEST MISSING=INCLUDE/TESTVAL=1.
])
AT_CHECK([pspp -O format=csv t-test.sps], [1], [dnl
"t-test.sps:2.16-2.17: error: T-TEST: Syntax error expecting number.
    2 | T-TEST TESTVAL=**.
      |                ^~"

"t-test.sps:3.15-3.16: error: T-TEST: Syntax error expecting variable name.
    3 | T-TEST GROUPS=**.
      |               ^~"

"t-test.sps:4.17-4.18: error: T-TEST: Syntax error expecting number.
    4 | T-TEST GROUPS=x(**).
      |                 ^~"

"t-test.sps:5.19-5.20: error: T-TEST: Syntax error expecting number.
    5 | T-TEST GROUPS=x(1,**).
      |                   ^~"

"t-test.sps:6.21-6.22: error: T-TEST: Syntax error expecting `)'.
    6 | T-TEST GROUPS=x(1,2 **).
      |                     ^~"

"t-test.sps:7.15-7.20: error: T-TEST: When applying GROUPS to a string variable, two values must be specified.
    7 | T-TEST GROUPS=s('a').
      |               ^~~~~~"

"t-test.sps:8.22-8.26: error: T-TEST: VARIABLES subcommand may not be used with PAIRS.
    8 | T-TEST VARIABLES=x y PAIRS.
      |                      ^~~~~"

"t-test.sps:9.14-9.15: error: T-TEST: Syntax error expecting variable name.
    9 | T-TEST PAIRS=**.
      |              ^~"

"t-test.sps:10.21-10.22: error: T-TEST: Syntax error expecting variable name.
   10 | T-TEST PAIRS=x WITH **.
      |                     ^~"

"t-test.sps:11.14-11.23: error: T-TEST: PAIRED was specified, but the number of variables preceding WITH (1) does not match the number following (2).
   11 | T-TEST PAIRS=x WITH y z (PAIRED).
      |              ^~~~~~~~~~"

"t-test.sps:12.23-12.31: error: T-TEST: VARIABLES subcommand may not be used with PAIRS.
   12 | T-TEST PAIRS=x WITH y/VARIABLES.
      |                       ^~~~~~~~~"

"t-test.sps:13.18-13.19: error: T-TEST: Syntax error expecting variable name.
   13 | T-TEST VARIABLES=**.
      |                  ^~"

"t-test.sps:14.16-14.17: error: T-TEST: Syntax error expecting INCLUDE, EXCLUDE, LISTWISE, or ANALYSIS.
   14 | T-TEST MISSING=**.
      |                ^~"

"t-test.sps:15.17-15.18: error: T-TEST: Syntax error expecting CIN or CI.
   15 | T-TEST CRITERIA=**.
      |                 ^~"

"t-test.sps:16.20-16.21: error: T-TEST: Syntax error expecting `('.
   16 | T-TEST CRITERIA=CIN**.
      |                    ^~"

"t-test.sps:17.21-17.22: error: T-TEST: Syntax error expecting number.
   17 | T-TEST CRITERIA=CIN(**).
      |                     ^~"

"t-test.sps:18.23-18.24: error: T-TEST: Syntax error expecting `)'.
   18 | T-TEST CRITERIA=CIN(1 **).
      |                       ^~"

"t-test.sps:19.8-19.9: error: T-TEST: Syntax error expecting TESTVAL, GROUPS, PAIRS, VARIABLES, MISSING, or CRITERIA.
   19 | T-TEST **.
      |        ^~"

"t-test.sps:20: error: T-TEST: Exactly one of TESTVAL, GROUPS and PAIRS subcommands must be specified."

"t-test.sps:21.1-21.33: error: T-TEST: Required subcommand VARIABLES was not specified.
   21 | T-TEST MISSING=INCLUDE/TESTVAL=1.
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
])
AT_CLEANUP
