diff options
Diffstat (limited to 'stdlib/source/test')
19 files changed, 443 insertions, 289 deletions
diff --git a/stdlib/source/test/aedifex.lux b/stdlib/source/test/aedifex.lux index eebccdf09..3833c0828 100644 --- a/stdlib/source/test/aedifex.lux +++ b/stdlib/source/test/aedifex.lux @@ -19,7 +19,6 @@ ["#/." test] ["#/." auto]] ["#." local] - ["#." cache] ["#." dependency ["#/." resolution] ["#/." status]] @@ -49,7 +48,6 @@ /command/test.test /command/auto.test /local.test - /cache.test /dependency.test /dependency/resolution.test /dependency/status.test diff --git a/stdlib/source/test/aedifex/artifact.lux b/stdlib/source/test/aedifex/artifact.lux index fc8bb2dae..5c694ae74 100644 --- a/stdlib/source/test/aedifex/artifact.lux +++ b/stdlib/source/test/aedifex/artifact.lux @@ -39,15 +39,6 @@ ($_ _.and (_.for [/.equivalence] ($equivalence.spec /.equivalence ..random)) - - (do random.monad - [sample ..random - #let [fs (: (file.System Promise) - (file.mock (\ file.default separator)))]] - (_.cover [/.uri /.path] - (|> (/.path fs sample) - (text.replace_all uri.separator (\ fs separator)) - (text\= (/.uri sample))))) /type.test /extension.test diff --git a/stdlib/source/test/aedifex/command/deploy.lux b/stdlib/source/test/aedifex/command/deploy.lux index 45d39cffc..617b3386a 100644 --- a/stdlib/source/test/aedifex/command/deploy.lux +++ b/stdlib/source/test/aedifex/command/deploy.lux @@ -75,15 +75,11 @@ (-> (Program Promise) (Repository Promise) (file.System Promise) Artifact ///.Profile (Promise (Try Text))) - (do promise.monad - [home (\ program home [])] - (do ///action.monad - [#let [console (@version.echo "")] - _ (..make_sources! fs (get@ #///.sources profile)) - _ (: (Promise (Try Path)) - (file.make_directories promise.monad fs (///local.repository fs home))) - _ (/.do! console repository fs artifact profile)] - (!.use (\ console read_line) [])))) + (do ///action.monad + [#let [console (@version.echo "")] + _ (..make_sources! fs (get@ #///.sources profile)) + _ (/.do! console repository fs artifact profile)] + (!.use (\ console read_line) []))) (def: #export test Test diff --git a/stdlib/source/test/aedifex/command/deps.lux b/stdlib/source/test/aedifex/command/deps.lux index 08345a0cb..99856c83c 100644 --- a/stdlib/source/test/aedifex/command/deps.lux +++ b/stdlib/source/test/aedifex/command/deps.lux @@ -39,14 +39,15 @@ ["#." action] ["#." pom] ["#." package] - ["#." cache] ["#." artifact ["#/." type]] ["#." dependency ["#/." resolution] + ["#/." deployment] ["#/." status]] ["#." repository - ["#/." origin]]]]]}) + ["#/." origin] + ["#/." local]]]]]}) (def: #export test Test @@ -89,13 +90,14 @@ program (program.async (program.mock environment.empty home working_directory))]] (wrap (do promise.monad [verdict (do ///action.monad - [#let [console (@version.echo "")] + [#let [console (@version.echo "") + local (///repository/local.repository program fs)] pre (|> ///dependency/resolution.empty (dictionary.put dependee dependee_package) - (///cache.write_all program fs)) + (///dependency/deployment.all local)) post (|> (\ ///.monoid identity) (set@ #///.dependencies (set.from_list ///dependency.hash (list dependee depender))) - (/.do! program console fs (list (///repository.mock ($///dependency/resolution.single depender_artifact depender_package) [])))) + (/.do! console local (list (///repository.mock ($///dependency/resolution.single depender_artifact depender_package) [])))) logging! (\ ///action.monad map (text\= //clean.success) (!.use (\ console read_line) []))] diff --git a/stdlib/source/test/aedifex/command/install.lux b/stdlib/source/test/aedifex/command/install.lux index 9df49efa4..ce3f21de8 100644 --- a/stdlib/source/test/aedifex/command/install.lux +++ b/stdlib/source/test/aedifex/command/install.lux @@ -26,7 +26,9 @@ ["." random (#+ Random)]] [world ["." file (#+ Path File)] - ["." program (#+ Program)]]] + ["." program (#+ Program)] + [net + ["." uri]]]] [// ["@." version] [// @@ -42,7 +44,9 @@ ["#." pom] ["#." local] ["#." artifact - ["#/." extension]]]]]}) + ["#/." extension]] + ["#." repository #_ + ["#/." local]]]]]}) (def: (make_sources! fs sources) (-> (file.System Promise) (Set Path) (Promise (Try Any))) @@ -68,9 +72,7 @@ (do ///action.monad [#let [console (@version.echo "")] _ (..make_sources! fs (get@ #///.sources sample)) - _ (: (Promise (Try Path)) - (file.make_directories promise.monad fs (///local.repository fs home))) - _ (/.do! program console fs sample)] + _ (/.do! console fs (///repository/local.repository program fs) sample)] (!.use (\ console read_line) [])))) (def: #export test @@ -88,9 +90,8 @@ program (program.async (program.mock environment.empty home working_directory))] verdict (do ///action.monad [logging (..execute! program fs sample) - #let [artifact_path (format (///local.path fs home identity) - (\ fs separator) - (///artifact.identity identity)) + #let [/ uri.separator + artifact_path (format (///local.uri identity) / (///artifact.identity identity)) library_path (format artifact_path ///artifact/extension.lux_library) pom_path (format artifact_path ///artifact/extension.pom)] diff --git a/stdlib/source/test/aedifex/local.lux b/stdlib/source/test/aedifex/local.lux index 7d0492815..6729d4485 100644 --- a/stdlib/source/test/aedifex/local.lux +++ b/stdlib/source/test/aedifex/local.lux @@ -3,35 +3,22 @@ ["_" test (#+ Test)] [abstract [monad (#+ do)]] - [control - [concurrency - [promise (#+ Promise)]]] [data ["." text]] [math - ["." random (#+ Random)]] - [world - ["." file]]] + ["." random (#+ Random)]]] [// ["@." artifact]] {#program - ["." / - ["/#" // #_ - ["#." artifact]]]}) + ["." /]}) (def: #export test Test (<| (_.covering /._) (do {! random.monad} - [sample @artifact.random - home (random.ascii/alpha 5) - #let [fs (: (file.System Promise) - (file.mock (\ file.default separator)))]] + [sample @artifact.random] ($_ _.and - (_.cover [/.repository /.path] - (let [path (/.path fs home sample)] - (and (text.starts_with? (/.repository fs home) - path) - (text.ends_with? (//artifact.path fs sample) - path)))) + (_.cover [/.repository /.uri] + (text.starts_with? /.repository + (/.uri sample))) )))) diff --git a/stdlib/source/test/aedifex/metadata.lux b/stdlib/source/test/aedifex/metadata.lux index 0cac022f8..33104330b 100644 --- a/stdlib/source/test/aedifex/metadata.lux +++ b/stdlib/source/test/aedifex/metadata.lux @@ -19,16 +19,6 @@ Test (<| (_.covering /._) ($_ _.and - (<| (_.for [/.file]) - (do random.monad - [sample @artifact.random] - ($_ _.and - (_.cover [/.project] - (text.ends_with? /.file (/.project sample))) - (_.cover [/.version] - (text.ends_with? /.file (/.version sample))) - ))) - /artifact.test /snapshot.test ))) diff --git a/stdlib/source/test/aedifex/metadata/artifact.lux b/stdlib/source/test/aedifex/metadata/artifact.lux index 6c39546b4..9977be8e1 100644 --- a/stdlib/source/test/aedifex/metadata/artifact.lux +++ b/stdlib/source/test/aedifex/metadata/artifact.lux @@ -60,9 +60,9 @@ ($equivalence.spec /.equivalence ..random)) (do random.monad [expected ..random] - (_.cover [/.write /.parser] + (_.cover [/.format /.parser] (|> expected - /.write + /.format (<xml>.run /.parser) (try\map (\ /.equivalence = expected)) (try.default false)))) diff --git a/stdlib/source/test/aedifex/metadata/snapshot.lux b/stdlib/source/test/aedifex/metadata/snapshot.lux index c1725f55a..a2f0b65db 100644 --- a/stdlib/source/test/aedifex/metadata/snapshot.lux +++ b/stdlib/source/test/aedifex/metadata/snapshot.lux @@ -24,8 +24,8 @@ [macro ["." code]]] ["$." /// #_ - [artifact - ["#." type]]] + ["#." artifact + ["#/." type]]] {#program ["." /]}) @@ -55,15 +55,13 @@ ($_ random.and ..random_instant random.nat - (random.list 5 $///type.random) + (random.list 5 $///artifact/type.random) )) (def: #export random (Random /.Metadata) ($_ random.and - (random.ascii/alpha 5) - (random.ascii/alpha 5) - (random.ascii/alpha 5) + $///artifact.random ..random_versioning)) (def: #export test @@ -75,9 +73,9 @@ ($equivalence.spec /.equivalence ..random)) (do random.monad [expected ..random] - (_.cover [/.write /.parser] + (_.cover [/.format /.parser] (|> expected - /.write + /.format (<xml>.run /.parser) (try\map (\ /.equivalence = expected)) (try.default false)))) diff --git a/stdlib/source/test/lux.lux b/stdlib/source/test/lux.lux index 60fc409ad..d490620ff 100644 --- a/stdlib/source/test/lux.lux +++ b/stdlib/source/test/lux.lux @@ -11,17 +11,17 @@ [data ["." name] [text - ["%" format (#+ format)]] + ["%" format (#+ format)]]] + ["." math] + ["_" test (#+ Test)] + [math + ["." random (#+ Random) ("#\." functor)] [number ["." i64] ["n" nat] ["i" int] ["r" rev] - ["f" frac]]] - ["." math] - ["_" test (#+ Test)] - [math - ["." random (#+ Random) ("#\." functor)]]] + ["f" frac]]]] ## TODO: Must have 100% coverage on tests. ["." / #_ ["#." abstract] diff --git a/stdlib/source/test/lux/control/parser/analysis.lux b/stdlib/source/test/lux/control/parser/analysis.lux index 8ffc75025..756ef3d21 100644 --- a/stdlib/source/test/lux/control/parser/analysis.lux +++ b/stdlib/source/test/lux/control/parser/analysis.lux @@ -23,7 +23,8 @@ ["r" rev]]] [tool [compiler - [reference (#+ Constant)] + [reference (#+ Constant) + [variable (#+)]] [language [lux ["." analysis]]]]]] diff --git a/stdlib/source/test/lux/data/collection/array.lux b/stdlib/source/test/lux/data/collection/array.lux index 5cfbe4a7d..78c933714 100644 --- a/stdlib/source/test/lux/data/collection/array.lux +++ b/stdlib/source/test/lux/data/collection/array.lux @@ -75,7 +75,10 @@ false) [#.None #.None] - true)) + true + + _ + false)) (_.cover [/.every?] (\ bit.equivalence = (list.every? n.even? (/.to_list the_array)) diff --git a/stdlib/source/test/lux/macro/syntax/common.lux b/stdlib/source/test/lux/macro/syntax/common.lux index 90a72ca26..429b7fc6e 100644 --- a/stdlib/source/test/lux/macro/syntax/common.lux +++ b/stdlib/source/test/lux/macro/syntax/common.lux @@ -29,61 +29,22 @@ ["." /// #_ ["#." code]] ["." / #_ + ["#." annotations] ["#." check] + ["#." declaration] ["#." definition] - ["#." export] - ["#." declaration]]) - -(def: annotations_equivalence - (Equivalence /.Annotations) - (list.equivalence - (product.equivalence name.equivalence - code.equivalence))) + ["#." export]]) (def: random_text (Random Text) (random.ascii/alpha 10)) -(def: random_name - (Random Name) - (random.and ..random_text ..random_text)) - -(def: random_annotations - (Random /.Annotations) - (do {! random.monad} - [size (\ ! map (|>> (n.% 3)) random.nat)] - (random.list size (random.and random_name - ///code.random)))) - (def: #export test Test (<| (_.covering /._) (_.covering /reader._) (_.covering /writer._) ($_ _.and - (_.for [/.Annotations] - ($_ _.and - (do random.monad - [expected ..random_annotations] - (_.cover [/reader.annotations /writer.annotations] - (|> expected - /writer.annotations list - (<c>.run /reader.annotations) - (case> (#try.Success actual) - (\ ..annotations_equivalence = expected actual) - - (#try.Failure error) - false)))) - (_.cover [/.empty_annotations] - (|> /.empty_annotations - /writer.annotations list - (<c>.run /reader.annotations) - (case> (#try.Success actual) - (\ ..annotations_equivalence = /.empty_annotations actual) - - (#try.Failure error) - false))) - )) (do {! random.monad} [size (\ ! map (|>> (n.% 3)) random.nat) expected (random.list size ..random_text)] @@ -111,8 +72,9 @@ (#try.Failure error) false)))) + /annotations.test /check.test + /declaration.test /definition.test /export.test - /declaration.test ))) diff --git a/stdlib/source/test/lux/macro/syntax/common/annotations.lux b/stdlib/source/test/lux/macro/syntax/common/annotations.lux new file mode 100644 index 000000000..bc29a00f6 --- /dev/null +++ b/stdlib/source/test/lux/macro/syntax/common/annotations.lux @@ -0,0 +1,52 @@ +(.module: + [lux #* + ["_" test (#+ Test)] + [abstract + [monad (#+ do)] + {[0 #spec] + [/ + ["$." equivalence]]}] + [control + ["." try] + [parser + ["<.>" code]]] + [data + [collection + ["." list]]] + [math + ["." random (#+ Random)] + [number + ["n" nat]]]] + {1 + ["." /]} + ["$." //// #_ + ["#." code]]) + +(def: #export random + (Random /.Annotations) + (let [word (random.ascii/alpha 10) + tag (random.and word word)] + (do {! random.monad} + [size (\ ! map (n.% 10) random.nat)] + (random.list size (random.and tag $////code.random))))) + +(def: #export test + Test + (<| (_.covering /._) + (_.for [/.Annotations]) + ($_ _.and + (_.for [/.equivalence] + ($equivalence.spec /.equivalence ..random)) + + (_.cover [/.empty] + (list.empty? /.empty)) + (do random.monad + [expected ..random] + (_.cover [/.write /.parser] + (case (<code>.run /.parser + (list (/.write expected))) + (#try.Failure _) + false + + (#try.Success actual) + (\ /.equivalence = expected actual))))))) diff --git a/stdlib/source/test/lux/macro/syntax/common/definition.lux b/stdlib/source/test/lux/macro/syntax/common/definition.lux index 937f5319a..a769df641 100644 --- a/stdlib/source/test/lux/macro/syntax/common/definition.lux +++ b/stdlib/source/test/lux/macro/syntax/common/definition.lux @@ -18,26 +18,20 @@ [meta ["." location]]] {1 - ["." / - [// (#+ Annotations)]]} + ["." /]} ["$."// #_ ["#." check] + ["#." annotations] ["#//" /// #_ ["#." code]]]) -(def: random_annotations - (Random Annotations) - (let [name (random.and (random.ascii/alpha 5) - (random.ascii/alpha 5))] - (random.list 5 (random.and name $////code.random)))) - (def: #export random (Random /.Definition) ($_ random.and (random.ascii/alpha 5) (random.or $//check.random $////code.random) - ..random_annotations + $//annotations.random random.bit )) diff --git a/stdlib/source/test/lux/math/logic/fuzzy.lux b/stdlib/source/test/lux/math/logic/fuzzy.lux index 6289dd64d..58587ad95 100644 --- a/stdlib/source/test/lux/math/logic/fuzzy.lux +++ b/stdlib/source/test/lux/math/logic/fuzzy.lux @@ -1,10 +1,13 @@ (.module: [lux #* - ["%" data/text/format (#+ format)] ["_" test (#+ Test)] [abstract + [equivalence (#+ Equivalence)] [monad (#+ do)] - ["." enum]] + {[0 #spec] + [/ + [functor + ["$." contravariant]]]}] [data ["." bit ("#\." equivalence)] [collection @@ -17,169 +20,338 @@ ["r" rev]]]] {1 ["." / (#+ Fuzzy) - [// - ["//" continuous]]]}) - -(template [<name> <desc> <hash> <gen> <triangle> <lt> <lte> <gt> <gte>] - [(def: <name> - Test - (<| (_.context (%.name (name_of <triangle>))) - (do random.monad - [values (random.set <hash> 3 <gen>) - #let [[x y z] (case (set.to_list values) - (^ (list x y z)) - [x y z] - - _ - (undefined))] - sample <gen> - #let [[bottom middle top] (case (list.sort <lt> (list x y z)) - (^ (list bottom middle top)) - [bottom middle top] - - _ - (undefined)) - triangle (<triangle> x y z)]] - ($_ _.and - (_.test "The middle value will always have maximum membership." - (r.= //.true (/.membership middle triangle))) - (_.test "Boundary values will always have 0 membership." - (and (r.= //.false (/.membership bottom triangle)) - (r.= //.false (/.membership top triangle)))) - (_.test "Values within range, will have membership > 0." - (bit\= (r.> //.false (/.membership sample triangle)) - (and (<gt> bottom sample) - (<lt> top sample)))) - (_.test "Values outside of range, will have membership = 0." - (bit\= (r.= //.false (/.membership sample triangle)) - (or (<lte> bottom sample) - (<gte> top sample)))) - ))))] - - [rev_triangles "Rev" r.hash random.rev /.triangle r.< r.<= r.> r.>=] - ) - -(template [<name> <desc> <hash> <gen> <trapezoid> <lt> <lte> <gt> <gte>] - [(def: <name> - Test - (<| (_.context (%.name (name_of <trapezoid>))) - (do random.monad - [values (random.set <hash> 4 <gen>) - #let [[w x y z] (case (set.to_list values) - (^ (list w x y z)) - [w x y z] - - _ - (undefined))] - sample <gen> - #let [[bottom middle_bottom middle_top top] (case (list.sort <lt> (list w x y z)) - (^ (list bottom middle_bottom middle_top top)) - [bottom middle_bottom middle_top top] - - _ - (undefined)) - trapezoid (<trapezoid> w x y z)]] - ($_ _.and - (_.test "The middle values will always have maximum membership." - (and (r.= //.true (/.membership middle_bottom trapezoid)) - (r.= //.true (/.membership middle_top trapezoid)))) - (_.test "Boundary values will always have 0 membership." - (and (r.= //.false (/.membership bottom trapezoid)) - (r.= //.false (/.membership top trapezoid)))) - (_.test "Values within inner range will have membership = 1" - (bit\= (r.= //.true (/.membership sample trapezoid)) - (and (<gte> middle_bottom sample) - (<lte> middle_top sample)))) - (_.test "Values within range, will have membership > 0." - (bit\= (r.> //.false (/.membership sample trapezoid)) - (and (<gt> bottom sample) - (<lt> top sample)))) - (_.test "Values outside of range, will have membership = 0." - (bit\= (r.= //.false (/.membership sample trapezoid)) - (or (<lte> bottom sample) - (<gte> top sample)))) - ))))] - - [rev_trapezoids "Rev" r.hash random.rev /.trapezoid r.< r.<= r.> r.>=] - ) - -(def: #export triangle - (Random (Fuzzy Rev)) + ["/#" // #_ + ["#" continuous]]]}) + +(def: trivial + Test (do random.monad - [x random.rev - y random.rev - z random.rev] - (wrap (/.triangle x y z)))) + [sample random.rev] + ($_ _.and + (_.cover [/.empty] + (r.= //.false (/.empty sample))) + (_.cover [/.full] + (r.= //.true (/.full sample))) + ))) -(def: combinators +(def: simple Test - (<| (_.context "Combinators") - (do random.monad - [left ..triangle - right ..triangle - sample random.rev] + (do {! random.monad} + [sample random.rev + + threshold_0 (\ ! map (r.% .5) + random.rev) + threshold_1 (\ ! map (|>> (r.% .5) (r.+ .5)) + random.rev) + + #let [bottom (r.min threshold_0 threshold_1) + top (r.max threshold_0 threshold_1)]] + ($_ _.and + (_.cover [/.gradient] + (let [ascending! + (let [set (/.gradient bottom top)] + (and (r.= //.false (set bottom)) + (r.= //.true (set top)) + (let [membership (set sample)] + (cond (r.<= bottom sample) + (r.= //.false membership) + + (r.>= top sample) + (r.= //.true membership) + + (r.> //.false membership))))) + + descending! + (let [set (/.gradient top bottom)] + (and (r.= //.true (set bottom)) + (r.= //.false (set top)) + (let [membership (set sample)] + (cond (r.<= bottom sample) + (r.= //.true membership) + + (r.>= top sample) + (r.= //.false membership) + + (r.> //.false membership)))))] + (and ascending! + descending!))) + (_.cover [/.membership] + (let [set (/.gradient bottom top)] + (r.= (set sample) + (/.membership set sample)))) + ))) + +(def: composition + Test + (do {! random.monad} + [sample random.rev + + [bottom middle_bottom middle_top top] + (|> random.rev + (random.set r.hash 4) + (\ ! map (|>> set.to_list (list.sort r.<))) + (random.one (function (_ thresholds) + (case thresholds + (^ (list threshold_0 threshold_1 threshold_2 threshold_3)) + (#.Some [threshold_0 threshold_1 threshold_2 threshold_3]) + + _ + #.None)))) + + #let [bottom_set (/.gradient bottom middle_bottom) + top_set (/.gradient middle_top top)]] + ($_ _.and + (_.cover [/.union] + (let [set (/.gradient bottom top)] + (and (r.= (/.membership set sample) + (/.membership (/.union /.empty set) sample)) + (r.= (/.membership /.full sample) + (/.membership (/.union /.full set) sample)) + + (r.>= (/.membership bottom_set sample) + (/.membership (/.union bottom_set top_set) sample)) + (r.>= (/.membership top_set sample) + (/.membership (/.union bottom_set top_set) sample))))) + (_.cover [/.intersection] + (let [set (/.gradient bottom top)] + (and (r.= (/.membership /.empty sample) + (/.membership (/.intersection /.empty set) sample)) + (r.= (/.membership set sample) + (/.membership (/.intersection /.full set) sample)) + + (r.<= (/.membership bottom_set sample) + (/.membership (/.intersection bottom_set top_set) sample)) + (r.<= (/.membership top_set sample) + (/.membership (/.intersection bottom_set top_set) sample))))) + (_.cover [/.complement] + (let [set (/.gradient bottom top) + + trivial! + (and (r.= (/.membership /.full sample) + (/.membership (/.complement /.empty) sample)) + (r.= (/.membership /.empty sample) + (/.membership (/.complement /.full) sample))) + + common! + (and (r.>= (/.membership set sample) + (/.membership (/.union set (/.complement set)) sample)) + (r.<= (/.membership set sample) + (/.membership (/.intersection set (/.complement set)) sample))) + + de_morgan! + (and (r.= (/.membership (/.complement (/.union bottom_set top_set)) + sample) + (/.membership (/.intersection (/.complement bottom_set) (/.complement top_set)) + sample)) + (r.= (/.membership (/.complement (/.intersection bottom_set top_set)) + sample) + (/.membership (/.union (/.complement bottom_set) (/.complement top_set)) + sample)))] + (and trivial! + common! + de_morgan!))) + (_.cover [/.difference] + (let [set (/.gradient bottom top)] + (and (r.= (/.membership set sample) + (/.membership (/.difference /.empty set) sample)) + (r.= (/.membership /.empty sample) + (/.membership (/.difference /.full set) sample)) + + (r.<= (/.membership top_set sample) + (/.membership (/.difference bottom_set top_set) sample)) + (r.<= (/.membership bottom_set sample) + (/.membership (/.difference bottom_set top_set) sample))))) + ))) + +(def: geometric + Test + (<| (_.covering /._) + (_.for [/.Fuzzy]) + (do {! random.monad} + [sample random.rev + + [bottom middle_bottom middle_top top] + (|> random.rev + (random.set r.hash 4) + (\ ! map (|>> set.to_list (list.sort r.<))) + (random.one (function (_ thresholds) + (case thresholds + (^ (list threshold_0 threshold_1 threshold_2 threshold_3)) + (#.Some [threshold_0 threshold_1 threshold_2 threshold_3]) + + _ + #.None))))] ($_ _.and - (_.test (%.name (name_of /.union)) - (let [combined (/.union left right) - combined_membership (/.membership sample combined)] - (and (r.>= (/.membership sample left) - combined_membership) - (r.>= (/.membership sample right) - combined_membership)))) - (_.test (%.name (name_of /.intersection)) - (let [combined (/.intersection left right) - combined_membership (/.membership sample combined)] - (and (r.<= (/.membership sample left) - combined_membership) - (r.<= (/.membership sample right) - combined_membership)))) - (_.test (%.name (name_of /.complement)) - (r.= (/.membership sample left) - (//.not (/.membership sample (/.complement left))))) - (_.test (%.name (name_of /.difference)) - (r.<= (/.membership sample right) - (/.membership sample (/.difference left right)))) + (_.cover [/.triangle] + (let [reference (/.triangle bottom middle_bottom top) + + irrelevant_order! + (list.every? (function (_ set) + (r.= (/.membership reference sample) + (/.membership set sample))) + (list (/.triangle bottom top middle_bottom) + (/.triangle middle_bottom bottom top) + (/.triangle middle_bottom top bottom) + (/.triangle top bottom middle_bottom) + (/.triangle top middle_bottom bottom))) + + middle_maximum! + (r.= //.true (/.membership reference middle_bottom)) + + boundary_minima! + (and (r.= //.false (/.membership reference bottom)) + (r.= //.false (/.membership reference top))) + + inside_range! + (bit\= (r.> //.false (/.membership reference sample)) + (and (r.> bottom sample) + (r.< top sample))) + + outside_range! + (bit\= (r.= //.false (/.membership reference sample)) + (or (r.<= bottom sample) + (r.>= top sample)))] + (and irrelevant_order! + middle_maximum! + boundary_minima! + inside_range! + outside_range!))) + (_.cover [/.trapezoid] + (let [reference (/.trapezoid bottom middle_bottom middle_top top) + + irrelevant_order! + (list.every? (function (_ set) + (r.= (/.membership reference sample) + (/.membership set sample))) + (let [r0 bottom + r1 middle_bottom + r2 middle_top + r3 top] + (list (/.trapezoid r0 r1 r2 r3) + (/.trapezoid r0 r1 r3 r2) + (/.trapezoid r0 r2 r1 r3) + (/.trapezoid r0 r2 r3 r1) + (/.trapezoid r0 r3 r1 r2) + (/.trapezoid r0 r3 r2 r1) + + (/.trapezoid r1 r0 r2 r3) + (/.trapezoid r1 r0 r3 r2) + (/.trapezoid r1 r2 r0 r3) + (/.trapezoid r1 r2 r3 r0) + (/.trapezoid r1 r3 r0 r2) + (/.trapezoid r1 r3 r2 r0) + + (/.trapezoid r2 r0 r1 r3) + (/.trapezoid r2 r0 r3 r1) + (/.trapezoid r2 r1 r0 r3) + (/.trapezoid r2 r1 r3 r0) + (/.trapezoid r2 r3 r0 r1) + (/.trapezoid r2 r3 r1 r0) + + (/.trapezoid r3 r0 r1 r2) + (/.trapezoid r3 r0 r2 r1) + (/.trapezoid r3 r1 r0 r2) + (/.trapezoid r3 r1 r2 r0) + (/.trapezoid r3 r2 r0 r1) + (/.trapezoid r3 r2 r1 r0) + ))) + + middle_maxima! + (and (r.= //.true (/.membership reference middle_bottom)) + (r.= //.true (/.membership reference middle_top))) + + boundary_minima! + (and (r.= //.false (/.membership reference bottom)) + (r.= //.false (/.membership reference top))) + + inside_range! + (bit\= (r.> //.false (/.membership reference sample)) + (and (r.> bottom sample) + (r.< top sample))) + + outside_range! + (bit\= (r.= //.false (/.membership reference sample)) + (or (r.<= bottom sample) + (r.>= top sample))) + + + inside_inner_range! + (bit\= (r.= //.true (/.membership reference sample)) + (and (r.<= middle_top sample) + (r.>= middle_bottom sample)))] + (and irrelevant_order! + middle_maxima! + boundary_minima! + inside_range! + outside_range! + inside_inner_range!))) )))) -(def: predicates_and_sets +(def: discrete Test - (do {! random.monad} - [#let [set_10 (set.from_list n.hash (enum.range n.enum 0 10))] - sample (|> random.nat (\ ! map (n.% 20)))] + (do random.monad + [threshold random.nat + #let [under? (n.< threshold) + set (set.from_list n.hash (list threshold))] + sample random.nat] ($_ _.and - (_.test (%.name (name_of /.from_predicate)) - (bit\= (r.= //.true (/.membership sample (/.from_predicate n.even?))) - (n.even? sample))) - (_.test (%.name (name_of /.from_set)) - (bit\= (r.= //.true (/.membership sample (/.from_set set_10))) - (set.member? set_10 sample))) + (_.cover [/.from_predicate] + (bit\= (r.= //.true (/.membership (/.from_predicate under?) sample)) + (under? sample))) + (_.cover [/.from_set] + (and (r.= //.true (/.membership (/.from_set set) threshold)) + (bit\= (r.= //.true (/.membership (/.from_set set) sample)) + (set.member? set sample)))) ))) -(def: thresholds +(def: gradient + (Random [[Rev Rev] (Fuzzy Rev)]) + (do random.monad + [sample random.rev + + threshold_0 random.rev + threshold_1 random.rev + + #let [bottom (r.min threshold_0 threshold_1) + top (r.max threshold_0 threshold_1)]] + (wrap [[bottom top] + (/.gradient bottom top)]))) + +(def: threshold Test (do random.monad - [fuzzy ..triangle - sample random.rev + [[_ set] ..gradient threshold random.rev - #let [vip_fuzzy (/.cut threshold fuzzy) - member? (/.to_predicate threshold fuzzy)]] - (<| (_.context (%.name (name_of /.cut))) - ($_ _.and - (_.test "Can increase the threshold of membership of a fuzzy set." - (bit\= (r.> //.false (/.membership sample vip_fuzzy)) - (r.> threshold (/.membership sample fuzzy)))) - (_.test "Can turn fuzzy sets into predicates through a threshold." - (bit\= (member? sample) - (r.> threshold (/.membership sample fuzzy)))) - )))) + sample random.rev] + ($_ _.and + (_.cover [/.to_predicate] + (bit\= (not ((/.to_predicate threshold set) sample)) + (r.< threshold (/.membership set sample)))) + (_.cover [/.cut] + (bit\= (r.= //.false (/.membership (/.cut threshold set) sample)) + (r.< threshold (/.membership set sample)))) + ))) (def: #export test Test - (<| (_.context (%.name (name_of /._))) - ($_ _.and - ..rev_triangles - ..rev_trapezoids - ..combinators - ..predicates_and_sets - ..thresholds - ))) + (<| (_.covering /._) + (_.for [/.Fuzzy]) + (do random.monad + [sample random.rev + [_ fuzzy] ..gradient + #let [equivalence (: (Equivalence (/.Fuzzy Rev)) + (structure + (def: (= left right) + (r.= (left sample) + (right sample)))))]] + ($_ _.and + (_.for [/.functor] + ($contravariant.spec equivalence fuzzy /.functor)) + + ..trivial + ..simple + ..composition + ..geometric + ..discrete + ..threshold + )))) diff --git a/stdlib/source/test/lux/math/modulus.lux b/stdlib/source/test/lux/math/modulus.lux index 4f3b4a2fb..c5147e75c 100644 --- a/stdlib/source/test/lux/math/modulus.lux +++ b/stdlib/source/test/lux/math/modulus.lux @@ -56,6 +56,10 @@ (_.cover [/.literal] (with_expansions [<divisor> (|divisor|)] (i.= <divisor> (/.divisor (/.literal <divisor>))))) + (_.cover [/.=] + (with_expansions [<divisor> (|divisor|)] + (/.= (/.literal <divisor>) + (/.literal <divisor>)))) (_.cover [/.congruent?] (and (/.congruent? modulus dividend dividend) (or (not (/.congruent? modulus dividend (inc dividend))) diff --git a/stdlib/source/test/lux/math/number/frac.lux b/stdlib/source/test/lux/math/number/frac.lux index dcaa417ed..2bd56a513 100644 --- a/stdlib/source/test/lux/math/number/frac.lux +++ b/stdlib/source/test/lux/math/number/frac.lux @@ -120,8 +120,8 @@ (with_expansions [<jvm> (as_is (host.import: java/lang/Double ["#::." - (#static doubleToRawLongBits #manual [double] long) - (#static longBitsToDouble #manual [long] double)]))] + (#static doubleToRawLongBits [double] long) + (#static longBitsToDouble [long] double)]))] (for {@.old (as_is <jvm>) @.jvm (as_is <jvm>)})) diff --git a/stdlib/source/test/lux/meta.lux b/stdlib/source/test/lux/meta.lux index 6997d55e3..3f92e9d13 100644 --- a/stdlib/source/test/lux/meta.lux +++ b/stdlib/source/test/lux/meta.lux @@ -114,7 +114,8 @@ (: (Meta Any)) (/.run expected_lux) (!expect (^multi (#try.Failure actual_error) - (text\= expected_error actual_error))))) + (text\= (location.with location.dummy expected_error) + actual_error))))) (_.cover [/.assert] (and (|> (/.assert expected_error true) (: (Meta Any)) @@ -143,12 +144,14 @@ (/.fail expected_error))) (/.run expected_lux) (!expect (^multi (#try.Failure actual_error) - (text\= expected_error actual_error)))) + (text\= (location.with location.dummy expected_error) + actual_error)))) (|> (/.either (\ /.monad wrap expected) (\ /.monad wrap dummy)) (/.run expected_lux) (!expect (^multi (#try.Success actual) - (n.= expected actual)))))) + (n.= expected actual)))) + )) ))) (def: module_related |