1 dnl PSPP - a program for statistical analysis.
2 dnl Copyright (C) 2017 Free Software Foundation, Inc.
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.
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.
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/>.
17 AT_BANNER([SORT CASES])
19 m4_divert_push([PREPARE_TESTS])
20 [sort_cases_gen_data () {
21 cat > gen-data.py <<'EOF'
28 for i in range(int(sys.argv[1])):
29 data += [i] * int(sys.argv[2])
32 data_txt = open('data.txt', 'w')
33 for i, item in enumerate(data):
34 data_txt.write('%s %s\n' % (item, i))
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))
43 $PYTHON3 gen-data.py "$@"]
45 m4_divert_pop([PREPARE_TESTS])
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.
60 AT_CHECK([pspp --testing-mode -o pspp.csv sort-cases.sps])
61 AT_CHECK([cat output.txt], [0], [expout])
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)
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)
78 SORT_CASES_TEST(1000, 5, 5, slow)
79 SORT_CASES_TEST(1000, 5, 50, slow)
80 SORT_CASES_TEST(1000, 5, [], slow)
82 SORT_CASES_TEST(100, 100, 3, slow)
83 SORT_CASES_TEST(100, 100, 5, slow)
84 SORT_CASES_TEST(100, 100, [], slow)
86 SORT_CASES_TEST(10000, 5, 500, slow)
88 SORT_CASES_TEST(50000, 1, [], slow)
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
97 COMPUTE mod2 = MOD(x, 2).
106 AT_CHECK([pspp -O format=csv sort-cases.sps], [0], [dnl