|
1 | | -export min, max, min_by, max_by, asc, desc |
| 1 | +export min, max, min_by, max_by, asc, nonasc, desc, nondesc |
2 | 2 |
|
3 | 3 | func max a b = if a > b then a else b |
4 | 4 |
|
@@ -39,15 +39,45 @@ func asc key a b = key a < key b |
39 | 39 | test "compare asc" { |
40 | 40 | let asc_first = asc (fn t.t.'left) |
41 | 41 | assert asc_first (1:2) (2:1) |
| 42 | + assert !(asc_first (2:2) (2:1)) |
| 43 | + assert !(asc_first (2:2) (1:1)) |
42 | 44 | assert asc_first ('a':true) ('b':1) |
| 45 | + assert !(asc_first ('b':true) ('b':1)) |
43 | 46 | assert !(asc_first ('b':true) ('a':1)) |
44 | 47 | } |
45 | 48 |
|
| 49 | +func nonasc key a b = key a >= key b |
| 50 | + |
| 51 | +test "compare nonasc" { |
| 52 | + let nonasc_first = nonasc (fn t.t.'left) |
| 53 | + assert !(nonasc_first (1:2) (2:1)) |
| 54 | + assert nonasc_first (2:2) (2:1) |
| 55 | + assert nonasc_first (2:2) (1:1) |
| 56 | + assert !(nonasc_first ('a':true) ('b':1)) |
| 57 | + assert nonasc_first ('b':true) ('b':1) |
| 58 | + assert nonasc_first ('b':true) ('a':1) |
| 59 | +} |
| 60 | + |
46 | 61 | func desc key a b = key a > key b |
47 | 62 |
|
48 | 63 | test "compare desc" { |
49 | 64 | let desc_first = desc (fn t.t.'left) |
50 | 65 | assert desc_first (2:1) (1:2) |
51 | | - assert !(desc_first ('a':true) ('b':1)) |
| 66 | + assert !(desc_first (2:1) (2:2)) |
| 67 | + assert !(desc_first (2:true) (2:1)) |
52 | 68 | assert desc_first ('b':true) ('a':1) |
| 69 | + assert !(desc_first ('b':true) ('b':1)) |
| 70 | + assert !(desc_first ('a':true) ('b':1)) |
| 71 | +} |
| 72 | + |
| 73 | +func nondesc key a b = key a <= key b |
| 74 | + |
| 75 | +test "compare nondesc" { |
| 76 | + let nondesc_first = nondesc (fn t.t.'left) |
| 77 | + assert !(nondesc_first (2:1) (1:2)) |
| 78 | + assert nondesc_first (2:1) (2:2) |
| 79 | + assert nondesc_first (2:true) (2:1) |
| 80 | + assert !(nondesc_first ('b':true) ('a':1)) |
| 81 | + assert nondesc_first ('b':true) ('b':1) |
| 82 | + assert nondesc_first ('a':true) ('b':1) |
53 | 83 | } |
0 commit comments