diff options
author | Eduardo Julian | 2017-12-31 00:51:30 -0400 |
---|---|---|
committer | Eduardo Julian | 2017-12-31 00:51:30 -0400 |
commit | 8f071917892ac919b91da12c2bf02d5d9b79f81a (patch) | |
tree | 8e5db500499241f6637cb1c5877314d4405390f6 /stdlib/test | |
parent | 59d674d660b4e52ec54ef046024b850b4eeb7a0f (diff) |
- Added bit-sets.
Diffstat (limited to 'stdlib/test')
-rw-r--r-- | stdlib/test/test/lux/control/eq.lux | 13 | ||||
-rw-r--r-- | stdlib/test/test/lux/control/pipe.lux | 3 | ||||
-rw-r--r-- | stdlib/test/test/lux/data/coll/bits.lux | 80 | ||||
-rw-r--r-- | stdlib/test/tests.lux | 3 |
4 files changed, 97 insertions, 2 deletions
diff --git a/stdlib/test/test/lux/control/eq.lux b/stdlib/test/test/lux/control/eq.lux new file mode 100644 index 000000000..9d33d4693 --- /dev/null +++ b/stdlib/test/test/lux/control/eq.lux @@ -0,0 +1,13 @@ +(.module: + lux + (lux (control ["/" eq] + [monad #+ do]) + (math ["r" random]) + test)) + +(def: #export (spec Eq<a> gen<a>) + (All [a] (-> (/.Eq a) (r.Random a) Test)) + (do r.Monad<Random> + [sample gen<a>] + (test "Equality is reflexive." + (:: Eq<a> = sample sample)))) diff --git a/stdlib/test/test/lux/control/pipe.lux b/stdlib/test/test/lux/control/pipe.lux index 545640030..79e920468 100644 --- a/stdlib/test/test/lux/control/pipe.lux +++ b/stdlib/test/test/lux/control/pipe.lux @@ -33,7 +33,8 @@ (i/= 15)) (|> 4 (cond> [i/even?] [(i/* 2)] - [i/odd?] [(i/* 3)]) + [i/odd?] [(i/* 3)] + []) (i/= 8)) (|> 5 (cond> [i/even?] [(i/* 2)] diff --git a/stdlib/test/test/lux/data/coll/bits.lux b/stdlib/test/test/lux/data/coll/bits.lux new file mode 100644 index 000000000..ccf0ff63d --- /dev/null +++ b/stdlib/test/test/lux/data/coll/bits.lux @@ -0,0 +1,80 @@ +(.module: + lux + (lux (control [monad #+ do] + [predicate]) + (data (coll ["/" bits])) + ["r" math/random]) + lux/test + (test (lux (control ["_." eq])))) + +(def: (size min max) + (-> Nat Nat (r.Random Nat)) + (|> r.nat + (:: r.Monad<Random> map (|>> (n/% max) (n/max min))))) + +(def: bits + (r.Random /.Bits) + (do r.Monad<Random> + [size (size +1 +1_000) + idx (|> r.nat (:: @ map (n/% size)))] + (wrap (|> /.empty (/.set idx))))) + +(context: "Bits." + (<| (times +100) + (do @ + [size (size +1 +1_000) + idx (|> r.nat (:: @ map (n/% size))) + sample bits] + ($_ seq + (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.union (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 (n/inc idx) /.empty) + (/.set idx /.empty))))) + (test "Cannot intersect with one's opposite." + (not (/.intersects? sample (/.not sample)))) + + (test "'and' with oneself changes nothing" + (:: /.Eq<Bits> = 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." + (:: /.Eq<Bits> = sample (/.not (/.not sample)))) + (test "Negation does not affect the empty bit-set." + (is /.empty (/.not /.empty))) + + (_eq.spec /.Eq<Bits> ..bits) + )))) diff --git a/stdlib/test/tests.lux b/stdlib/test/tests.lux index e234b6b48..ecce3d56b 100644 --- a/stdlib/test/tests.lux +++ b/stdlib/test/tests.lux @@ -39,6 +39,7 @@ (format ["_." json] ["_." xml]) (coll ["_." array] + ["_." bits] ["_." dict] ["_." list] ["_." queue] @@ -66,7 +67,7 @@ ["poly_." functor])) (type ["_." implicit] ["_." object]) - (lang ["lang_." syntax] + (lang ["lang/_." syntax] ["_." type] (type ["_." check])) (world ["_." blob] |