2 # Test discriminator-based sorting.
4 # Copyright (C) 2012-2024 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 <https://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 max_int200
=$
(expr $UINTMAX_MAX / 200) &&
46 max_frac200
=$
(printf '%.2d' $
(expr $UINTMAX_MAX / 2 % 100)) &&
47 max_int320
=$
(expr $UINTMAX_MAX / 320) &&
48 max_frac320
=$
(expr $UINTMAX_MAX / 32 % 10) &&
58 -$max_int200.${max_frac200}1
59 -$max_int200.$max_frac200
60 -$max_int320.${max_frac320}1
61 -$max_int320.$max_frac320
66 $max_int320.$max_frac320
67 $max_int320.${max_frac320}1
69 $max_int200.$max_frac200
70 $max_int200.${max_frac200}1
83 sort -R exp | LC_ALL
=C
sort $opts > out || fail
=1
84 compare exp out || fail
=1