diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/ChangeLog | 4 | ||||
-rw-r--r-- | test/Makefile.am | 4 | ||||
-rw-r--r-- | test/Makefile.in | 9 | ||||
-rw-r--r-- | test/Maketests | 5 | ||||
-rw-r--r-- | test/sortu.awk | 114 | ||||
-rw-r--r-- | test/sortu.ok | 50 |
6 files changed, 184 insertions, 2 deletions
diff --git a/test/ChangeLog b/test/ChangeLog index 3081a53c..3754c554 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,7 @@ +Fri Apr 22 16:07:01 2011 John Haque <j.eh@mchsi.com> + + * sortu.awk, sortu.ok: New files. + Fri Apr 22 09:19:06 2011 Arnold D. Robbins <arnold@skeeve.com> * arraysort.ok: Updated. diff --git a/test/Makefile.am b/test/Makefile.am index 321cbde3..8eeb80da 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -634,6 +634,8 @@ EXTRA_DIST = \ sortfor.awk \ sortfor.in \ sortfor.ok \ + sortu.awk \ + sortu.ok \ space.ok \ splitarg4.awk \ splitarg4.in \ @@ -781,7 +783,7 @@ GAWK_EXT_TESTS = \ lintold manyfiles match1 match2 match3 mbstr1 nondec nondec2 patsplit \ posix profile1 profile2 profile3 printfbad1 printfbad2 \ procinfs rebuf regx8bit reint reint2 rsstart1 rsstart2 rsstart3 \ - rstest6 shadow sortfor splitarg4 strftime strtonum switch2 + rstest6 shadow sortfor sortu splitarg4 strftime strtonum switch2 EXTRA_TESTS = regtest inftest diff --git a/test/Makefile.in b/test/Makefile.in index 8319041c..85b7e80e 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -819,6 +819,8 @@ EXTRA_DIST = \ sortfor.awk \ sortfor.in \ sortfor.ok \ + sortu.awk \ + sortu.ok \ space.ok \ splitarg4.awk \ splitarg4.in \ @@ -965,7 +967,7 @@ GAWK_EXT_TESTS = \ lintold manyfiles match1 match2 match3 mbstr1 nondec nondec2 patsplit \ posix profile1 profile2 profile3 printfbad1 printfbad2 \ procinfs rebuf regx8bit reint reint2 rsstart1 rsstart2 rsstart3 \ - rstest6 shadow sortfor splitarg4 strftime strtonum switch2 + rstest6 shadow sortfor sortu splitarg4 strftime strtonum switch2 EXTRA_TESTS = regtest inftest INET_TESTS = inetechu inetecht inetdayu inetdayt @@ -2760,6 +2762,11 @@ sortfor: @AWKPATH=$(srcdir) $(AWK) -f $@.awk < $(srcdir)/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@ +sortu: + @echo sortu + @AWKPATH=$(srcdir) $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@ + splitarg4: @echo splitarg4 @AWKPATH=$(srcdir) $(AWK) -f $@.awk < $(srcdir)/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ diff --git a/test/Maketests b/test/Maketests index 2f2ff93a..772ee657 100644 --- a/test/Maketests +++ b/test/Maketests @@ -1055,6 +1055,11 @@ sortfor: @AWKPATH=$(srcdir) $(AWK) -f $@.awk < $(srcdir)/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@ +sortu: + @echo sortu + @AWKPATH=$(srcdir) $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@ + splitarg4: @echo splitarg4 @AWKPATH=$(srcdir) $(AWK) -f $@.awk < $(srcdir)/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ diff --git a/test/sortu.awk b/test/sortu.awk new file mode 100644 index 00000000..b4d30138 --- /dev/null +++ b/test/sortu.awk @@ -0,0 +1,114 @@ +# numeric before string, ascending by index +function comp_num_str(s1, v1, s2, v2, n1, n2) { + n1 = s1 + 0 + n2 = s2 + 0 + if (n1 == s1) + return (n2 == s2) ? (n1 - n2) : -1 + else if (n2 == s2) + return 1 + return (s1 < s2) ? -1 : (s1 != s2) +} + +# ascending index number +function comp_idx_num(s1, v1, s2, v2) +{ + return (s1 - s2) +} + +# ascending value number +function comp_val_num(s1, v1, s2, v2) +{ + return (v1 - v2) +} + +# ascending value string +function comp_val_str(s1, v1, s2, v2) +{ + v1 = v1 "" + v2 = v2 "" + return (v1 < v2) ? -1 : (v1 != v2) +} + +# deterministic, by value (and index), descending numeric +function comp_val_idx(s1, v1, s2, v2) +{ + return (v1 != v2) ? (v2 - v1) : (s2 - s1) +} + +BEGIN { + a[1] = 10; a[100] = 1; a[2] = 200 + a["cat"] = "tac"; a["rat"] = "tar";a["bat"] = "tab" + + print "--- number before string, ascending by index ---" + PROCINFO["sorted_in"] = "comp_num_str" + for (i in a) + printf("%-10s%-s\n", i, a[i]) + + delete a + a[11] = 10; a[100] = 5; a[2] = 200 + a[4] = 1; a[20] = 10; a[14] = 10 + print "--- deterministic, by value (index), descending numeric ---" + PROCINFO["sorted_in"] = "comp_val_idx" + for (i in a) + printf("%-10s%-s\n", i, a[i]) + + for (IGNORECASE=0; IGNORECASE <= 1; IGNORECASE++) { + makea(a) + SORT_STR = "comp_val_num" + printf("--- asort(a, b, \"%s\"), IGNORECASE = %d---\n", SORT_STR, IGNORECASE) + asort2(a, "") + + makea(a) + SORT_STR = "comp_val_str" + printf("--- asort(a, b, \"%s\"), IGNORECASE = %d---\n", SORT_STR, IGNORECASE) + asort2(a, "") + + makea(a) + SORT_STR = "comp_val_str" + printf("--- asort(a, a, \"%s\"), IGNORECASE = %d---\n", SORT_STR, IGNORECASE) + asort1(a, "") + } +} + +function makea(aa) +{ + delete aa + aa[1] = "barz"; + aa[2] = "blattt"; + aa[3] = "Zebra"; + aa[4] = 1234; + aa[5] = 234; +} + +# source array != destination array +function asort2(c, s, d, k, m) +{ + if (SORT_STR < 0) + m = asort(c, d); + else + m = asort(c, d, SORT_STR); + for (k=1; k <= m; k++) { + if (isarray(d[k])) + asort2(d[k], s"["k"]") + else + printf("%-10s:%-10s%-10s\n", s"["k"]", c[k], d[k]) + } +} + +# source array == destination array +function asort1(c, s, k, m) +{ + if (SORT_STR < 0) + m = asort(c) + else if (SORT_STR != "") + m = asort(c, c, SORT_STR) + else + m = asort(c, c); + + for (k=1; k <= m; k++) { + if (isarray(c[k])) + asort1(c[k], s"["k"]") + else + printf("%-10s:%-10s\n", s"["k"]", c[k]) + } +} diff --git a/test/sortu.ok b/test/sortu.ok new file mode 100644 index 00000000..ba9ac997 --- /dev/null +++ b/test/sortu.ok @@ -0,0 +1,50 @@ +--- number before string, ascending by index --- +1 10 +2 200 +100 1 +bat tab +cat tac +rat tar +--- deterministic, by value (index), descending numeric --- +2 200 +20 10 +14 10 +11 10 +100 5 +4 1 +--- asort(a, b, "comp_val_num"), IGNORECASE = 0--- +[1] :barz barz +[2] :blattt blattt +[3] :Zebra Zebra +[4] :1234 234 +[5] :234 1234 +--- asort(a, b, "comp_val_str"), IGNORECASE = 0--- +[1] :barz 1234 +[2] :blattt 234 +[3] :Zebra Zebra +[4] :1234 barz +[5] :234 blattt +--- asort(a, a, "comp_val_str"), IGNORECASE = 0--- +[1] :1234 +[2] :234 +[3] :Zebra +[4] :barz +[5] :blattt +--- asort(a, b, "comp_val_num"), IGNORECASE = 1--- +[1] :barz barz +[2] :blattt blattt +[3] :Zebra Zebra +[4] :1234 234 +[5] :234 1234 +--- asort(a, b, "comp_val_str"), IGNORECASE = 1--- +[1] :barz 1234 +[2] :blattt 234 +[3] :Zebra barz +[4] :1234 blattt +[5] :234 Zebra +--- asort(a, a, "comp_val_str"), IGNORECASE = 1--- +[1] :1234 +[2] :234 +[3] :barz +[4] :blattt +[5] :Zebra |