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.pl <<'EOF'
25 # Generate shuffled data.
27 for my $i (0...$ARGV[0] - 1) {
28 push (@data, ($i) x $ARGV[1]);
30 fisher_yates_shuffle (\@data);
32 # Output shuffled data.
33 my (@shuffled) = map ([$data[$_], $_], 0...$#data);
34 open (SHUFFLED, ">data.txt");
35 print SHUFFLED "$data[$_] $_\n" foreach 0...$#data;
38 my (@sorted) = sort { $a->[0] <=> $b->[0] || $a->[1] <=> $b->[1] } @shuffled;
39 open (SORTED, ">expout");
40 printf SORTED " %8d %8d \n", $_->[0], $_->[1] foreach @sorted;
43 sub fisher_yates_shuffle {
44 my $deck = shift; # $deck is a reference to an array
47 my $j = int rand ($i+1);
48 @$deck[$i,$j] = @$deck[$j,$i];
52 $PERL gen-data.pl "$@"]
54 m4_divert_pop([PREPARE_TESTS])
56 m4_define([SORT_CASES_TEST],
57 [AT_SETUP([sort m4_eval([$1 * $2]) cases[]m4_if([$2], [1], [], [ ($1 unique)])[]m4_if([$3], [], [], [ with $3 buffers])])
58 AT_KEYWORDS([SORT CASES $4])
59 AT_CHECK([sort_cases_gen_data $1 $2 $3])
60 AT_CAPTURE_FILE([data.txt])
61 AT_CAPTURE_FILE([output.txt])
62 AT_CAPTURE_FILE([sort-cases.sps])
63 AT_DATA([sort-cases.sps], [dnl
64 DATA LIST LIST NOTABLE FILE='data.txt'/x y (F8).
65 SORT CASES BY x[]m4_if([$3], [], [], [/BUFFERS=$3]).
66 PRINT OUTFILE='output.txt'/x y.
69 AT_CHECK([pspp --testing-mode -o pspp.csv sort-cases.sps])
70 AT_CHECK([cat output.txt], [0], [expout])
73 SORT_CASES_TEST(100, 5, 2)
74 SORT_CASES_TEST(100, 5, 3)
75 SORT_CASES_TEST(100, 5, 4)
76 SORT_CASES_TEST(100, 5, 5)
77 SORT_CASES_TEST(100, 5, 10)
78 SORT_CASES_TEST(100, 5, 50)
79 SORT_CASES_TEST(100, 5, 100)
80 SORT_CASES_TEST(100, 5)
82 SORT_CASES_TEST(100, 10, 2)
83 SORT_CASES_TEST(100, 10, 3)
84 SORT_CASES_TEST(100, 10, 5)
85 SORT_CASES_TEST(100, 10)
87 SORT_CASES_TEST(1000, 5, 5, slow)
88 SORT_CASES_TEST(1000, 5, 50, slow)
89 SORT_CASES_TEST(1000, 5, [], slow)
91 SORT_CASES_TEST(100, 100, 3, slow)
92 SORT_CASES_TEST(100, 100, 5, slow)
93 SORT_CASES_TEST(100, 100, [], slow)
95 SORT_CASES_TEST(10000, 5, 500, slow)
97 SORT_CASES_TEST(50000, 1, [], slow)
99 dnl Bug #33089 caused SORT CASES to delete filtered cases permanently.
100 AT_SETUP([SORT CASES preserves filtered cases])
101 AT_DATA([sort-cases.sps], [dnl
106 COMPUTE mod2 = MOD(x, 2).
115 AT_CHECK([pspp -O format=csv sort-cases.sps], [0], [dnl