1- (import tests-tools)
2-
31(import std.List)
42(import std.Math :even)
3+ (import std.Testing)
54
6- (let list-tests (fun () {
7- (mut tests 0)
8- (let start-time (time))
9-
10- (let a [1 2 3])
11- (let b [4 5 6])
12- (let zipped [[1 5] [2 6] [3 7] [4 8]])
5+ (let a [1 2 3])
6+ (let b [4 5 6])
7+ (let zipped [[1 5] [2 6] [3 7] [4 8]])
138
9+ (test:suite list {
1410 (list:forEach a (fun (e) {
1511 # just assert we have something, basically it's just a while + @
16- (set tests (assert-neq e nil "forEach" tests))}))
17-
18- (set tests (assert-eq (list:product b) (* 4 5 6) "product" tests))
19- (set tests (assert-eq (list:product []) 1 "product" tests))
20-
21- (set tests (assert-eq (list:sum b) (+ 4 5 6) "sum" tests))
22- (set tests (assert-eq (list:sum []) 0 "sum" tests))
23-
24- (set tests (assert-eq (list:drop a 0) [1 2 3] "drop" tests))
25- (set tests (assert-eq (list:drop a 1) [2 3] "drop" tests))
26- (set tests (assert-eq (list:drop a 2) [3] "drop" tests))
12+ (test:neq e nil)}))
2713
28- (set tests (assert-eq (list:dropWhile a (fun (c) (< c 0))) [1 2 3] "dropWhile" tests))
29- (set tests (assert-eq (list:dropWhile a (fun (c) (< c 2))) [2 3] "dropWhile" tests))
30- (set tests (assert-eq (list:dropWhile a (fun (c) (< c 5))) [] "dropWhile" tests))
14+ (test:eq (list:product b) (* 4 5 6))
15+ (test:eq (list:product []) 1)
3116
32- (set tests (assert-eq (list:filter a math:even) [2] "filter" tests))
33- (set tests (assert-eq (list:filter a (fun (e) (> e 100))) [] "filter" tests))
34- (set tests (assert-eq (list:filter [] (fun (e) (> e 100))) [] "filter" tests))
17+ (test:eq (list:sum b) (+ 4 5 6))
18+ (test:eq (list:sum []) 0)
3519
36- (set tests (assert-eq (list:map b (fun (e) (* e e))) [16 25 36] "map" tests))
37- (set tests (assert-eq (list:map [] (fun (e) (* e e))) [] "map" tests))
20+ (test:eq (list:drop a 0) [1 2 3])
21+ (test:eq (list:drop a 1) [2 3])
22+ (test:eq (list:drop a 2) [3])
3823
39- (set tests (assert-eq (list:reduce a (fun (x y) (- x y))) -4 "reduce" tests))
24+ (test:eq (list:dropWhile a (fun (c) (< c 0))) [1 2 3])
25+ (test:eq (list:dropWhile a (fun (c) (< c 2))) [2 3])
26+ (test:eq (list:dropWhile a (fun (c) (< c 5))) [])
4027
41- (set tests (assert-eq (list:flatten []) [] "flatten" tests))
42- (set tests (assert-eq (list:flatten [[]]) [] "flatten" tests))
43- (set tests (assert-eq (list:flatten [[1]]) [1] "flatten" tests))
44- (set tests (assert-eq (list:flatten zipped) [1 5 2 6 3 7 4 8] "flatten" tests))
28+ (test:eq (list:filter a math:even) [2])
29+ (test:eq (list:filter a (fun (e) (> e 100))) [])
30+ (test:eq (list:filter [] (fun (e) (> e 100))) [])
4531
46- (set tests (assert-eq (list:flatMap [] (fun (a) [a a])) [] "flatMap" tests))
47- (set tests (assert-eq (list:flatMap a (fun (a) (* 2 a))) [2 4 6] "flatMap" tests))
48- (set tests (assert-eq (list:flatMap a (fun (a) [a a])) [1 1 2 2 3 3] "flatMap" tests))
32+ (test:eq (list:map b (fun (e) (* e e))) [16 25 36])
33+ (test:eq (list:map [] (fun (e) (* e e))) [])
4934
50- (set tests (assert-eq (list:take a 1) [1] "take" tests))
51- (set tests (assert-eq (list:take a 100) a "take" tests))
35+ (test:eq (list:reduce a (fun (x y) (- x y))) -4)
5236
53- (set tests (assert- eq (list:takeWhile a (fun (c) (< c 0))) [] "takeWhile" tests) )
54- (set tests (assert- eq (list:takeWhile a (fun (c) (< c 2))) [1] "takeWhile" tests) )
55- (set tests (assert- eq (list:takeWhile a (fun (c) (< c 3))) [1 2] "takeWhile" tests) )
56- (set tests (assert- eq (list:takeWhile a (fun (c) (< c 5))) [1 2 3] "takeWhile" tests) )
37+ (test: eq (list:flatten []) [] )
38+ (test: eq (list:flatten [[]]) [] )
39+ (test: eq (list:flatten [[1]]) [1] )
40+ (test: eq (list:flatten zipped) [1 5 2 6 3 7 4 8] )
5741
58- (set tests (assert-eq (list:unzip zipped) [[1 2 3 4] [5 6 7 8]] "unzip" tests))
59- (set tests (assert-eq (list:unzip []) [[] []] "unzip" tests))
42+ (test:eq (list:flatMap [] (fun (a) [a a])) [])
43+ (test:eq (list:flatMap a (fun (a) (* 2 a))) [2 4 6])
44+ (test:eq (list:flatMap a (fun (a) [a a])) [1 1 2 2 3 3])
6045
61- (set tests (assert- eq (list:zip a b ) [[1 4] [2 5] [3 6]] "zip" tests) )
62- (set tests (assert- eq (list:zip [] []) [] "zip" tests) )
46+ (test: eq (list:take a 1 ) [1] )
47+ (test: eq (list:take a 100) a )
6348
64- (set tests (assert-eq (list:foldLeft [] 0 (fun (x y) (+ x y))) 0 "foldLeft" tests))
65- (set tests (assert-eq (list:foldLeft ["1" "2" "3"] "" (fun (x y) (+ x y))) "123" "foldLeft" tests))
66- (set tests (assert-eq (list:foldLeft a 0 (fun (x y) (+ x y))) 6 "foldLeft" tests))
49+ (test:eq (list:takeWhile a (fun (c) (< c 0))) [])
50+ (test:eq (list:takeWhile a (fun (c) (< c 2))) [1])
51+ (test:eq (list:takeWhile a (fun (c) (< c 3))) [1 2])
52+ (test:eq (list:takeWhile a (fun (c) (< c 5))) [1 2 3])
6753
68- (set tests (assert-eq a [ 1 2 3] "unmodified list" tests) )
69- (set tests (assert-eq b [4 5 6] "unmodified list" tests) )
54+ (test:eq (list:unzip zipped) [[ 1 2 3 4] [5 6 7 8]] )
55+ (test:eq (list:unzip []) [[] []] )
7056
71- (set tests (assert-eq (list:forAll a (fun (e) (< e 4))) true "list:forAll" tests))
72- (set tests (assert-eq (list:forAll a (fun (e) (< e 2))) false "list:forAll" tests))
73- (set tests (assert-eq (list:forAll [] (fun (e) (= e 2))) true "list:forAll" tests))
74- (set tests (assert-eq (list:any a (fun (e) (< e 2))) true "list:any" tests))
75- (set tests (assert-eq (list:any a (fun (e) (> e 8))) false "list:any" tests))
76- (set tests (assert-eq (list:any [] (fun (e) (= e 8))) false "list:any" tests))
57+ (test:eq (list:zip a b) [[1 4] [2 5] [3 6]])
58+ (test:eq (list:zip [] []) [])
7759
78- (recap "List tests passed" tests (- (time) start-time))
60+ (test:eq (list:foldLeft [] 0 (fun (x y) (+ x y))) 0)
61+ (test:eq (list:foldLeft ["1" "2" "3"] "" (fun (x y) (+ x y))) "123")
62+ (test:eq (list:foldLeft a 0 (fun (x y) (+ x y))) 6)
7963
80- tests }))
64+ (test:eq a [1 2 3])
65+ (test:eq b [4 5 6])
8166
82- (let passed-list (list-tests))
67+ (test:expect (list:forAll a (fun (e) (< e 4))))
68+ (test:expect (not (list:forAll a (fun (e) (< e 2)))))
69+ (test:expect (list:forAll [] (fun (e) (= e 2))))
70+ (test:expect (list:any a (fun (e) (< e 2))))
71+ (test:expect (not (list:any a (fun (e) (> e 8)))))
72+ (test:expect (not (list:any [] (fun (e) (= e 8)))))})
0 commit comments