X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=tests%2Flanguage%2Fstats%2Fsort-cases.at;h=8d839f9dabeacf7dfa87459e629e23d719af37a8;hb=06ac0c2d623e9ae54c3e22a2d6740219ab357b21;hp=4624dbfddef1f233cd2b5204f80f2c118ce8498b;hpb=6c471f2f6675ed32e6d550adfda1106f1baf1421;p=pspp diff --git a/tests/language/stats/sort-cases.at b/tests/language/stats/sort-cases.at index 4624dbfdde..8d839f9dab 100644 --- a/tests/language/stats/sort-cases.at +++ b/tests/language/stats/sort-cases.at @@ -1,16 +1,16 @@ dnl PSPP - a program for statistical analysis. dnl Copyright (C) 2017 Free Software Foundation, Inc. -dnl +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 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 dnl You should have received a copy of the GNU General Public License dnl along with this program. If not, see . dnl @@ -18,42 +18,33 @@ AT_BANNER([SORT CASES]) m4_divert_push([PREPARE_TESTS]) [sort_cases_gen_data () { - cat > gen-data.pl <<'EOF' -use strict; -use warnings; - -# Generate shuffled data. -my (@data); -for my $i (0...$ARGV[0] - 1) { - push (@data, ($i) x $ARGV[1]); -} -fisher_yates_shuffle (\@data); - -# Output shuffled data. -my (@shuffled) = map ([$data[$_], $_], 0...$#data); -open (SHUFFLED, ">data.txt"); -print SHUFFLED "$data[$_] $_\n" foreach 0...$#data; - -# Output sorted data. -my (@sorted) = sort { $a->[0] <=> $b->[0] || $a->[1] <=> $b->[1] } @shuffled; -open (SORTED, ">expout"); -printf SORTED " %8d %8d \n", $_->[0], $_->[1] foreach @sorted; - -# From perlfaq4. -sub fisher_yates_shuffle { - my $deck = shift; # $deck is a reference to an array - my $i = @$deck; - while ($i--) { - my $j = int rand ($i+1); - @$deck[$i,$j] = @$deck[$j,$i]; - } -} + cat > gen-data.py <<'EOF' +#! /usr/bin/python3 + +import random +import sys + +data = [] +for i in range(int(sys.argv[1])): + data += [i] * int(sys.argv[2]) +random.shuffle(data) + +data_txt = open('data.txt', 'w') +for i, item in enumerate(data): + data_txt.write('%s %s\n' % (item, i)) +data_txt.close() + +shuffled = ((item, i) for i, item in enumerate(data)) +expout = open('expout', 'w') +for item, i in sorted(shuffled): + expout.write(' %8d %8d \n' % (item, i)) +expout.close() EOF - $PERL gen-data.pl "$@"] + $PYTHON3 gen-data.py "$@"] } m4_divert_pop([PREPARE_TESTS]) -m4_define([SORT_CASES_TEST], +m4_define([SORT_CASES_TEST], [AT_SETUP([sort m4_eval([$1 * $2]) cases[]m4_if([$2], [1], [], [ ($1 unique)])[]m4_if([$3], [], [], [ with $3 buffers])]) AT_KEYWORDS([SORT CASES $4]) AT_CHECK([sort_cases_gen_data $1 $2 $3])