Carp/test/sort.carp

122 lines
3.7 KiB
Plaintext
Raw Normal View History

2018-06-26 11:03:34 +03:00
(use Array)
(load "Test.carp")
(use Test)
2018-11-07 18:11:38 +03:00
(deftest test
(let-do [arr [1 3 4 2 6 1]
exp [1 1 2 3 4 6]]
(Array.sort! &arr)
(assert-equal test
&exp
&arr
"Array.sort! works with integers"))
2018-11-07 18:11:38 +03:00
(let-do [arr [1 3 4 2 6 1]
exp [1 1 2 3 4 6]
res (Array.sorted &arr)]
(assert-equal test
&exp
&res
"Array.sorted works with integers"))
2018-11-07 18:11:38 +03:00
(let-do [res (Array.sort [1 3 4 2 6 1])
exp [1 1 2 3 4 6]]
(assert-equal test
&exp
&res
"Array.sort works with integers"))
2018-11-07 18:11:38 +03:00
(let-do [arr [1.0 0.8 12.4 3.2]
exp [0.8 1.0 3.2 12.4]]
(Array.sort! &arr)
(assert-equal test
&exp
&arr
"Array.sort! works with floats"))
2018-11-07 18:11:38 +03:00
(let-do [arr [1.0 0.8 12.4 3.2]
exp [0.8 1.0 3.2 12.4]
res (Array.sorted &arr)]
(assert-equal test
&exp
&res
"Array.sorted works with floats"))
2018-11-07 18:11:38 +03:00
(let-do [res (Array.sort [1.0 0.8 12.4 3.2])
exp [0.8 1.0 3.2 12.4]]
(assert-equal test
&exp
&res
"Array.sort works with floats"))
2018-11-07 18:11:38 +03:00
(let-do [arr [@"aaac" @"aaaa" @"aaab" @"aaad"]
exp [@"aaaa" @"aaab" @"aaac" @"aaad"]]
(Array.sort! &arr)
(assert-equal test
&exp
&arr
"Array.sort! works with strings"))
2018-11-07 18:11:38 +03:00
(let-do [arr [@"aaac" @"aaaa" @"aaab" @"aaad"]
exp [@"aaaa" @"aaab" @"aaac" @"aaad"]
res (Array.sorted &arr)]
(assert-equal test
&exp
&res
"Array.sorted works with strings"))
2018-11-07 18:11:38 +03:00
(let-do [res (Array.sort [@"aaac" @"aaaa" @"aaab" @"aaad"])
exp [@"aaaa" @"aaab" @"aaac" @"aaad"]]
(assert-equal test
&exp
&res
"Array.sort works with strings"))
2018-11-07 18:11:38 +03:00
(let-do [arr [\d \a \c \b]
exp [\a \b \c \d]]
(Array.sort! &arr)
(assert-equal test
&exp
&arr
"Array.sort! works with chars"))
2018-11-07 18:11:38 +03:00
(let-do [arr [\d \a \c \b]
exp [\a \b \c \d]
res (Array.sorted &arr)]
(assert-equal test
&exp
&res
"Array.sorted works with chars"))
2018-11-07 18:11:38 +03:00
(let-do [res (Array.sort [\d \a \c \b])
exp [\a \b \c \d]]
(assert-equal test
&exp
&res
"Array.sort works with chars"))
(let-do [arr [1 3 4 2 6 1]
exp [6 4 3 2 1 1]]
(Array.sort-by! &arr &(fn [a b] (< a b)))
(assert-equal test
&exp
&arr
"Array.sort-by! works with custom functions"))
(let-do [arr [1 3 4 2 6 1]
exp [6 4 3 2 1 1]
res (Array.sorted-by &arr &(fn [a b] (< a b)))]
(assert-equal test
&exp
&res
"Array.sorted-by works with custom functions"))
(let-do [res (Array.sort-by [1 3 4 2 6 1] &(fn [a b] (< a b)))
exp [6 4 3 2 1 1]]
(assert-equal test
&exp
&res
"Array.sort-by works with custom functions"))
2018-11-07 18:11:38 +03:00
)