ls: tune is_colored
[coreutils.git] / tests / sort / sort-discrim.sh
blobaf2817826edcede801bd0d73bc7f23fae1abf4e3
1 #!/bin/sh
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
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 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) &&
49 { printf -- "\
50 -$UINTMAX_OFLOW
51 -$UINTMAX_MAX
52 -${max_int200}0.1
53 -${max_int200}0
54 -${max_int200}0.0
55 -${max_int320}0.1
56 -${max_int320}0
57 -${max_int320}0.0
58 -$max_int200.${max_frac200}1
59 -$max_int200.$max_frac200
60 -$max_int320.${max_frac320}1
61 -$max_int320.$max_frac320
62 " &&
63 seq -- -10 .001 10 &&
64 printf "\
65 $max_int320
66 $max_int320.$max_frac320
67 $max_int320.${max_frac320}1
68 $max_int200
69 $max_int200.$max_frac200
70 $max_int200.${max_frac200}1
71 ${max_int320}0
72 ${max_int320}0.0
73 ${max_int320}0.1
74 ${max_int200}0
75 ${max_int200}0.0
76 ${max_int200}0.1
77 $UINTMAX_MAX
78 $UINTMAX_OFLOW
80 } > exp || fail=1
82 for opts in -n -h; do
83 sort -R exp | LC_ALL=C sort $opts > out || fail=1
84 compare exp out || fail=1
85 done
87 Exit $fail