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/>.
16 dnl AT_BANNER([SORT CASES])
18 m4_divert_push([PREPARE_TESTS])
19 [sort_cases_gen_data () {
20 cat > gen-data.pl <<'EOF'
24 # Generate shuffled data.
26 for my $i (0...$ARGV[0] - 1) {
27 push (@data, ($i) x $ARGV[1]);
29 fisher_yates_shuffle (\@data);
31 # Output shuffled data.
32 my (@shuffled) = map ([$data[$_], $_], 0...$#data);
33 open (SHUFFLED, ">data.txt");
34 print SHUFFLED "$data[$_] $_\n" foreach 0...$#data;
37 my (@sorted) = sort { $a->[0] <=> $b->[0] || $a->[1] <=> $b->[1] } @shuffled;
38 open (SORTED, ">expout");
39 printf SORTED " %8d %8d \n", $_->[0], $_->[1] foreach @sorted;
42 sub fisher_yates_shuffle {
43 my $deck = shift; # $deck is a reference to an array
46 my $j = int rand ($i+1);
47 @$deck[$i,$j] = @$deck[$j,$i];
51 $PERL gen-data.pl "$@"]
53 m4_divert_pop([PREPARE_TESTS])
55 m4_define([SORT_CASES_TEST],
56 [AT_SETUP([sort m4_eval([$1 * $2]) cases[]m4_if([$2], [1], [], [ ($1 unique)])[]m4_if([$3], [], [], [ with $3 buffers])])
57 AT_KEYWORDS([SORT CASES])
58 AT_CHECK([sort_cases_gen_data $1 $2 $3])
59 AT_CAPTURE_FILE([data.txt])
60 AT_CAPTURE_FILE([output.txt])
61 AT_CAPTURE_FILE([sort-cases.sps])
62 AT_DATA([sort-cases.sps], [dnl
63 DATA LIST LIST NOTABLE FILE='data.txt'/x y (F8).
64 SORT CASES BY x[]m4_if([$3], [], [], [/BUFFERS=$3]).
65 PRINT OUTFILE='output.txt'/x y.
68 AT_CHECK([pspp --testing-mode -o pspp.csv sort-cases.sps])
69 AT_CHECK([cat output.txt], [0], [expout])
72 SORT_CASES_TEST(100, 5, 2)
73 SORT_CASES_TEST(100, 5, 3)
74 SORT_CASES_TEST(100, 5, 4)
75 SORT_CASES_TEST(100, 5, 5)
76 SORT_CASES_TEST(100, 5, 10)
77 SORT_CASES_TEST(100, 5, 50)
78 SORT_CASES_TEST(100, 5, 100)
79 SORT_CASES_TEST(100, 5)
81 SORT_CASES_TEST(100, 10, 2)
82 SORT_CASES_TEST(100, 10, 3)
83 SORT_CASES_TEST(100, 10, 5)
84 SORT_CASES_TEST(100, 10)
86 SORT_CASES_TEST(1000, 5, 5)
87 SORT_CASES_TEST(1000, 5, 50)
88 SORT_CASES_TEST(1000, 5)
90 SORT_CASES_TEST(100, 100, 3)
91 SORT_CASES_TEST(100, 100, 5)
92 SORT_CASES_TEST(100, 100)
94 SORT_CASES_TEST(10000, 5, 500)
96 SORT_CASES_TEST(50000, 1)
98 dnl Bug #33089 caused SORT CASES to delete filtered cases permanently.
99 AT_SETUP([SORT CASES preserves filtered cases])
100 AT_DATA([sort-cases.sps], [dnl
105 COMPUTE mod2 = MOD(x, 2).
114 AT_CHECK([pspp -O format=csv sort-cases.sps], [0], [dnl