aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/data/collection/set.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/test/lux/data/collection/set.lux')
-rw-r--r--stdlib/source/test/lux/data/collection/set.lux111
1 files changed, 59 insertions, 52 deletions
diff --git a/stdlib/source/test/lux/data/collection/set.lux b/stdlib/source/test/lux/data/collection/set.lux
index b383f32c2..f319af295 100644
--- a/stdlib/source/test/lux/data/collection/set.lux
+++ b/stdlib/source/test/lux/data/collection/set.lux
@@ -1,67 +1,74 @@
(.module:
[lux #*
+ data/text/format
+ ["_" test (#+ Test)]
[control
- [monad (#+ do Monad)]]
+ [monad (#+ do)]
+ {[0 #test]
+ [/
+ ["$." equivalence]
+ ["$." monoid]]}]
[data
- ["." number]
+ [number
+ ["." nat]]
[collection
- ["&" set (#+ Set)]
["." list]]]
[math
["r" random]]]
- lux/test)
+ {1
+ ["." /]})
(def: gen-nat
(r.Random Nat)
(|> r.nat
(:: r.monad map (n/% 100))))
-(context: "Sets"
- (<| (times 100)
- (do @
- [sizeL gen-nat
- sizeR gen-nat
- setL (r.set number.hash sizeL gen-nat)
- setR (r.set number.hash sizeR gen-nat)
- non-member (|> gen-nat
- (r.filter (|>> (&.member? setL) not)))
- #let [(^open "&;.") &.equivalence]]
- ($_ seq
- (test "I can query the size of a set."
- (and (n/= sizeL (&.size setL))
- (n/= sizeR (&.size setR))))
+(def: #export test
+ Test
+ (<| (_.context (%name (name-of /.Set)))
+ (do r.monad
+ [size gen-nat]
+ ($_ _.and
+ ($equivalence.spec /.equivalence (r.set nat.hash size r.nat))
+ ($monoid.spec /.equivalence (/.monoid nat.hash) (r.set nat.hash size r.nat))
- (test "Converting sets to/from lists can't change their values."
- (|> setL
- &.to-list (&.from-list number.hash)
- (&;= setL)))
-
- (test "Every set is a sub-set of the union of itself with another."
- (let [setLR (&.union setL setR)]
- (and (&.sub? setLR setL)
- (&.sub? setLR setR))))
-
- (test "Every set is a super-set of the intersection of itself with another."
- (let [setLR (&.intersection setL setR)]
- (and (&.super? setLR setL)
- (&.super? setLR setR))))
-
- (test "Union with the empty set leaves a set unchanged."
- (&;= setL
- (&.union (&.new number.hash)
- setL)))
-
- (test "Intersection with the empty set results in the empty set."
- (let [empty-set (&.new number.hash)]
- (&;= empty-set
- (&.intersection empty-set setL))))
-
- (test "After substracting a set A from another B, no member of A can be a member of B."
- (let [sub (&.difference setR setL)]
- (not (list.any? (&.member? sub) (&.to-list setR)))))
-
- (test "Every member of a set must be identifiable."
- (and (not (&.member? setL non-member))
- (&.member? (&.add non-member setL) non-member)
- (not (&.member? (&.remove non-member (&.add non-member setL)) non-member))))
- ))))
+ (do r.monad
+ [sizeL gen-nat
+ sizeR gen-nat
+ setL (r.set nat.hash sizeL gen-nat)
+ setR (r.set nat.hash sizeR gen-nat)
+ non-member (|> gen-nat
+ (r.filter (|>> (/.member? setL) not)))
+ #let [(^open "/@.") /.equivalence]]
+ ($_ _.and
+ (_.test "I can query the size of a set."
+ (and (n/= sizeL (/.size setL))
+ (n/= sizeR (/.size setR))))
+ (_.test "Converting sets to/from lists can't change their values."
+ (|> setL
+ /.to-list (/.from-list nat.hash)
+ (/@= setL)))
+ (_.test "Every set is a sub-set of the union of itself with another."
+ (let [setLR (/.union setL setR)]
+ (and (/.sub? setLR setL)
+ (/.sub? setLR setR))))
+ (_.test "Every set is a super-set of the intersection of itself with another."
+ (let [setLR (/.intersection setL setR)]
+ (and (/.super? setLR setL)
+ (/.super? setLR setR))))
+ (_.test "Union with the empty set leaves a set unchanged."
+ (/@= setL
+ (/.union (/.new nat.hash)
+ setL)))
+ (_.test "Intersection with the empty set results in the empty set."
+ (let [empty-set (/.new nat.hash)]
+ (/@= empty-set
+ (/.intersection empty-set setL))))
+ (_.test "After substracting a set A from another B, no member of A can be a member of B."
+ (let [sub (/.difference setR setL)]
+ (not (list.any? (/.member? sub) (/.to-list setR)))))
+ (_.test "Every member of a set must be identifiable."
+ (and (not (/.member? setL non-member))
+ (/.member? (/.add non-member setL) non-member)
+ (not (/.member? (/.remove non-member (/.add non-member setL)) non-member))))
+ ))))))