aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test
diff options
context:
space:
mode:
authorEduardo Julian2020-12-04 01:13:01 -0400
committerEduardo Julian2020-12-04 01:13:01 -0400
commit8df63aae42c40ac0413ccfacc3b2e8eb72e00a15 (patch)
tree5e1eb6833398b8a67a2e3d0db4a615204a25f80f /stdlib/source/test
parent0205e5146b50ab066d152fccda0fc8cef4eef852 (diff)
Re-named old luxc-jvm to lux-bootstrapper.
Diffstat (limited to 'stdlib/source/test')
-rw-r--r--stdlib/source/test/lux/data/number/frac.lux240
-rw-r--r--stdlib/source/test/lux/data/number/i64.lux26
-rw-r--r--stdlib/source/test/lux/data/number/int.lux179
3 files changed, 289 insertions, 156 deletions
diff --git a/stdlib/source/test/lux/data/number/frac.lux b/stdlib/source/test/lux/data/number/frac.lux
index fd963a3ef..193b4a960 100644
--- a/stdlib/source/test/lux/data/number/frac.lux
+++ b/stdlib/source/test/lux/data/number/frac.lux
@@ -12,9 +12,7 @@
["$." monoid]
["$." codec]]}]
[data
- ["." bit ("#\." equivalence)]
- [text
- ["%" format (#+ format)]]]
+ ["." bit ("#\." equivalence)]]
[math
["." random (#+ Random)]]]
{1
@@ -29,31 +27,6 @@
(Random Frac)
(\ random.monad map (|>> (i.% +1,000,000) i.frac) random.int))
-(def: signature
- Test
- (`` ($_ _.and
- (_.with-cover [/.equivalence /.=]
- ($equivalence.spec /.equivalence random.safe-frac))
- (_.with-cover [/.order /.<]
- ($order.spec /.order random.safe-frac))
- (~~ (template [<compose> <monoid>]
- [(_.with-cover [<monoid> <compose>]
- ($monoid.spec /.equivalence <monoid> ..random))]
-
- [/.+ /.addition]
- [/.* /.multiplication]
-
- [/.min /.minimum]
- [/.max /.maximum]
- ))
- (~~ (template [<codec>]
- [(_.with-cover [<codec>]
- ($codec.spec /.equivalence <codec> random.safe-frac))]
-
- [/.binary] [/.octal] [/.decimal] [/.hex]
- ))
- )))
-
(def: constant
Test
(do random.monad
@@ -117,6 +90,31 @@
(|> expected r.frac /.rev (r.= expected))))
))
+(def: signature
+ Test
+ (`` ($_ _.and
+ (_.with-cover [/.equivalence /.=]
+ ($equivalence.spec /.equivalence random.safe-frac))
+ (_.with-cover [/.order /.<]
+ ($order.spec /.order random.safe-frac))
+ (~~ (template [<compose> <monoid>]
+ [(_.with-cover [<monoid> <compose>]
+ ($monoid.spec /.equivalence <monoid> ..random))]
+
+ [/.+ /.addition]
+ [/.* /.multiplication]
+
+ [/.min /.minimum]
+ [/.max /.maximum]
+ ))
+ (~~ (template [<codec>]
+ [(_.with-cover [<codec>]
+ ($codec.spec /.equivalence <codec> random.safe-frac))]
+
+ [/.binary] [/.octal] [/.decimal] [/.hex]
+ ))
+ )))
+
(with-expansions [<jvm> (as-is (host.import: java/lang/Double
["#::."
(#static doubleToRawLongBits #manual [double] long)
@@ -128,92 +126,104 @@
Test
(<| (_.covering /._)
(_.with-cover [.Frac])
- (`` ($_ _.and
- (do random.monad
- [left random.safe-frac
- right random.safe-frac]
- ($_ _.and
- (_.cover [/.>]
- (bit\= (/.> left right)
- (/.< right left)))
- (_.cover [/.<= /.>=]
- (bit\= (/.<= left right)
- (/.>= right left)))
- ))
- (do random.monad
- [left ..random
- right ..random]
- ($_ _.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
- [sample random.safe-frac]
- ($_ _.and
- (_.cover [/.-]
- (and (/.= +0.0 (/.- sample sample))
- (/.= sample (/.- +0.0 sample))
- (/.= (/.negate sample)
- (/.- sample +0.0))))
- (_.cover [/./]
- (and (/.= +1.0 (/./ sample sample))
- (/.= sample (/./ +1.0 sample))))
- (_.cover [/.abs]
- (bit\= (/.> sample (/.abs sample))
- (/.negative? sample)))
- (_.cover [/.signum]
- (/.= (/.abs sample)
- (/.* (/.signum sample) sample)))
- ))
- (with-expansions [<jvm> ($_ _.and
- (do random.monad
- [expected random.frac]
- (_.cover [/.to-bits]
- (n.= (.nat (java/lang/Double::doubleToRawLongBits expected))
- (/.to-bits expected))))
- (do random.monad
- [sample random.i64]
- (_.cover [/.from-bits]
- (let [expected (java/lang/Double::longBitsToDouble sample)
- actual (/.from-bits sample)]
- (or (/.= expected actual)
- (and (/.not-a-number? expected)
- (/.not-a-number? actual))))))
- )]
- (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))))))))
- (do random.monad
- [sample random.frac]
- (_.cover [/.hash]
- (n.= (/.to-bits sample)
- (\ /.hash hash sample))))
- (do random.monad
- [expected random.safe-frac]
- (_.cover [/.negate]
- (let [subtraction!
- (/.= +0.0 (/.+ (/.negate expected) expected))
+ ($_ _.and
+ (do random.monad
+ [left random.safe-frac
+ right random.safe-frac]
+ ($_ _.and
+ (_.cover [/.>]
+ (bit\= (/.> left right)
+ (/.< right left)))
+ (_.cover [/.<= /.>=]
+ (bit\= (/.<= left right)
+ (/.>= right left)))
+ ))
+ (do random.monad
+ [sample random.safe-frac]
+ ($_ _.and
+ (_.cover [/.-]
+ (and (/.= +0.0 (/.- sample sample))
+ (/.= sample (/.- +0.0 sample))
+ (/.= (/.negate sample)
+ (/.- sample +0.0))))
+ (_.cover [/./]
+ (and (/.= +1.0 (/./ sample sample))
+ (/.= sample (/./ +1.0 sample))))
+ (_.cover [/.abs]
+ (bit\= (/.> sample (/.abs sample))
+ (/.negative? sample)))
+ (_.cover [/.signum]
+ (/.= (/.abs sample)
+ (/.* (/.signum sample) sample)))
+ ))
+ (do random.monad
+ [left ..random
+ right ..random]
+ ($_ _.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)))))
+ (_.cover [/.mod]
+ (and (/.= (/.signum left)
+ (/.signum (/.mod left right)))
+ (/.= (/.signum right)
+ (/.signum (/.% left right)))
+ (if (/.= (/.signum left) (/.signum right))
+ (/.= (/.% left right)
+ (/.mod left right))
+ (or (and (/.= +0.0 (/.% left right))
+ (/.= +0.0 (/.mod left right)))
+ (/.= (/.+ left (/.% left right))
+ (/.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))))
+ (do random.monad
+ [sample random.i64]
+ (_.cover [/.from-bits]
+ (let [expected (java/lang/Double::longBitsToDouble sample)
+ actual (/.from-bits sample)]
+ (or (/.= expected actual)
+ (and (/.not-a-number? expected)
+ (/.not-a-number? actual))))))
+ )]
+ (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))))))))
+ (do random.monad
+ [expected random.safe-frac]
+ (_.cover [/.negate]
+ (let [subtraction!
+ (/.= +0.0 (/.+ (/.negate expected) expected))
- inverse!
- (|> expected /.negate /.negate (/.= expected))]
- (and subtraction!
- inverse!))))
+ inverse!
+ (|> expected /.negate /.negate (/.= expected))]
+ (and subtraction!
+ inverse!))))
+ (do random.monad
+ [sample random.frac]
+ (_.cover [/.hash]
+ (n.= (/.to-bits sample)
+ (\ /.hash hash sample))))
- ..constant
- ..predicate
- ..conversion
- ..signature
- ))))
+ ..constant
+ ..predicate
+ ..conversion
+ ..signature
+ )))
diff --git a/stdlib/source/test/lux/data/number/i64.lux b/stdlib/source/test/lux/data/number/i64.lux
index 89dc6a669..a9cddc921 100644
--- a/stdlib/source/test/lux/data/number/i64.lux
+++ b/stdlib/source/test/lux/data/number/i64.lux
@@ -118,18 +118,20 @@
#let [spare (n.- size /.width)]
offset (\ ! map (n.% spare) random.nat)]
(_.cover [/.region]
- (\= (|> pattern
- ## NNNNYYYYNNNN
- (/.logic-right-shift offset)
- ## ____NNNNYYYY
- (/.left-shift spare)
- ## YYYY________
- (/.logic-right-shift spare)
- ## ________YYYY
- (/.left-shift offset)
- ## ____YYYY____
- )
- (/.and (/.region size offset) pattern))))
+ (case size
+ 0 (\= /.false (/.region size offset))
+ _ (\= (|> pattern
+ ## NNNNYYYYNNNN
+ (/.logic-right-shift offset)
+ ## ____NNNNYYYY
+ (/.left-shift spare)
+ ## YYYY________
+ (/.logic-right-shift spare)
+ ## ________YYYY
+ (/.left-shift offset)
+ ## ____YYYY____
+ )
+ (/.and (/.region size offset) pattern)))))
))))
(def: sub
diff --git a/stdlib/source/test/lux/data/number/int.lux b/stdlib/source/test/lux/data/number/int.lux
index 680def4f5..31b732b88 100644
--- a/stdlib/source/test/lux/data/number/int.lux
+++ b/stdlib/source/test/lux/data/number/int.lux
@@ -1,6 +1,5 @@
(.module:
[lux #*
- ["%" data/text/format (#+ format)]
["_" test (#+ Test)]
[abstract
[monad (#+ do)]
@@ -12,38 +11,160 @@
["$." 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.int)
- ($order.spec /.order r.int)
- ($enum.spec /.enum r.int)
- ($interval.spec /.interval r.int)
- (~~ (template [<monoid>]
- [(<| (_.context (%.name (name-of <monoid>)))
- ($monoid.spec /.equivalence <monoid> r.int))]
+ (`` ($_ _.and
+ (_.with-cover [/.equivalence /.=]
+ ($equivalence.spec /.equivalence random.int))
+ (_.with-cover [/.order /.<]
+ ($order.spec /.order random.int))
+ (_.with-cover [/.enum]
+ ($enum.spec /.enum random.int))
+ (_.with-cover [/.interval]
+ ($interval.spec /.interval random.int))
+ (~~ (template [<compose> <monoid>]
+ [(_.with-cover [<monoid> <compose>]
+ ($monoid.spec /.equivalence <monoid> random.int))]
+
+ [/.+ /.addition]
+ [/.* /.multiplication]
+
+ [/.min /.minimum]
+ [/.max /.maximum]
+ ))
+ (~~ (template [<codec>]
+ [(_.with-cover [<codec>]
+ ($codec.spec /.equivalence <codec> random.int))]
- [/.addition] [/.multiplication] [/.minimum] [/.maximum]
- ))
- (~~ (template [<codec>]
- [(<| (_.context (%.name (name-of /.binary)))
- ($codec.spec /.equivalence <codec> r.int))]
+ [/.binary] [/.octal] [/.decimal] [/.hex]
+ ))
+ )))
+
+(def: predicate
+ Test
+ (do {! random.monad}
+ [sample random.int
+ shift (\ ! map /.abs random.int)]
+ ($_ _.and
+ (_.cover [/.negative?]
+ (bit\= (/.negative? sample)
+ (/.< +0 sample)))
+ (_.cover [/.positive?]
+ (bit\= (/.positive? sample)
+ (/.> +0 sample)))
+ (_.cover [/.zero?]
+ (bit\= (/.zero? sample)
+ (/.= +0 sample)))
+ (_.cover [/.even? /.odd?]
+ (bit\= (/.even? sample)
+ (not (/.odd? sample))))
+ )))
+
+(def: #export test
+ Test
+ (<| (_.covering /._)
+ (_.with-cover [.Int])
+ ($_ _.and
+ (do random.monad
+ [sample random.int]
+ ($_ _.and
+ (_.cover [/.-]
+ (and (/.= +0 (/.- sample sample))
+ (/.= sample (/.- +0 sample))
+ (/.= (/.negate sample)
+ (/.- sample +0))))
+ (_.cover [/./]
+ (and (/.= +1 (/./ sample sample))
+ (/.= sample (/./ +1 sample))))
+ (_.cover [/.abs]
+ (bit\= (/.> sample (/.abs sample))
+ (/.negative? sample)))
+ (_.cover [/.signum]
+ (/.= (/.abs sample)
+ (/.* (/.signum sample) sample)))
+ ))
+ (do random.monad
+ [left random.int
+ right random.int]
+ ($_ _.and
+ (_.cover [/.>]
+ (bit\= (/.> left right)
+ (/.< right left)))
+ (_.cover [/.<= /.>=]
+ (bit\= (/.<= left right)
+ (/.>= right left)))
+ ))
+ (do random.monad
+ [left (random.filter (|>> (/.= +0) not)
+ random.int)
+ right random.int]
+ ($_ _.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)))))
+ (_.cover [/.mod]
+ (and (/.= (/.signum left)
+ (/.signum (/.mod left right)))
+ (/.= (/.signum right)
+ (/.signum (/.% left right)))
+ (if (/.= (/.signum left) (/.signum right))
+ (/.= (/.% left right)
+ (/.mod left right))
+ (or (and (/.= +0 (/.% left right))
+ (/.= +0 (/.mod left right)))
+ (/.= (/.+ left (/.% left right))
+ (/.mod left right))))))
+ ))
+ (do {! random.monad}
+ [#let [random (\ ! map (/.% +1,000) random.int)]
+ 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 random.int]
+ (_.cover [/.negate]
+ (let [subtraction!
+ (/.= +0 (/.+ (/.negate expected) expected))
- [/.binary] [/.octal] [/.decimal] [/.hex]
- ))
+ inverse!
+ (|> expected /.negate /.negate (/.= expected))]
+ (and subtraction!
+ inverse!))))
+ (do {! random.monad}
+ [expected (\ ! map (/.% +1,000,000) random.int)]
+ (_.cover [/.frac]
+ (|> expected /.frac f.int (/.= expected))))
+ (do random.monad
+ [sample random.int]
+ (_.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
+ )))