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
22 # Set limit variables.
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) &&
60 -$max_int100.${max_frac100}1
61 -$max_int100.$max_frac100
62 -$max_int160.${max_frac160}1
63 -$max_int160.$max_frac160
68 $max_int160.$max_frac160
69 $max_int160.${max_frac160}1
71 $max_int100.$max_frac100
72 $max_int100.${max_frac100}1
85 sort -R exp | LC_ALL
=C
sort $opts > out || fail
=1
86 compare exp out || fail
=1