blob: 783dcf2dfca3956e57919231348a58054c6a09c2 (
plain)
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
(.require
[library
[lux (.except)
[abstract
[monad (.only do)]
["[0]" equivalence
["[1]T" \\test]]
["[0]" hash
["[1]T" \\test]]]
[control
["[0]" pipe]]
[data
["[0]" text]
[collection
["[0]" list (.use "[1]#[0]" functor)]]]
[math
["[0]" random]
[number
["n" nat]
["i" int]]]
[test
["_" property (.only Test)]]]]
[\\library
["[0]" /]])
(def .public test
Test
(<| (_.covering /._)
(_.for [.Union .Or])
(do [! random.monad]
[expected random.nat
shift random.nat]
(all _.and
(_.for [/.equivalence]
(equivalenceT.spec (/.equivalence n.equivalence n.equivalence)
(random.or random.nat random.nat)))
(_.for [/.hash]
(hashT.spec (/.hash n.hash n.hash)
(random.or random.nat random.nat)))
(_.coverage [/.left]
(|> (/.left expected)
(is (Or Nat Nat))
(pipe.when
{0 #0 actual} (n.= expected actual)
_ false)))
(_.coverage [/.right]
(|> (/.right expected)
(is (Or Nat Nat))
(pipe.when
{0 #1 actual} (n.= expected actual)
_ false)))
(_.coverage [/.either]
(and (|> (/.left expected)
(is (Or Nat Nat))
(/.either (n.+ shift) (n.- shift))
(n.= (n.+ shift expected)))
(|> (/.right expected)
(is (Or Nat Nat))
(/.either (n.+ shift) (n.- shift))
(n.= (n.- shift expected)))))
(_.coverage [/.then]
(and (|> (/.left expected)
(is (Or Nat Nat))
(/.then (n.+ shift) (n.- shift))
(pipe.when {0 #0 actual} (n.= (n.+ shift expected) actual) _ false))
(|> (/.right expected)
(is (Or Nat Nat))
(/.then (n.+ shift) (n.- shift))
(pipe.when {0 #1 actual} (n.= (n.- shift expected) actual) _ false))))
(do !
[size (of ! each (n.% 5) random.nat)
expected (random.list size random.nat)]
(all _.and
(_.coverage [/.lefts]
(let [actual (is (List (Or Nat Nat))
(list#each /.left expected))]
(and (of (list.equivalence n.equivalence) =
expected
(/.lefts actual))
(of (list.equivalence n.equivalence) =
(list)
(/.rights actual)))))
(_.coverage [/.rights]
(let [actual (is (List (Or Nat Nat))
(list#each /.right expected))]
(and (of (list.equivalence n.equivalence) =
expected
(/.rights actual))
(of (list.equivalence n.equivalence) =
(list)
(/.lefts actual)))))
(_.coverage [/.partition]
(let [[lefts rights] (|> expected
(list#each (function (_ value)
(if (n.even? value)
(/.left value)
(/.right value))))
(is (List (Or Nat Nat)))
/.partition)]
(and (of (list.equivalence n.equivalence) =
(list.only n.even? expected)
lefts)
(of (list.equivalence n.equivalence) =
(list.only (|>> n.even? not) expected)
rights))))
))
))))
|