blob: cef90b094ba8004d6e7678b7ae4530a975770ef2 (
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
|
... 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]" maybe (.use "[1]#[0]" functor)]]
[data
["[0]" bit (.use "[1]#[0]" equivalence)]
["[0]" text (.only)
["%" \\format]]]
[math
["[0]" random (.only Random)]
[number
["n" nat]
["i" int]]]
[test
["_" property (.only Test)]]]]
[\\library
["[0]" / (.only)
[///
["[0]" money (.only)
["[0]" currency (.only Currency)]]]]]
[///
["[0]T" money]])
(def .public (random $ max_sub_units)
(All (_ $)
(-> (Currency $) Nat
(Random (/.Action $))))
(do random.monad
[from (moneyT.random $ max_sub_units)
to (moneyT.random $ max_sub_units)]
(in (/.action from to))))
(def .public test
Test
(<| (_.covering /._)
(do [! random.monad]
[parameter (..random currency.usd 1000,00)
subject (..random currency.usd 1000,00)
from (moneyT.random currency.usd 1000,00)
to (moneyT.random currency.usd 1000,00)])
(_.for [/.Price /.Action])
(all _.and
(_.for [/.equivalence /.=]
(equivalenceT.spec /.equivalence (..random currency.usd 1000,00)))
(_.for [/.order /.<]
(orderT.spec /.order (..random currency.usd 1000,00)))
(_.coverage [/.action /.currency /.movement]
(let [it (/.action from to)]
(and (same? currency.usd (/.currency it))
(i.= (int (n.- (money.amount from) (money.amount to)))
(/.movement it)))))
(_.coverage [/.+ /.-]
(and (|> subject
(/.+ parameter)
(of /.equivalence = subject)
not)
(|> subject
(/.+ parameter)
(/.- parameter)
(of /.equivalence = subject))))
(_.coverage [/.min]
(and (/.<= parameter
(/.min parameter subject))
(/.<= subject
(/.min parameter subject))))
(_.coverage [/.max]
(and (/.>= parameter
(/.max parameter subject))
(/.>= subject
(/.max parameter subject))))
(_.coverage [/.>]
(bit#= (/.> parameter subject)
(/.< subject parameter)))
(_.coverage [/.<= /.>=]
(bit#= (/.<= parameter subject)
(/.>= subject parameter)))
(_.coverage [/.units /.sub_units
/.of_units /.of_sub_units]
(/.= subject
(/.+ (/.of_units currency.usd (/.units subject))
(/.of_sub_units currency.usd (/.sub_units subject)))))
(do !
[it (..random currency.usd 1000,00)]
(_.coverage [/.format]
(let [starts_with_quantity!
(text.starts_with? (%.int (/.movement it))
(text.replaced_once "." "" (/.format it)))
ends_with_currency!
(text.ends_with? (currency.alphabetic_code (/.currency it))
(/.format it))]
(and starts_with_quantity!
ends_with_currency!))))
)))
|