Skip to content

Commit 999cf0e

Browse files
committed
additional stdlib
1 parent dbacd8d commit 999cf0e

1 file changed

Lines changed: 32 additions & 2 deletions

File tree

trilogy/src/stdlib/compare.tri

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export min, max, min_by, max_by, asc, desc
1+
export min, max, min_by, max_by, asc, nonasc, desc, nondesc
22

33
func max a b = if a > b then a else b
44

@@ -39,15 +39,45 @@ func asc key a b = key a < key b
3939
test "compare asc" {
4040
let asc_first = asc (fn t.t.'left)
4141
assert asc_first (1:2) (2:1)
42+
assert !(asc_first (2:2) (2:1))
43+
assert !(asc_first (2:2) (1:1))
4244
assert asc_first ('a':true) ('b':1)
45+
assert !(asc_first ('b':true) ('b':1))
4346
assert !(asc_first ('b':true) ('a':1))
4447
}
4548

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+
4661
func desc key a b = key a > key b
4762

4863
test "compare desc" {
4964
let desc_first = desc (fn t.t.'left)
5065
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))
5268
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)
5383
}

0 commit comments

Comments
 (0)