aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/data
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/test/lux/data')
-rw-r--r--stdlib/source/test/lux/data/binary.lux8
-rw-r--r--stdlib/source/test/lux/data/collection/bits.lux128
2 files changed, 73 insertions, 63 deletions
diff --git a/stdlib/source/test/lux/data/binary.lux b/stdlib/source/test/lux/data/binary.lux
index 17f773206..c011df720 100644
--- a/stdlib/source/test/lux/data/binary.lux
+++ b/stdlib/source/test/lux/data/binary.lux
@@ -31,7 +31,7 @@
(#try.Success output)
output))
-(def: #export (binary size)
+(def: #export (random size)
(-> Nat (Random Binary))
(let [output (/.create size)]
(loop [idx 0]
@@ -80,7 +80,7 @@
(do {@ random.monad}
[#let [gen-size (|> random.nat (:: @ map (|>> (n.% 100) (n.max 8))))]
size gen-size
- sample (..binary size)
+ sample (..random size)
value random.nat
#let [gen-idx (|> random.nat (:: @ map (n.% size)))]
[from to] (random.and gen-idx gen-idx)
@@ -88,9 +88,9 @@
(_.with-cover [/.Binary]
($_ _.and
(_.with-cover [/.equivalence]
- ($equivalence.spec /.equivalence (..binary size)))
+ ($equivalence.spec /.equivalence (..random size)))
(_.with-cover [/.monoid]
- ($monoid.spec /.equivalence /.monoid (..binary size)))
+ ($monoid.spec /.equivalence /.monoid (..random size)))
(_.cover [/.fold]
(n.= (:: list.fold fold n.+ 0 (..as-list sample))
(/.fold n.+ 0 sample)))
diff --git a/stdlib/source/test/lux/data/collection/bits.lux b/stdlib/source/test/lux/data/collection/bits.lux
index 59d7e3443..166ced163 100644
--- a/stdlib/source/test/lux/data/collection/bits.lux
+++ b/stdlib/source/test/lux/data/collection/bits.lux
@@ -1,6 +1,5 @@
(.module:
[lux #*
- ["%" data/text/format (#+ format)]
["_" test (#+ Test)]
[abstract
[monad (#+ do)]
@@ -12,74 +11,85 @@
[number
["n" nat]]]
[math
- ["r" random (#+ Random)]]]
+ ["." random (#+ Random)]]]
{1
["." / (#+ Bits)]})
(def: (size min max)
(-> Nat Nat (Random Nat))
- (|> r.nat
- (:: r.monad map (|>> (n.% max) (n.max min)))))
+ (|> random.nat
+ (:: random.monad map (|>> (n.% (inc max)) (n.max min)))))
-(def: #export bits
+(def: #export random
(Random Bits)
- (do {@ r.monad}
- [size (size 1 1,000)
- idx (|> r.nat (:: @ map (n.% size)))]
- (wrap (|> /.empty (/.set idx)))))
+ (do {@ random.monad}
+ [size (:: @ map (n.% 1,000) random.nat)]
+ (case size
+ 0 (wrap /.empty)
+ _ (do {@ random.monad}
+ [idx (|> random.nat (:: @ map (n.% size)))]
+ (wrap (/.set idx /.empty))))))
(def: #export test
Test
- (<| (_.context (%.name (name-of /._)))
+ (<| (_.covering /._)
+ (_.with-cover [/.Bits])
($_ _.and
- ($equivalence.spec /.equivalence ..bits)
- (do {@ r.monad}
- [size (size 1 1,000)
- idx (|> r.nat (:: @ map (n.% size)))
- sample bits]
+ (_.with-cover [/.equivalence]
+ ($equivalence.spec /.equivalence ..random))
+
+ (do random.monad
+ [sample ..random]
+ (_.cover [/.empty? /.size]
+ (if (/.empty? sample)
+ (n.= 0 (/.size sample))
+ (n.> 0 (/.size sample)))))
+ (_.cover [/.empty]
+ (/.empty? /.empty))
+
+ (do {@ random.monad}
+ [size (:: @ map (|>> (n.% 1,000) inc) random.nat)
+ idx (:: @ map (n.% size) random.nat)
+ sample ..random]
($_ _.and
- (_.test "Can set individual bits."
- (and (|> /.empty (/.get idx) not)
- (|> /.empty (/.set idx) (/.get idx))))
- (_.test "Can clear individual bits."
- (|> /.empty (/.set idx) (/.clear idx) (/.get idx) not))
- (_.test "Can flip individual bits."
- (and (|> /.empty (/.flip idx) (/.get idx))
- (|> /.empty (/.flip idx) (/.flip idx) (/.get idx) not)))
- (_.test "Bits (only) grow when (and as much as) necessary."
- (and (n.= 0 (/.capacity /.empty))
- (|> /.empty (/.set idx) /.capacity
- (n.- idx)
- (predicate.unite (n.>= 0)
- (n.< /.chunk-size)))))
- (_.test "Bits (must) shrink when (and as much as) possible."
- (let [grown (/.flip idx /.empty)]
- (and (n.> 0 (/.capacity grown))
- (is? /.empty (/.flip idx grown)))))
- (_.test "Intersection can be detected when there are set bits in common."
- (and (not (/.intersects? /.empty
- /.empty))
- (/.intersects? (/.set idx /.empty)
- (/.set idx /.empty))
- (not (/.intersects? (/.set (inc idx) /.empty)
- (/.set idx /.empty)))))
- (_.test "Cannot intersect with one's opposite."
- (not (/.intersects? sample (/.not sample))))
- (_.test "'and' with oneself changes nothing"
- (:: /.equivalence = sample (/.and sample sample)))
- (_.test "'and' with one's opposite yields the empty bit-set."
- (is? /.empty (/.and sample (/.not sample))))
-
- (_.test "'or' with one's opposite fully saturates a bit-set."
- (n.= (/.size (/.or sample (/.not sample)))
- (/.capacity sample)))
- (_.test "'xor' with oneself yields the empty bit-set."
- (is? /.empty (/.xor sample sample)))
- (_.test "'xor' with one's opposite fully saturates a bit-set."
- (n.= (/.size (/.xor sample (/.not sample)))
- (/.capacity sample)))
- (_.test "Double negation results in original bit-set."
- (:: /.equivalence = sample (/.not (/.not sample))))
- (_.test "Negation does not affect the empty bit-set."
- (is? /.empty (/.not /.empty)))
+ (_.cover [/.get /.set]
+ (and (|> /.empty (/.get idx) not)
+ (|> /.empty (/.set idx) (/.get idx))))
+ (_.cover [/.clear]
+ (|> /.empty (/.set idx) (/.clear idx) (/.get idx) not))
+ (_.cover [/.flip]
+ (and (|> /.empty (/.flip idx) (/.get idx))
+ (|> /.empty (/.flip idx) (/.flip idx) (/.get idx) not)))
+ (_.cover [/.Chunk /.capacity /.chunk-size]
+ (and (n.= 0 (/.capacity /.empty))
+ (|> /.empty (/.set idx) /.capacity
+ (n.- idx)
+ (predicate.unite (n.>= 0)
+ (n.< /.chunk-size)))
+ (let [grown (/.flip idx /.empty)]
+ (and (n.> 0 (/.capacity grown))
+ (is? /.empty (/.flip idx grown))))))
+ (_.cover [/.intersects?]
+ (and (not (/.intersects? /.empty
+ /.empty))
+ (/.intersects? (/.set idx /.empty)
+ (/.set idx /.empty))
+ (not (/.intersects? (/.set (inc idx) /.empty)
+ (/.set idx /.empty)))
+ (not (/.intersects? sample (/.not sample)))))
+ (_.cover [/.not]
+ (and (not (:: /.equivalence = sample (/.not sample)))
+ (:: /.equivalence = sample (/.not (/.not sample)))
+ (is? /.empty (/.not /.empty))))
+ (_.cover [/.xor]
+ (and (is? /.empty (/.xor sample sample))
+ (n.= (/.size (/.xor sample (/.not sample)))
+ (/.capacity sample))))
+ (_.cover [/.or]
+ (and (:: /.equivalence = sample (/.or sample sample))
+ (n.= (/.size (/.or sample (/.not sample)))
+ (/.capacity sample))))
+ (_.cover [/.and]
+ (and (:: /.equivalence = sample (/.and sample sample))
+ (is? /.empty (/.and sample (/.not sample)))))
)))))