blob: 9c8fde31c07f10390ea765d949f36d6a5503f55b (
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
... This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
... If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
(.require
[library
[lux (.except)
[abstract
[monad (.only do)]
["[0]" equivalence
["[1]T" \\test]]
["[0]" order
["[1]T" \\test]]]
[control
["[0]" try (.use "[1]#[0]" functor)]
["[0]" exception]]
[data
["[0]" bit (.use "[1]#[0]" equivalence)]
["[0]" text (.only)
["%" \\format]]]
[math
["[0]" random (.only Random)]
[number
["n" nat]]
["[0]" arithmetic
["[1]T" \\test]]]
[test
["_" property (.only Test)]]]]
[\\library
["[0]" /]])
(def .public (random @)
(All (_ @)
(-> (/.Point @)
(Random (/.Fixed @))))
(do random.monad
[units random.int
sub_units random.rev]
(in (/.fixed @ units sub_units))))
(def .public test
Test
(<| (_.covering /._)
(do [! random.monad]
[candidate_point random.nat
expected_point (of ! each (n.% (++ /.maximum)) random.nat)
.let [@ (try.trusted (/.point expected_point))]
expected (..random @)
parameter (..random @)
subject (..random @)])
(all _.and
(<| (_.for [/.Point])
(all _.and
(_.coverage [/.point /.location]
(|> (/.point expected_point)
(try#each (|>> /.location
(same? expected_point)))
(try.else false)))
(_.coverage [/.maximum /.point_exceeds_maximum]
(when (/.point candidate_point)
{try.#Success it}
(n.<= /.maximum candidate_point)
{try.#Failure error}
(and (n.> /.maximum candidate_point)
(exception.match? /.point_exceeds_maximum error))))
))
(<| (_.for [/.Fixed])
(all _.and
(_.for [/.equivalence /.=]
(equivalenceT.spec (/.equivalence @) (..random @)))
(_.for [/.order /.<]
(orderT.spec (/.order @) (..random @)))
... (_.for [/.arithmetic]
... (arithmeticT.spec (/.equivalence @) (/.arithmetic @) (..random @)))
(_.coverage [/.fixed /.units /.sub_units]
(/.= @
expected
(/.fixed @ (/.units @ expected) (/.sub_units @ expected))))
(_.coverage [/.of_int /.of_rev]
(/.= @
expected
(/.+ @
(/.of_int @ (/.units @ expected))
(/.of_rev @ (/.sub_units @ expected)))))
(_.coverage [/.>]
(bit#= (/.> @ parameter subject)
(/.< @ subject parameter)))
(_.coverage [/.<= /.>=]
(bit#= (/.<= @ parameter subject)
(/.>= @ subject parameter)))
(_.coverage [/.-]
(and (/.= @
(/.of_int @ +0)
(/.- @ expected expected))
(/.= @
(/.of_rev @ .0)
(/.- @ expected expected))))
(_.coverage [/.+]
(|> subject
(/.+ @ parameter)
(/.- @ parameter)
(/.= @ subject)))
(_.coverage [/./]
(/.= @
(/.of_int @ +1)
(/./ @ expected expected)))
(_.coverage [/.* /.%]
(let [rem (/.% @ parameter subject)
div (|> subject (/.- @ rem) (/./ @ parameter))]
(/.= @ subject
(|> div (/.* @ parameter) (/.+ @ rem)))))
(_.coverage [/.format]
(let [it (/.format @ expected)]
(and (text.contains? (%.int (/.units @ expected))
it)
(text.contains? (%.rev (/.sub_units @ expected))
it))))
))
)))
|