Convert all Perl build tools to Python and remove Perl build dependency.
[pspp] / tests / language / stats / sort-cases.at
1 dnl PSPP - a program for statistical analysis.
2 dnl Copyright (C) 2017 Free Software Foundation, Inc.
3 dnl
4 dnl This program is free software: you can redistribute it and/or modify
5 dnl it under the terms of the GNU General Public License as published by
6 dnl the Free Software Foundation, either version 3 of the License, or
7 dnl (at your option) any later version.
8 dnl
9 dnl This program is distributed in the hope that it will be useful,
10 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
11 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 dnl GNU General Public License for more details.
13 dnl
14 dnl You should have received a copy of the GNU General Public License
15 dnl along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 dnl
17 AT_BANNER([SORT CASES])
18
19 m4_divert_push([PREPARE_TESTS])
20 [sort_cases_gen_data () {
21   cat > gen-data.py <<'EOF'
22 #! /usr/bin/python3
23
24 import random
25 import sys
26
27 data = []
28 for i in range(int(sys.argv[1])):
29     data += [i] * int(sys.argv[2])
30 random.shuffle(data)
31
32 data_txt = open('data.txt', 'w')
33 for i, item in enumerate(data):
34     data_txt.write('%s %s\n' % (item, i))
35 data_txt.close()
36
37 shuffled = ((item, i) for i, item in enumerate(data))
38 expout = open('expout', 'w')
39 for item, i in sorted(shuffled):
40     expout.write(' %8d %8d \n' % (item, i))
41 expout.close()
42 EOF
43   $PYTHON3 gen-data.py "$@"]
44 }
45 m4_divert_pop([PREPARE_TESTS])
46
47 m4_define([SORT_CASES_TEST],
48   [AT_SETUP([sort m4_eval([$1 * $2]) cases[]m4_if([$2], [1], [], [ ($1 unique)])[]m4_if([$3], [], [], [ with $3 buffers])])
49    AT_KEYWORDS([SORT CASES $4])
50    AT_CHECK([sort_cases_gen_data $1 $2 $3])
51    AT_CAPTURE_FILE([data.txt])
52    AT_CAPTURE_FILE([output.txt])
53    AT_CAPTURE_FILE([sort-cases.sps])
54    AT_DATA([sort-cases.sps], [dnl
55 DATA LIST LIST NOTABLE FILE='data.txt'/x y (F8).
56 SORT CASES BY x[]m4_if([$3], [], [], [/BUFFERS=$3]).
57 PRINT OUTFILE='output.txt'/x y.
58 EXECUTE.
59 ])
60    AT_CHECK([pspp --testing-mode -o pspp.csv sort-cases.sps])
61    AT_CHECK([cat output.txt], [0], [expout])
62    AT_CLEANUP])
63
64 SORT_CASES_TEST(100, 5, 2)
65 SORT_CASES_TEST(100, 5, 3)
66 SORT_CASES_TEST(100, 5, 4)
67 SORT_CASES_TEST(100, 5, 5)
68 SORT_CASES_TEST(100, 5, 10)
69 SORT_CASES_TEST(100, 5, 50)
70 SORT_CASES_TEST(100, 5, 100)
71 SORT_CASES_TEST(100, 5)
72
73 SORT_CASES_TEST(100, 10, 2)
74 SORT_CASES_TEST(100, 10, 3)
75 SORT_CASES_TEST(100, 10, 5)
76 SORT_CASES_TEST(100, 10)
77
78 SORT_CASES_TEST(1000, 5, 5, slow)
79 SORT_CASES_TEST(1000, 5, 50, slow)
80 SORT_CASES_TEST(1000, 5, [], slow)
81
82 SORT_CASES_TEST(100, 100, 3, slow)
83 SORT_CASES_TEST(100, 100, 5, slow)
84 SORT_CASES_TEST(100, 100, [], slow)
85
86 SORT_CASES_TEST(10000, 5, 500, slow)
87
88 SORT_CASES_TEST(50000, 1, [], slow)
89
90 dnl Bug #33089 caused SORT CASES to delete filtered cases permanently.
91 AT_SETUP([SORT CASES preserves filtered cases])
92 AT_DATA([sort-cases.sps], [dnl
93 DATA LIST FREE /x.
94 BEGIN DATA.
95 5 4 3 2 1 0
96 END DATA.
97 COMPUTE mod2 = MOD(x, 2).
98 LIST.
99 FILTER BY mod2.
100 LIST.
101 SORT CASES BY x.
102 LIST.
103 FILTER OFF.
104 LIST.
105 ])
106 AT_CHECK([pspp -O format=csv sort-cases.sps], [0], [dnl
107 Table: Data List
108 x,mod2
109 5.00,1.00
110 4.00,.00
111 3.00,1.00
112 2.00,.00
113 1.00,1.00
114 .00,.00
115
116 Table: Data List
117 x,mod2
118 5.00,1.00
119 3.00,1.00
120 1.00,1.00
121
122 Table: Data List
123 x,mod2
124 1.00,1.00
125 3.00,1.00
126 5.00,1.00
127
128 Table: Data List
129 x,mod2
130 .00,.00
131 1.00,1.00
132 2.00,.00
133 3.00,1.00
134 4.00,.00
135 5.00,1.00
136 ])
137 AT_CLEANUP