-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.zp
85 lines (73 loc) · 2.59 KB
/
test.zp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
(load "transducers")
(load "minitest/minitest")
(define transducers:transduce (import "transducers:transduce"))
(define transducers:map (import "transducers:map"))
(define transducers:take (import "transducers:take"))
(define transducers:filter (import "transducers:filter"))
(define transducers:partition-by (import "transducers:partition-by"))
(define transducers:compose (import "transducers:compose"))
(define transducers:into (import "transducers:into"))
(define transducers:cat (import "transducers:cat"))
(define transducers:mapcat (import "transducers:mapcat"))
(define minitest:assert-equal (import "minitest:assert-equal"))
((import "minitest:colorize") #t)
((import "minitest:verbose") #t)
(minitest:assert-equal
9
(transducers:transduce (transducers:map add1) + 0 [1 2 3])
"test that we can map and reduce with a transducer")
(minitest:assert-equal
9
(transducers:transduce (transducers:map add1) + 0 {1 2 3} vector:reduce)
"test that we can transduce other collections")
(minitest:assert-equal
1
(transducers:transduce (transducers:take 1) + 0 [1 2 3])
"test that we can take and reduce with a transducer")
(minitest:assert-equal
[(1 1 1) (2 2 2) (1)]
(transducers:transduce (transducers:partition-by id) += [] [1 1 1 2 2 2 1])
"test that we can take and reduce with a transducer")
(minitest:assert-equal
[1 1]
(transducers:transduce (transducers:filter (curry eq? 1)) += [] [1 2 3 1])
"test that we can filter with a transducer")
(minitest:assert-equal
[2 3]
(transducers:transduce
(transducers:compose
(transducers:map add1)
(transducers:filter (lambda (x) (not (eq? 4 x)))))
+=
[]
[1 2 3])
"test that we can compose transducers")
(minitest:assert-equal
[2]
(transducers:transduce
(transducers:compose
(transducers:map add1)
(transducers:filter (lambda (x) (not (eq? 3 x))))
(transducers:compose
(transducers:filter (lambda (x) (not (eq? 4 x))))))
+=
[]
[1 2 3])
"test that we can nest compositions")
(minitest:assert-equal
{1 2 3 4}
(transducers:into {} (transducers:map sub1) [2 3 4 5])
"test that we can transduce into new collection")
(minitest:assert-equal
[1 2 3 4]
(transducers:into [] transducers:cat [(1 2) (3 4)])
"test that we can cat collections (list)")
(minitest:assert-equal
[1 2 3 4]
(transducers:into [] transducers:cat {(1 2) (3 4)})
"test that we can cat collections (vector)")
(minitest:assert-equal
[0 1 2 3 4 5 6 7 8 9]
(transducers:into [] (transducers:mapcat reverse) [(3 2 1 0) (6 5 4) (9 8 7)])
"test that we can mapcat collections")
((import "minitest:results"))