aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/world/money.lux
diff options
context:
space:
mode:
authorEduardo Julian2022-12-11 16:07:39 -0400
committerEduardo Julian2022-12-11 16:07:39 -0400
commiteef4422b1f16be2b8c651461f2c006dc4c11f314 (patch)
tree0fa040c7a628d03551b7d7d4244a4af025d5edba /stdlib/source/test/lux/world/money.lux
parentfd3f02c024687bc5c2b9741f6386719a0affb7bb (diff)
Added support for fixed-point arithmetic.
Diffstat (limited to 'stdlib/source/test/lux/world/money.lux')
-rw-r--r--stdlib/source/test/lux/world/money.lux42
1 files changed, 40 insertions, 2 deletions
diff --git a/stdlib/source/test/lux/world/money.lux b/stdlib/source/test/lux/world/money.lux
index 4ebd46bf2..4cddc38ee 100644
--- a/stdlib/source/test/lux/world/money.lux
+++ b/stdlib/source/test/lux/world/money.lux
@@ -4,10 +4,12 @@
[abstract
[monad (.only do)]
[\\specification
- ["[0]S" equivalence]]]
+ ["[0]S" equivalence]
+ ["[0]S" order]]]
[control
["[0]" maybe (.use "[1]#[0]" functor)]]
[data
+ ["[0]" bit (.use "[1]#[0]" equivalence)]
["[0]" text (.only)
["%" \\format]]]
[math
@@ -41,8 +43,10 @@
expected_subject random.nat])
(_.for [/.Money])
(all _.and
- (_.for [/.equivalence]
+ (_.for [/.equivalence /.=]
(equivalenceS.spec /.equivalence ..random))
+ (_.for [/.order /.<]
+ (orderS.spec /.order ..random))
(_.coverage [/.money /.currency /.amount]
(let [it (/.money expected_currency expected_amount)]
@@ -60,6 +64,40 @@
(/.- parameter)
(maybe#each (of /.equivalence = subject))
(maybe.else false)))))
+ (_.coverage [/.min]
+ (let [expected_parameter (/.money expected_currency expected_parameter)
+ expected_subject (/.money expected_currency expected_subject)]
+ (and (/.<= expected_parameter
+ (/.min expected_parameter expected_subject))
+ (/.<= expected_subject
+ (/.min expected_parameter expected_subject)))))
+ (_.coverage [/.max]
+ (let [expected_parameter (/.money expected_currency expected_parameter)
+ expected_subject (/.money expected_currency expected_subject)]
+ (and (/.>= expected_parameter
+ (/.max expected_parameter expected_subject))
+ (/.>= expected_subject
+ (/.max expected_parameter expected_subject)))))
+ (let [expected_parameter (/.money expected_currency expected_parameter)
+ expected_subject (/.money expected_currency expected_subject)]
+ (all _.and
+ (_.coverage [/.>]
+ (bit#= (/.> expected_parameter expected_subject)
+ (/.< expected_subject expected_parameter)))
+ (_.coverage [/.<= /.>=]
+ (bit#= (/.<= expected_parameter expected_subject)
+ (/.>= expected_subject expected_parameter)))
+ ))
+ (_.coverage [/.units /.sub_units]
+ (let [expected (/.money expected_currency expected_amount)
+ actual (/.money expected_currency (n.+ (/.units expected)
+ (/.sub_units expected)))]
+ (/.= expected actual)))
+ (_.coverage [/.of_units /.of_sub_units]
+ (let [expected (/.money expected_currency expected_amount)
+ actual (/.+ (/.of_units expected_currency (/.units expected))
+ (/.of_sub_units expected_currency (/.sub_units expected)))]
+ (/.= expected actual)))
(do !
[it ..random]
(_.coverage [/.format]