diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/ChangeLog | 4 | ||||
-rw-r--r-- | test/arraysort.awk | 15 | ||||
-rw-r--r-- | test/arraysort.ok | 85 | ||||
-rw-r--r-- | test/sort1.awk | 122 | ||||
-rw-r--r-- | test/sort1.ok | 191 |
5 files changed, 351 insertions, 66 deletions
diff --git a/test/ChangeLog b/test/ChangeLog index 94bf6924..89aa4d11 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,7 @@ +Mon Apr 18 10:22:28 2011 John Haque <j.eh@mchsi.com> + + * arraysort.awk, arraysort.ok, sort1.awk, sort1.ok: Updated. + Fri Apr 15 13:49:36 2011 Arnold D. Robbins <arnold@skeeve.com> * ofmta.awk, ofmta.ok: New files from John Haque. diff --git a/test/arraysort.awk b/test/arraysort.awk index 912d5880..09922044 100644 --- a/test/arraysort.awk +++ b/test/arraysort.awk @@ -66,16 +66,25 @@ BEGIN { n = split(" 4 \n 3\n3D\nD3\n3\n0\n2\n4\n1\n5", a, "\n") for (i = 1; i <= n; i++) b[a[i]] = a[i] + print "--unsorted--" + PROCINFO["sorted_in"] = "unsorted" + for (i in b) + print "|"i"|"b[i]"|" + print "--asc ind str--" PROCINFO["sorted_in"] = "asc ind str" for (i in b) - print "|"i"|"b[i] + print "|"i"|"b[i]"|" + print "--asc val str--" + PROCINFO["sorted_in"] = "asc val str" + for (i in b) + print "|"i"|"b[i]"|" print "--asc ind num--" PROCINFO["sorted_in"] = "asc ind num" for (i in b) - print "|"i"|"b[i] + print "|"i"|"b[i]"|" print "--asc val num--" PROCINFO["sorted_in"] = "asc val num" for (i in b) - print "|"i"|"b[i] + print "|"i"|"b[i]"|" } diff --git a/test/arraysort.ok b/test/arraysort.ok index bf48ecda..23d7c44a 100644 --- a/test/arraysort.ok +++ b/test/arraysort.ok @@ -1,7 +1,7 @@ --- test1 --- - 5 5 10 10 3D 3D + 5 5 --- test2 --- x 1 y 1 @@ -26,37 +26,58 @@ y 1 "3 " "4" --- test7 --- +--unsorted-- +|4|4| +|5|5| +|D3|D3| +|3D|3D| +| 3| 3| +|0|0| +|1|1| +|2|2| +|3|3| +| 4 | 4 | --asc ind str-- -| 3| 3 -| 4 | 4 -|0|0 -|1|1 -|2|2 -|3|3 -|3D|3D -|4|4 -|5|5 -|D3|D3 +| 3| 3| +| 4 | 4 | +|0|0| +|1|1| +|2|2| +|3|3| +|3D|3D| +|4|4| +|5|5| +|D3|D3| +--asc val str-- +| 3| 3| +| 4 | 4 | +|0|0| +|1|1| +|2|2| +|3|3| +|3D|3D| +|4|4| +|5|5| +|D3|D3| --asc ind num-- -|0|0 -|D3|D3 -|1|1 -|2|2 -| 3| 3 -|3|3 -|3D|3D -| 4 | 4 -|4|4 -|5|5 +|0|0| +|D3|D3| +|1|1| +|2|2| +| 3| 3| +|3|3| +|3D|3D| +| 4 | 4 | +|4|4| +|5|5| --asc val num-- -gawk: arraysort.awk:79: warning: `PROCINFO["sorted_in"]': sorting by value can't be forced to use numeric comparison -|4|4 -|5|5 -|D3|D3 -|3D|3D -| 3| 3 -|0|0 -|1|1 -|2|2 -|3|3 -| 4 | 4 +|0|0| +|D3|D3| +|1|1| +|2|2| +| 3| 3| +|3|3| +|3D|3D| +| 4 | 4 | +|4|4| +|5|5| diff --git a/test/sort1.awk b/test/sort1.awk index 3800c40e..44af59ff 100644 --- a/test/sort1.awk +++ b/test/sort1.awk @@ -1,31 +1,113 @@ BEGIN{ - a[1] = "barz"; - a[2] = "blattt"; - a[3] = "Zebra"; - a[4] = 1234; + for (IGNORECASE=0; IGNORECASE <= 1; IGNORECASE++) { + SORT_STR = -1 - testit1(a) + makea(a) + asort1(a, "") + printf("---end asort(a), IGNORECASE = %d---\n", IGNORECASE) - delete a + makea(a) + asort2(a, "") + printf("---end asort(a, b), IGNORECASE = %d---\n", IGNORECASE) - a[1] = "barz"; - a[2] = "blattt"; - a[3] = "Zebra"; - a[4] = 1234; + makea(a) + SORT_STR = "" + asort1(a) + printf("---end asort(a, a), IGNORECASE = %d---\n", IGNORECASE) - n = asort(a, b); + makea(a) + SORT_STR = "num" + asort2(a, "") + printf("---end asort(a, b, \"num\"), IGNORECASE = %d---\n", IGNORECASE) - print "N = ", n; + makea(a) + SORT_STR = "desc str" + asort1(a, "") + printf("---end asort(a, a, \"desc str\"), IGNORECASE = %d---\n", IGNORECASE) - for(i=1; i <= n; i++) - print i, a[i], b[i]; + makea(a) + SORT_STR = "val str" + proc_sort(a, "") + printf("---end PROCINFO[\"sorted_in\"] = \"val str\", IGNORECASE = %d---\n", + IGNORECASE) + + makea(a) + SORT_STR = "val num" + proc_sort(a, "") + printf("---end PROCINFO[\"sorted_in\"] = \"val num\", IGNORECASE = %d---\n", + IGNORECASE) + + makea(a) + SORT_STR = "desc val str" + proc_sort(a, "") + printf("---end PROCINFO[\"sorted_in\"] = \"desc val str\", IGNORECASE = %d---\n", + IGNORECASE) + + makea(a) + SORT_STR = "desc val num" + proc_sort(a, "") + printf("---end PROCINFO[\"sorted_in\"] = \"desc val num\", IGNORECASE = %d---\n", + IGNORECASE) + } +} + +function makea(aa) +{ + delete aa + aa[1] = "barz"; + aa[2] = "blattt"; + aa[3] = "Zebra"; + aa[4] = 1234; + aa[5] = 234; + aa[6][1] = 4321; +# aa[6][2] = 432; + aa[6][3] = "tttalb"; + aa[6][2] = "arbeZ"; + aa[6][4] = "zrab"; } -function testit1(a, count, j) + +# 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]) + } +} + + +function proc_sort(c, s, k) { - print "start testit" - count = asort(a) - for (j = 1; j <= count; j++) - print j, a[j] - print "end testit" + PROCINFO["sorted_in"] = SORT_STR + for(k in c) { + if (isarray(c[k])) + proc_sort(c[k], s"["k"]") + else + printf("%10s:%10s\n", s"["k"]", c[k]) + } } diff --git a/test/sort1.ok b/test/sort1.ok index 4838daba..8ba2bcd2 100644 --- a/test/sort1.ok +++ b/test/sort1.ok @@ -1,11 +1,180 @@ -start testit -1 1234 -2 Zebra -3 barz -4 blattt -end testit -N = 4 -1 barz 1234 -2 blattt Zebra -3 Zebra barz -4 1234 blattt + [1]: 1234 + [2]: 234 + [3]: Zebra + [4]: barz + [5]: blattt + [6][1]: 4321 + [6][2]: arbeZ + [6][3]: tttalb + [6][4]: zrab +---end asort(a), IGNORECASE = 0--- + [1]: barz 1234 + [2]: blattt 234 + [3]: Zebra Zebra + [4]: 1234 barz + [5]: 234 blattt + [6][1]: 4321 4321 + [6][2]: arbeZ arbeZ + [6][3]: tttalb tttalb + [6][4]: zrab zrab +---end asort(a, b), IGNORECASE = 0--- + [1]: 1234 + [2]: 234 + [3]: Zebra + [4]: barz + [5]: blattt + [6][1]: 4321 + [6][2]: arbeZ + [6][3]: tttalb + [6][4]: zrab +---end asort(a, a), IGNORECASE = 0--- + [1]: barz Zebra + [2]: blattt barz + [3]: Zebra blattt + [4]: 1234 234 + [5]: 234 1234 + [6][1]: 4321 arbeZ + [6][2]: arbeZ tttalb + [6][3]: tttalb zrab + [6][4]: zrab 4321 +---end asort(a, b, "num"), IGNORECASE = 0--- + [1][1]: zrab + [1][2]: tttalb + [1][3]: arbeZ + [1][4]: 4321 + [2]: blattt + [3]: barz + [4]: Zebra + [5]: 234 + [6]: 1234 +---end asort(a, a, "desc str"), IGNORECASE = 0--- + [4]: 1234 + [5]: 234 + [3]: Zebra + [1]: barz + [2]: blattt + [6][1]: 4321 + [6][2]: arbeZ + [6][3]: tttalb + [6][4]: zrab +---end PROCINFO["sorted_in"] = "val str", IGNORECASE = 0--- + [3]: Zebra + [1]: barz + [2]: blattt + [5]: 234 + [4]: 1234 + [6][2]: arbeZ + [6][3]: tttalb + [6][4]: zrab + [6][1]: 4321 +---end PROCINFO["sorted_in"] = "val num", IGNORECASE = 0--- + [6][4]: zrab + [6][3]: tttalb + [6][2]: arbeZ + [6][1]: 4321 + [2]: blattt + [1]: barz + [3]: Zebra + [5]: 234 + [4]: 1234 +---end PROCINFO["sorted_in"] = "desc val str", IGNORECASE = 0--- + [6][1]: 4321 + [6][4]: zrab + [6][3]: tttalb + [6][2]: arbeZ + [4]: 1234 + [5]: 234 + [2]: blattt + [1]: barz + [3]: Zebra +---end PROCINFO["sorted_in"] = "desc val num", IGNORECASE = 0--- + [1]: 1234 + [2]: 234 + [3]: barz + [4]: blattt + [5]: Zebra + [6][1]: 4321 + [6][2]: arbeZ + [6][3]: tttalb + [6][4]: zrab +---end asort(a), IGNORECASE = 1--- + [1]: barz 1234 + [2]: blattt 234 + [3]: Zebra barz + [4]: 1234 blattt + [5]: 234 Zebra + [6][1]: 4321 4321 + [6][2]: arbeZ arbeZ + [6][3]: tttalb tttalb + [6][4]: zrab zrab +---end asort(a, b), IGNORECASE = 1--- + [1]: 1234 + [2]: 234 + [3]: barz + [4]: blattt + [5]: Zebra + [6][1]: 4321 + [6][2]: arbeZ + [6][3]: tttalb + [6][4]: zrab +---end asort(a, a), IGNORECASE = 1--- + [1]: barz barz + [2]: blattt blattt + [3]: Zebra Zebra + [4]: 1234 234 + [5]: 234 1234 + [6][1]: 4321 arbeZ + [6][2]: arbeZ tttalb + [6][3]: tttalb zrab + [6][4]: zrab 4321 +---end asort(a, b, "num"), IGNORECASE = 1--- + [1][1]: zrab + [1][2]: tttalb + [1][3]: arbeZ + [1][4]: 4321 + [2]: Zebra + [3]: blattt + [4]: barz + [5]: 234 + [6]: 1234 +---end asort(a, a, "desc str"), IGNORECASE = 1--- + [4]: 1234 + [5]: 234 + [1]: barz + [2]: blattt + [3]: Zebra + [6][1]: 4321 + [6][2]: arbeZ + [6][3]: tttalb + [6][4]: zrab +---end PROCINFO["sorted_in"] = "val str", IGNORECASE = 1--- + [1]: barz + [2]: blattt + [3]: Zebra + [5]: 234 + [4]: 1234 + [6][2]: arbeZ + [6][3]: tttalb + [6][4]: zrab + [6][1]: 4321 +---end PROCINFO["sorted_in"] = "val num", IGNORECASE = 1--- + [6][4]: zrab + [6][3]: tttalb + [6][2]: arbeZ + [6][1]: 4321 + [3]: Zebra + [2]: blattt + [1]: barz + [5]: 234 + [4]: 1234 +---end PROCINFO["sorted_in"] = "desc val str", IGNORECASE = 1--- + [6][1]: 4321 + [6][4]: zrab + [6][3]: tttalb + [6][2]: arbeZ + [4]: 1234 + [5]: 234 + [3]: Zebra + [2]: blattt + [1]: barz +---end PROCINFO["sorted_in"] = "desc val num", IGNORECASE = 1--- |