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 | |
parent | 8059ba6c421d3094fba336ac5d3dd39fe984b05e (diff) |
Added money-handling machinery.
Diffstat (limited to 'stdlib/source/test')
-rw-r--r-- | stdlib/source/test/lux/control/exception.lux | 3 | ||||
-rw-r--r-- | stdlib/source/test/lux/ffi.js.lux | 18 | ||||
-rw-r--r-- | stdlib/source/test/lux/meta/target/js.lux | 4 | ||||
-rw-r--r-- | stdlib/source/test/lux/world.lux | 5 | ||||
-rw-r--r-- | stdlib/source/test/lux/world/money.lux | 72 | ||||
-rw-r--r-- | stdlib/source/test/lux/world/money/currency.lux | 26 |
6 files changed, 108 insertions, 20 deletions
diff --git a/stdlib/source/test/lux/control/exception.lux b/stdlib/source/test/lux/control/exception.lux index 5c29d3103..164dfa9bf 100644 --- a/stdlib/source/test/lux/control/exception.lux +++ b/stdlib/source/test/lux/control/exception.lux @@ -37,7 +37,8 @@ field1 report_element value1 report_element] (<| (_.covering /._) - (_.for [/.Exception]) + (_.for [/.Exception + /.#constructor /.#label]) (all _.and (_.coverage [/.except] (when (/.except ..an_exception []) diff --git a/stdlib/source/test/lux/ffi.js.lux b/stdlib/source/test/lux/ffi.js.lux index 2a5748483..ba09925f2 100644 --- a/stdlib/source/test/lux/ffi.js.lux +++ b/stdlib/source/test/lux/ffi.js.lux @@ -101,13 +101,13 @@ (not (/.null? (|>>))))) (_.coverage [/.global] (|> (/.global /.Function [parseFloat]) - "js object null?" + .js_object_null?# not)) (_.coverage [/.function] (|> (/.function (_ [input/0 Nat]) Int (.int input/0)) - "js object null?" + .js_object_null?# not)) (_.coverage [/.on_browser? /.on_node_js? /.on_nashorn?] (and (or /.on_nashorn? @@ -157,13 +157,13 @@ "my_function" function "my_object" object "my_undefined" (/.undefined))] - (and (same? boolean ("js object get" "my_boolean" it)) - (same? number ("js object get" "my_number" it)) - (same? string ("js object get" "my_string" it)) - (same? function ("js object get" "my_function" it)) - (same? object ("js object get" "my_object" it)) - (same? (/.undefined) ("js object get" "my_undefined" it)) - (/.undefined? ("js object get" "my_yolo" it))))) + (and (same? boolean (.js_object_get# "my_boolean" it)) + (same? number (.js_object_get# "my_number" it)) + (same? string (.js_object_get# "my_string" it)) + (same? function (.js_object_get# "my_function" it)) + (same? object (.js_object_get# "my_object" it)) + (same? (/.undefined) (.js_object_get# "my_undefined" it)) + (/.undefined? (.js_object_get# "my_yolo" it))))) $/export.test $/node_js.test diff --git a/stdlib/source/test/lux/meta/target/js.lux b/stdlib/source/test/lux/meta/target/js.lux index f305710cf..eef7a43d3 100644 --- a/stdlib/source/test/lux/meta/target/js.lux +++ b/stdlib/source/test/lux/meta/target/js.lux @@ -36,8 +36,8 @@ ... Note: I have to call "eval" this way ... in order to avoid a quirk of calling eval in Node ... when the code is running under "use strict";. - (try (let [return ("js apply" (function.identity ("js constant" "eval")) [(/.code code)])] - (if ("js object null?" return) + (try (let [return (.js_apply# (function.identity (.js_constant# "eval")) [(/.code code)])] + (if (.js_object_null?# return) {.#None} {.#Some return})))) diff --git a/stdlib/source/test/lux/world.lux b/stdlib/source/test/lux/world.lux index 9ce864d44..e1309f5f5 100644 --- a/stdlib/source/test/lux/world.lux +++ b/stdlib/source/test/lux/world.lux @@ -13,8 +13,7 @@ ["[1][0]" output ["[1]/[0]" video ["[1]/[0]" resolution]]] - ["[1][0]" money - ["[1]/[0]" currency]] + ["[1][0]" money] ["[1][0]" net] ["[1][0]" time] ["[1][0]" locale] @@ -29,7 +28,7 @@ /environment.test /input/keyboard.test /output/video/resolution.test - /money/currency.test + /money.test /net.test /time.test /locale.test 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]) |