From 677ae72669dabcad59262287aa4d84c5631bbddd Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Tue, 1 May 2018 21:32:29 -0400 Subject: - Re-organized set modules. --- stdlib/test/test/lux/control/interval.lux | 4 +- stdlib/test/test/lux/data/coll/ordered/dict.lux | 2 +- stdlib/test/test/lux/data/coll/ordered/set.lux | 94 ------------------------ stdlib/test/test/lux/data/coll/set.lux | 64 ---------------- stdlib/test/test/lux/data/coll/set/ordered.lux | 94 ++++++++++++++++++++++++ stdlib/test/test/lux/data/coll/set/unordered.lux | 64 ++++++++++++++++ stdlib/test/test/lux/lang/type/check.lux | 2 +- stdlib/test/test/lux/math/logic/fuzzy.lux | 2 +- stdlib/test/test/lux/math/random.lux | 2 +- stdlib/test/tests.lux | 6 +- 10 files changed, 167 insertions(+), 167 deletions(-) delete mode 100644 stdlib/test/test/lux/data/coll/ordered/set.lux delete mode 100644 stdlib/test/test/lux/data/coll/set.lux create mode 100644 stdlib/test/test/lux/data/coll/set/ordered.lux create mode 100644 stdlib/test/test/lux/data/coll/set/unordered.lux (limited to 'stdlib/test') diff --git a/stdlib/test/test/lux/control/interval.lux b/stdlib/test/test/lux/control/interval.lux index 05566f464..3187c0b7b 100644 --- a/stdlib/test/test/lux/control/interval.lux +++ b/stdlib/test/test/lux/control/interval.lux @@ -8,8 +8,8 @@ ["r" math/random] (data text/format [number] - ["S" coll/set] - ["L" coll/list]))) + (coll ["S" set/unordered] + ["L" list])))) (context: "Equality." (<| (times +100) diff --git a/stdlib/test/test/lux/data/coll/ordered/dict.lux b/stdlib/test/test/lux/data/coll/ordered/dict.lux index 975b26dd2..301e64927 100644 --- a/stdlib/test/test/lux/data/coll/ordered/dict.lux +++ b/stdlib/test/test/lux/data/coll/ordered/dict.lux @@ -6,7 +6,7 @@ (data [product] [number] (coll (ordered ["&" dict]) - ["s" set] + (set ["s" unordered]) ["d" dict] [list "L/" Functor])) ["r" math/random]) diff --git a/stdlib/test/test/lux/data/coll/ordered/set.lux b/stdlib/test/test/lux/data/coll/ordered/set.lux deleted file mode 100644 index 123613972..000000000 --- a/stdlib/test/test/lux/data/coll/ordered/set.lux +++ /dev/null @@ -1,94 +0,0 @@ -(.module: - lux - (lux [io] - (control [monad #+ do Monad]) - (data (coll (ordered ["&" set]) - ["s" set] - [list "" Fold]) - [number] - text/format) - ["r" math/random]) - lux/test) - -(def: gen-nat - (r.Random Nat) - (|> r.nat - (:: r.Monad map (n/% +100)))) - -(context: "Sets" - (<| (times +100) - (do @ - [sizeL gen-nat - sizeR gen-nat - listL (|> (r.set number.Hash sizeL gen-nat) (:: @ map s.to-list)) - listR (|> (r.set number.Hash sizeR gen-nat) (:: @ map s.to-list)) - #let [(^open "&/") &.Eq - setL (&.from-list number.Order listL) - setR (&.from-list number.Order listR) - sortedL (list.sort n/< listL) - minL (list.head sortedL) - maxL (list.last sortedL)]] - ($_ seq - (test "I can query the size of a set." - (n/= sizeL (&.size setL))) - - (test "Can query minimum value." - (case [(&.min setL) minL] - [#.None #.None] - true - - [(#.Some reference) (#.Some sample)] - (n/= reference sample) - - _ - false)) - - (test "Can query maximum value." - (case [(&.max setL) maxL] - [#.None #.None] - true - - [(#.Some reference) (#.Some sample)] - (n/= reference sample) - - _ - false)) - - (test "Converting sets to/from lists can't change their values." - (|> setL - &.to-list (&.from-list number.Order) - (&/= setL))) - - (test "Order is preserved." - (let [listL (&.to-list setL) - (^open "L/") (list.Eq number.Eq)] - (L/= listL - (list.sort n/< listL)))) - - (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.Order) - setL))) - - (test "Intersection with the empty set results in the empty set." - (let [empty-set (&.new number.Order)] - (&/= 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." - (list.every? (&.member? setL) (&.to-list setL))) - )))) diff --git a/stdlib/test/test/lux/data/coll/set.lux b/stdlib/test/test/lux/data/coll/set.lux deleted file mode 100644 index eb43bd0d2..000000000 --- a/stdlib/test/test/lux/data/coll/set.lux +++ /dev/null @@ -1,64 +0,0 @@ -(.module: - lux - (lux [io] - (control [monad #+ do Monad]) - (data (coll ["&" set] - [list "" Fold]) - [number]) - ["r" math/random]) - lux/test) - -(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 "&/") &.Eq]] - ($_ seq - (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 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)))) - )))) diff --git a/stdlib/test/test/lux/data/coll/set/ordered.lux b/stdlib/test/test/lux/data/coll/set/ordered.lux new file mode 100644 index 000000000..cb78ad963 --- /dev/null +++ b/stdlib/test/test/lux/data/coll/set/ordered.lux @@ -0,0 +1,94 @@ +(.module: + lux + (lux [io] + (control [monad #+ do Monad]) + (data (coll (set ["s" unordered] + ["&" ordered]) + [list "" Fold]) + [number] + text/format) + ["r" math/random]) + lux/test) + +(def: gen-nat + (r.Random Nat) + (|> r.nat + (:: r.Monad map (n/% +100)))) + +(context: "Sets" + (<| (times +100) + (do @ + [sizeL gen-nat + sizeR gen-nat + listL (|> (r.set number.Hash sizeL gen-nat) (:: @ map s.to-list)) + listR (|> (r.set number.Hash sizeR gen-nat) (:: @ map s.to-list)) + #let [(^open "&/") &.Eq + setL (&.from-list number.Order listL) + setR (&.from-list number.Order listR) + sortedL (list.sort n/< listL) + minL (list.head sortedL) + maxL (list.last sortedL)]] + ($_ seq + (test "I can query the size of a set." + (n/= sizeL (&.size setL))) + + (test "Can query minimum value." + (case [(&.min setL) minL] + [#.None #.None] + true + + [(#.Some reference) (#.Some sample)] + (n/= reference sample) + + _ + false)) + + (test "Can query maximum value." + (case [(&.max setL) maxL] + [#.None #.None] + true + + [(#.Some reference) (#.Some sample)] + (n/= reference sample) + + _ + false)) + + (test "Converting sets to/from lists can't change their values." + (|> setL + &.to-list (&.from-list number.Order) + (&/= setL))) + + (test "Order is preserved." + (let [listL (&.to-list setL) + (^open "L/") (list.Eq number.Eq)] + (L/= listL + (list.sort n/< listL)))) + + (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.Order) + setL))) + + (test "Intersection with the empty set results in the empty set." + (let [empty-set (&.new number.Order)] + (&/= 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." + (list.every? (&.member? setL) (&.to-list setL))) + )))) diff --git a/stdlib/test/test/lux/data/coll/set/unordered.lux b/stdlib/test/test/lux/data/coll/set/unordered.lux new file mode 100644 index 000000000..bdb896e8b --- /dev/null +++ b/stdlib/test/test/lux/data/coll/set/unordered.lux @@ -0,0 +1,64 @@ +(.module: + lux + (lux [io] + (control [monad #+ do Monad]) + (data (coll (set ["&" unordered #+ Set]) + [list "" Fold]) + [number]) + ["r" math/random]) + lux/test) + +(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 "&/") &.Eq]] + ($_ seq + (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 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)))) + )))) diff --git a/stdlib/test/test/lux/lang/type/check.lux b/stdlib/test/test/lux/lang/type/check.lux index dd42ceaf4..48a3f35cb 100644 --- a/stdlib/test/test/lux/lang/type/check.lux +++ b/stdlib/test/test/lux/lang/type/check.lux @@ -9,7 +9,7 @@ [text "text/" Monoid Eq] text/format (coll [list "list/" Functor] - [set])) + (set ["set" unordered]))) ["r" math/random] (lang [type "type/" Eq] ["@" type/check])) diff --git a/stdlib/test/test/lux/math/logic/fuzzy.lux b/stdlib/test/test/lux/math/logic/fuzzy.lux index a1c01408c..068e00523 100644 --- a/stdlib/test/test/lux/math/logic/fuzzy.lux +++ b/stdlib/test/test/lux/math/logic/fuzzy.lux @@ -3,7 +3,7 @@ (lux [io] (control [monad #+ do Monad]) (data (coll [list] - [set]) + (set ["set" unordered])) [bool "B/" Eq] [number] text/format) diff --git a/stdlib/test/test/lux/math/random.lux b/stdlib/test/test/lux/math/random.lux index b5e305ff7..eed882ea7 100644 --- a/stdlib/test/test/lux/math/random.lux +++ b/stdlib/test/test/lux/math/random.lux @@ -9,7 +9,7 @@ [array] [queue] [stack] - [set] + (set ["set" unordered]) [dict])) (math ["r" random])) lux/test) diff --git a/stdlib/test/tests.lux b/stdlib/test/tests.lux index 05118f921..9739c63e5 100644 --- a/stdlib/test/tests.lux +++ b/stdlib/test/tests.lux @@ -46,15 +46,15 @@ ["_." dict] ["_." list] ["_." queue] - ["_." set] + ["_." set/unordered] + ["_." set/ordered] ["_." stack] ["_." sequence] ["_." priority-queue] ["_." stream] (tree ["tree_." rose] ["tree_." zipper]) - (ordered ["ordered_." dict] - ["ordered_." set])) + (ordered ["ordered_." dict])) (text ["_." format] ["_." lexer] ["_." regex])) -- cgit v1.2.3