diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/test/lux/data/number/frac.lux | 40 | ||||
-rw-r--r-- | stdlib/source/test/lux/data/number/int.lux | 9 | ||||
-rw-r--r-- | stdlib/source/test/lux/data/number/nat.lux | 139 |
3 files changed, 143 insertions, 45 deletions
diff --git a/stdlib/source/test/lux/data/number/frac.lux b/stdlib/source/test/lux/data/number/frac.lux index 193b4a960..08fcef498 100644 --- a/stdlib/source/test/lux/data/number/frac.lux +++ b/stdlib/source/test/lux/data/number/frac.lux @@ -183,11 +183,19 @@ (/.mod left right)))))) )) (with-expansions [<jvm> ($_ _.and - (do random.monad - [expected random.frac] - (_.cover [/.to-bits] - (n.= (.nat (java/lang/Double::doubleToRawLongBits expected)) - (/.to-bits expected)))) + (let [test (: (-> Frac Bit) + (function (_ value) + (n.= (.nat (java/lang/Double::doubleToRawLongBits value)) + (/.to-bits value))))] + (do random.monad + [sample random.frac] + (_.cover [/.to-bits] + (and (test sample) + (test /.biggest) + (test /.smallest) + (test /.not-a-number) + (test /.positive-infinity) + (test /.negative-infinity))))) (do random.monad [sample random.i64] (_.cover [/.from-bits] @@ -199,13 +207,21 @@ )] (for {@.old <jvm> @.jvm <jvm>} - (do random.monad - [expected random.frac] - (_.cover [/.to-bits /.from-bits] - (let [actual (|> expected /.to-bits /.from-bits)] - (or (/.= expected actual) - (and (/.not-a-number? expected) - (/.not-a-number? actual)))))))) + (let [test (: (-> Frac Bit) + (function (_ expected) + (let [actual (|> expected /.to-bits /.from-bits)] + (or (/.= expected actual) + (and (/.not-a-number? expected) + (/.not-a-number? actual))))))] + (do random.monad + [sample random.frac] + (_.cover [/.to-bits /.from-bits] + (and (test sample) + (test /.biggest) + (test /.smallest) + (test /.not-a-number) + (test /.positive-infinity) + (test /.negative-infinity))))))) (do random.monad [expected random.safe-frac] (_.cover [/.negate] diff --git a/stdlib/source/test/lux/data/number/int.lux b/stdlib/source/test/lux/data/number/int.lux index 31b732b88..16c23246a 100644 --- a/stdlib/source/test/lux/data/number/int.lux +++ b/stdlib/source/test/lux/data/number/int.lux @@ -17,7 +17,7 @@ ["f" frac] ["." i64 ("#\." hash)]]] [math - ["." random]]] + ["." random (#+ Random)]]] {1 ["." /]}) @@ -53,8 +53,7 @@ (def: predicate Test (do {! random.monad} - [sample random.int - shift (\ ! map /.abs random.int)] + [sample random.int] ($_ _.and (_.cover [/.negative?] (bit\= (/.negative? sample) @@ -132,7 +131,9 @@ (/.mod left right)))))) )) (do {! random.monad} - [#let [random (\ ! map (/.% +1,000) random.int)] + [#let [random (|> random.int + (\ ! map (/.% +1,000)) + (random.filter (|>> (/.= +0) not)))] left random right random] ($_ _.and diff --git a/stdlib/source/test/lux/data/number/nat.lux b/stdlib/source/test/lux/data/number/nat.lux index e07f584b1..6e027eab1 100644 --- a/stdlib/source/test/lux/data/number/nat.lux +++ b/stdlib/source/test/lux/data/number/nat.lux @@ -1,6 +1,5 @@ (.module: [lux #* - ["%" data/text/format (#+ format)] ["_" test (#+ Test)] [abstract [monad (#+ do)] @@ -12,38 +11,120 @@ ["$." interval] ["$." monoid] ["$." codec]]}] + [data + ["." bit ("#\." equivalence)] + [number + ["f" frac] + ["." i64 ("#\." hash)]]] [math - ["r" random]]] + ["." random]]] {1 - ["." / - //]}) + ["." /]}) -(def: #export test +(def: signature Test - (<| (_.context (%.name (name-of /._))) - (`` ($_ _.and - ($equivalence.spec /.equivalence r.nat) - ($order.spec /.order r.nat) - ($enum.spec /.enum r.nat) - ($interval.spec /.interval r.nat) - (~~ (template [<monoid>] - [(<| (_.context (%.name (name-of <monoid>))) - ($monoid.spec /.equivalence <monoid> r.nat))] + (`` ($_ _.and + (_.with-cover [/.equivalence /.=] + ($equivalence.spec /.equivalence random.nat)) + (_.with-cover [/.order /.<] + ($order.spec /.order random.nat)) + (_.with-cover [/.enum] + ($enum.spec /.enum random.nat)) + (_.with-cover [/.interval] + ($interval.spec /.interval random.nat)) + (~~ (template [<compose> <monoid>] + [(_.with-cover [<monoid> <compose>] + ($monoid.spec /.equivalence <monoid> random.nat))] + + [/.+ /.addition] + [/.* /.multiplication] + + [/.min /.minimum] + [/.max /.maximum] + )) + (~~ (template [<codec>] + [(_.with-cover [<codec>] + ($codec.spec /.equivalence <codec> random.nat))] + + [/.binary] [/.octal] [/.decimal] [/.hex] + )) + ))) - [/.addition] [/.multiplication] [/.minimum] [/.maximum] - )) - (~~ (template [<codec>] - [(<| (_.context (%.name (name-of /.binary))) - ($codec.spec /.equivalence <codec> r.nat))] +(def: predicate + Test + (do {! random.monad} + [sample random.nat] + ($_ _.and + (_.cover [/.even? /.odd?] + (bit\= (/.even? sample) + (not (/.odd? sample)))) + ))) - [/.binary] [/.octal] [/.decimal] [/.hex] - )) +(def: #export test + Test + (<| (_.covering /._) + (_.with-cover [.Nat]) + ($_ _.and + (do random.monad + [sample random.nat] + ($_ _.and + (_.cover [/.-] + (and (/.= 0 (/.- sample sample)) + (/.= sample (/.- 0 sample)))) + (_.cover [/./] + (and (/.= 1 (/./ sample sample)) + (/.= sample (/./ 1 sample)))) + )) + (do random.monad + [left random.nat + right random.nat] + ($_ _.and + (_.cover [/.>] + (bit\= (/.> left right) + (/.< right left))) + (_.cover [/.<= /.>=] + (bit\= (/.<= left right) + (/.>= right left))) + )) + (do random.monad + [left (random.filter (|>> (/.= 0) not) + random.nat) + right random.nat] + ($_ _.and + (_.cover [/.%] + (let [rem (/.% left right) + div (|> right (/.- rem) (/./ left))] + (/.= right + (|> div (/.* left) (/.+ rem))))) + (_.cover [/./%] + (let [[div rem] (/./% left right)] + (and (/.= div (/./ left right)) + (/.= rem (/.% left right))))) + )) + (do {! random.monad} + [#let [random (\ ! map (|>> (/.% 1,000) inc) random.nat)] + left random + right random] + ($_ _.and + (_.cover [/.gcd] + (let [gcd (/.gcd left right)] + (and (/.= 0 (/.% gcd left)) + (/.= 0 (/.% gcd right))))) + (_.cover [/.lcm] + (let [lcm (/.lcm left right)] + (and (/.= 0 (/.% left lcm)) + (/.= 0 (/.% right lcm))))) + )) + (do {! random.monad} + [expected (\ ! map (/.% 1,000,000) random.nat)] + (_.cover [/.frac] + (|> expected /.frac f.nat (/.= expected)))) + (do random.monad + [sample random.nat] + (_.cover [/.hash] + (i64\= (i64\hash sample) + (\ /.hash hash sample)))) - (_.test "Alternate notations." - (and (/.= (bin "11001001") - (bin "11,00,10,01")) - (/.= (oct "615243") - (oct "615,243")) - (/.= (hex "deadBEEF") - (hex "dead,BEEF")))) - )))) + ..predicate + ..signature + ))) |