ptx: fix an invalid heap reference with short --width
[coreutils.git] / tests / misc / sort-discrim.sh
blobeb682d741558db94a6afcca4a0954f9efb850d59
1 #!/bin/sh
2 # Test discriminator-based sorting.
4 # Copyright (C) 2012-2016 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20 print_ver_ sort
22 # Set limit variables.
23 getlimits_
25 # These tests are designed for a 'sort' implementation that uses a
26 # discriminator, i.e., a brief summary of a key that may have lost info,
27 # but whose ordering is consistent with that of the original key.
28 # The tests are useful even if 'sort' does not use this representation.
30 # Test lexicographic sorting.
32 # A long-enough string so that it overruns a small discriminator buffer size.
33 long_prefix='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
34 seq -f "$long_prefix%5.0f" 10000 > exp || fail=1
35 sort -R exp | LC_ALL=C sort > out || fail=1
36 compare exp out || fail=1
39 # Test numeric sorting.
41 # These tests are designed for an internal representation that ordinarily
42 # looks at the number plus two decimal digits, but if -h is
43 # used it looks at one decimal place plus a 4-bit SI prefix value.
44 # In both cases, there's an extra factor of 2 for the sign.
45 # Note INTMAX_MAX is used below as that's that largest number
46 # expr can handle on all systems (without GMP).
47 max_int100=$(expr $INTMAX_MAX / 100) &&
48 max_frac100=$(printf '%.2d' $(expr $INTMAX_MAX % 100)) &&
49 max_int160=$(expr $INTMAX_MAX / 160) &&
50 max_frac160=$(expr $INTMAX_MAX / 16 % 10) &&
51 { printf -- "\
52 -$UINTMAX_OFLOW
53 -$UINTMAX_MAX
54 -${max_int100}0.1
55 -${max_int100}0
56 -${max_int100}0.0
57 -${max_int160}0.1
58 -${max_int160}0
59 -${max_int160}0.0
60 -$max_int100.${max_frac100}1
61 -$max_int100.$max_frac100
62 -$max_int160.${max_frac160}1
63 -$max_int160.$max_frac160
64 " &&
65 seq -- -10 .001 10 &&
66 printf "\
67 $max_int160
68 $max_int160.$max_frac160
69 $max_int160.${max_frac160}1
70 $max_int100
71 $max_int100.$max_frac100
72 $max_int100.${max_frac100}1
73 ${max_int160}0
74 ${max_int160}0.0
75 ${max_int160}0.1
76 ${max_int100}0
77 ${max_int100}0.0
78 ${max_int100}0.1
79 $UINTMAX_MAX
80 $UINTMAX_OFLOW
82 } > exp || fail=1
84 for opts in -n -h; do
85 sort -R exp | LC_ALL=C sort $opts > out || fail=1
86 compare exp out || fail=1
87 done
89 Exit $fail