diff options
Diffstat (limited to 'stdlib/source/test/lux/math/number/nat.lux')
-rw-r--r-- | stdlib/source/test/lux/math/number/nat.lux | 230 |
1 files changed, 115 insertions, 115 deletions
diff --git a/stdlib/source/test/lux/math/number/nat.lux b/stdlib/source/test/lux/math/number/nat.lux index f236a7aa6..05c248337 100644 --- a/stdlib/source/test/lux/math/number/nat.lux +++ b/stdlib/source/test/lux/math/number/nat.lux @@ -1,132 +1,132 @@ (.using - [library - [lux "*" - ["_" test {"+" Test}] - [abstract - [monad {"+" do}] - [\\specification - ["$[0]" equivalence] - ["$[0]" hash] - ["$[0]" order] - ["$[0]" enum] - ["$[0]" interval] - ["$[0]" monoid] - ["$[0]" codec]]] - [data - ["[0]" bit ("[1]#[0]" equivalence)]] - [math - ["[0]" random]]]] - [\\library - ["[0]" / - [// - ["f" frac]]]]) + [library + [lux "*" + ["_" test {"+" Test}] + [abstract + [monad {"+" do}] + [\\specification + ["$[0]" equivalence] + ["$[0]" hash] + ["$[0]" order] + ["$[0]" enum] + ["$[0]" interval] + ["$[0]" monoid] + ["$[0]" codec]]] + [data + ["[0]" bit ("[1]#[0]" equivalence)]] + [math + ["[0]" random]]]] + [\\library + ["[0]" / + [// + ["f" frac]]]]) (def: signature Test - (`` ($_ _.and - (_.for [/.equivalence /.=] - ($equivalence.spec /.equivalence random.nat)) - (_.for [/.hash] - ($hash.spec /.hash random.nat)) - (_.for [/.order /.<] - ($order.spec /.order random.nat)) - (_.for [/.enum] - ($enum.spec /.enum random.nat)) - (_.for [/.interval] - ($interval.spec /.interval random.nat)) - (~~ (template [<composite> <monoid>] - [(_.for [<monoid> <composite>] - ($monoid.spec /.equivalence <monoid> random.nat))] - - [/.+ /.addition] - [/.* /.multiplication] + (`` (all _.and + (_.for [/.equivalence /.=] + ($equivalence.spec /.equivalence random.nat)) + (_.for [/.hash] + ($hash.spec /.hash random.nat)) + (_.for [/.order /.<] + ($order.spec /.order random.nat)) + (_.for [/.enum] + ($enum.spec /.enum random.nat)) + (_.for [/.interval] + ($interval.spec /.interval random.nat)) + (~~ (template [<composite> <monoid>] + [(_.for [<monoid> <composite>] + ($monoid.spec /.equivalence <monoid> random.nat))] + + [/.+ /.addition] + [/.* /.multiplication] - [/.min /.minimum] - [/.max /.maximum] - )) - (~~ (template [<codec>] - [(_.for [<codec>] - ($codec.spec /.equivalence <codec> random.nat))] + [/.min /.minimum] + [/.max /.maximum] + )) + (~~ (template [<codec>] + [(_.for [<codec>] + ($codec.spec /.equivalence <codec> random.nat))] - [/.binary] [/.octal] [/.decimal] [/.hex] - )) - ))) + [/.binary] [/.octal] [/.decimal] [/.hex] + )) + ))) (def: predicate Test (do [! random.monad] [sample random.nat] - ($_ _.and - (_.cover [/.even? /.odd?] - (bit#= (/.even? sample) - (not (/.odd? sample)))) - ))) + (all _.and + (_.cover [/.even? /.odd?] + (bit#= (/.even? sample) + (not (/.odd? sample)))) + ))) (def: .public test Test (<| (_.covering /._) (_.for [.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.only (|>> (/.= 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 (# ! each (|>> (/.% 1,000) ++) random.nat)] - left random - right random] - ($_ _.and - (_.cover [/.gcd] - (let [gcd (/.gcd left right)] - (and (/.= 0 (/.% gcd left)) - (/.= 0 (/.% gcd right))))) - (_.cover [/.co_prime?] - (bit#= (/.= 1 (/.gcd left right)) - (/.co_prime? left right))) - (_.cover [/.lcm] - (let [lcm (/.lcm left right)] - (and (/.= 0 (/.% left lcm)) - (/.= 0 (/.% right lcm))))) - )) - (do [! random.monad] - [expected (# ! each (/.% 1,000,000) random.nat) - sample random.nat] - (_.cover [/.frac] - (and (|> expected /.frac f.nat (/.= expected)) - (f.number? (/.frac sample))))) + (all _.and + (do random.monad + [sample random.nat] + (all _.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] + (all _.and + (_.cover [/.>] + (bit#= (/.> left right) + (/.< right left))) + (_.cover [/.<= /.>=] + (bit#= (/.<= left right) + (/.>= right left))) + )) + (do random.monad + [left (random.only (|>> (/.= 0) not) + random.nat) + right random.nat] + (all _.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 (# ! each (|>> (/.% 1,000) ++) random.nat)] + left random + right random] + (all _.and + (_.cover [/.gcd] + (let [gcd (/.gcd left right)] + (and (/.= 0 (/.% gcd left)) + (/.= 0 (/.% gcd right))))) + (_.cover [/.co_prime?] + (bit#= (/.= 1 (/.gcd left right)) + (/.co_prime? left right))) + (_.cover [/.lcm] + (let [lcm (/.lcm left right)] + (and (/.= 0 (/.% left lcm)) + (/.= 0 (/.% right lcm))))) + )) + (do [! random.monad] + [expected (# ! each (/.% 1,000,000) random.nat) + sample random.nat] + (_.cover [/.frac] + (and (|> expected /.frac f.nat (/.= expected)) + (f.number? (/.frac sample))))) - ..predicate - ..signature - ))) + ..predicate + ..signature + ))) |