diff options
author | Eduardo Julian | 2022-11-29 18:48:42 -0400 |
---|---|---|
committer | Eduardo Julian | 2022-11-29 18:48:42 -0400 |
commit | c7f67a85f980db2dab2e2d7df4168af83e9013a8 (patch) | |
tree | 4bd1dc93b333066840b7a3a0704486005a0607b7 /stdlib/source/test/lux/world | |
parent | 8059ba6c421d3094fba336ac5d3dd39fe984b05e (diff) |
Added money-handling machinery.
Diffstat (limited to 'stdlib/source/test/lux/world')
-rw-r--r-- | stdlib/source/test/lux/world/money.lux | 72 | ||||
-rw-r--r-- | stdlib/source/test/lux/world/money/currency.lux | 26 |
2 files changed, 93 insertions, 5 deletions
diff --git a/stdlib/source/test/lux/world/money.lux b/stdlib/source/test/lux/world/money.lux new file mode 100644 index 000000000..dc21b0603 --- /dev/null +++ b/stdlib/source/test/lux/world/money.lux @@ -0,0 +1,72 @@ +(.require + [library + [lux (.except) + [abstract + [monad (.only do)] + [\\specification + ["[0]S" equivalence]]] + [control + ["[0]" maybe (.use "[1]#[0]" functor)]] + [data + ["[0]" text (.only) + ["%" \\format]]] + [math + ["[0]" random (.only Random)] + [number + ["n" nat]]] + [test + ["_" property (.only Test)]]]] + [\\library + ["[0]" / (.only) + ["[0]" currency]]] + ["[0]" / + ["[1][0]" currency]]) + +(def .public random + (Random (Ex (_ of) + (/.Money of))) + (do random.monad + [expected_currency /currency.random + expected_amount random.nat] + (in (/.money expected_currency expected_amount)))) + +(def .public test + Test + (<| (_.covering /._) + (do [! random.monad] + [.let [expected_currency currency.usd] + expected_amount random.nat + + expected_parameter (random.only (n.> 0) random.nat) + expected_subject random.nat]) + (_.for [/.Money]) + (all _.and + (_.for [/.equivalence] + (equivalenceS.spec /.equivalence ..random)) + + (_.coverage [/.money /.currency /.amount] + (let [it (/.money expected_currency expected_amount)] + (and (same? expected_currency (/.currency it)) + (same? expected_amount (/.amount it))))) + (_.coverage [/.+ /.-] + (let [parameter (/.money expected_currency expected_parameter) + subject (/.money expected_currency expected_subject)] + (and (|> subject + (/.+ parameter) + (at /.equivalence = subject) + not) + (|> subject + (/.+ parameter) + (/.- parameter) + (maybe#each (at /.equivalence = subject)) + (maybe.else false))))) + (do ! + [it ..random] + (_.coverage [/.format] + (and (text.starts_with? (%.nat (/.amount it)) + (text.replaced_once "." "" (/.format it))) + (text.ends_with? (currency.alphabetic_code (/.currency it)) + (/.format it))))) + + /currency.test + ))) diff --git a/stdlib/source/test/lux/world/money/currency.lux b/stdlib/source/test/lux/world/money/currency.lux index 0edb4b33c..927ffd8f3 100644 --- a/stdlib/source/test/lux/world/money/currency.lux +++ b/stdlib/source/test/lux/world/money/currency.lux @@ -2,14 +2,16 @@ [library [lux (.except) [abstract - [monad (.only do)]] + [monad (.only do)] + [\\specification + ["[0]S" equivalence]]] [data ["[0]" text] [collection ["[0]" list (.use "[1]#[0]" functor)] ["[0]" set]]] [math - ["[0]" random (.only Random)] + ["[0]" random (.only Random) (.use "[1]#[0]" monad)] [number ["n" nat]]] [test @@ -196,6 +198,17 @@ [/.zmw /.ZMW /.zambian_kwacha] [/.zwl /.ZWL /.zimbabwean_dollar] )] + (def .public random + (Random (Ex (_ of) + (/.Currency of))) + (`` (all random.either + (,, (with_template [<short> <type> <long>] + [(random#in <short>)] + + <currencies> + )) + ))) + (def .public test Test (<| (_.covering /._) @@ -203,9 +216,12 @@ []) (_.for [/.Currency]) (all _.and + (_.for [/.equivalence] + (equivalenceS.spec /.equivalence ..random)) + (with_expansions [<shorts> (with_template [<short> <type> <long>] [<short>] - + <currencies> )] (<| (_.for [<shorts>]) @@ -224,8 +240,8 @@ (set.of_list n.hash))] (n.= (list.size options) (set.size uniques)))) - (_.coverage [/.decimals] - (list.every? (|>> /.decimals (n.<= 3)) + (_.coverage [/.subdivisions] + (list.every? (|>> /.subdivisions (n.> 0)) options)) ))) (<| (_.for [/.currency /.type]) |