From 33491c1f0331f7e1e089b612286a8def1b42b630 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sat, 28 Sep 2024 04:52:41 -0400 Subject: [PATCH] Improving test coverage [part 7] --- stdlib/source/library/lux.lux | 132 ++---- .../source/library/lux/abstract/functor.lux | 3 +- .../library/lux/abstract/projection.lux | 4 +- .../source/library/lux/data/format/json.lux | 3 +- stdlib/source/library/lux/error.lux | 1 + stdlib/source/library/lux/macro/pattern.lux | 9 +- .../library/lux/math/number/64/rational.lux | 2 +- .../library/lux/math/number/big/fraction.lux | 6 +- .../library/lux/math/number/big/integer.lux | 54 ++- .../library/lux/math/number/big/natural.lux | 26 +- .../library/lux/math/number/big/rational.lux | 24 +- stdlib/source/library/lux/meta/module.lux | 14 +- stdlib/source/library/lux/physics/2.lux | 54 --- .../library/lux/physics/2/motion/circle.lux | 63 ++- stdlib/source/library/lux/type.lux | 4 +- stdlib/source/test/lux.lux | 187 ++++---- stdlib/source/test/lux/abstract/functor.lux | 27 ++ .../source/test/lux/abstract/projection.lux | 21 +- .../source/test/lux/data/collection/array.lux | 2 +- .../source/test/lux/data/collection/list.lux | 16 +- stdlib/source/test/lux/data/format/json.lux | 30 +- stdlib/source/test/lux/error.lux | 3 +- .../test/lux/math/number/64/decimal.lux | 5 +- .../test/lux/math/number/64/rational.lux | 10 +- .../test/lux/math/number/big/fraction.lux | 2 +- .../test/lux/math/number/big/integer.lux | 6 +- .../test/lux/math/number/big/natural.lux | 2 +- .../test/lux/math/number/big/rational.lux | 68 ++- stdlib/source/test/lux/meta/module.lux | 39 +- stdlib/source/test/lux/type.lux | 442 +++++++++--------- 30 files changed, 705 insertions(+), 554 deletions(-) diff --git a/stdlib/source/library/lux.lux b/stdlib/source/library/lux.lux index cca17cf61..4ca4ff19c 100644 --- a/stdlib/source/library/lux.lux +++ b/stdlib/source/library/lux.lux @@ -1959,32 +1959,32 @@ ..no_provenance (code#text value)))) -(the' .public UnQuote +(the' .private UnQuote Type {#Named [..prelude "UnQuote"] {#Nominal ".Macro/UnQuote" (.list#)}}) -(the' .public (unquote it) +(the' .private (unquote it) (-> Macro UnQuote) (.as# (-> Macro UnQuote) it)) -(the' .public (unquote_macro it) +(the' .private (unquote_macro it) (-> UnQuote Macro') (.as# (-> UnQuote Macro') it)) -(the' .public Spliced_UnQuote +(the' .private Spliced_UnQuote Type {#Named [..prelude "Spliced_UnQuote"] {#Nominal ".Macro/Spliced_UnQuote" (.list#)}}) -(the' .public (spliced_unquote it) +(the' .private (spliced_unquote it) (-> Macro Spliced_UnQuote) (.as# (-> Macro Spliced_UnQuote) it)) -(the' .public (spliced_unquote_macro it) +(the' .private (spliced_unquote_macro it) (-> Spliced_UnQuote Macro') (.as# (-> Spliced_UnQuote Macro') it)) @@ -2998,8 +2998,7 @@ [[?#variant #Variant] [?#tuple #Tuple] - [?#form #Form]] - ) + [?#form #Form]]) (the' .private (?#binding tape) ($ Projection (And Text Code)) @@ -3065,8 +3064,7 @@ [[?#bit Bit #Bit] [?#natural Natural #Natural] [?#text Text #Text] - [?#name Name #Name]] - ) + [?#name Name #Name]]) (the' .private (?#this_name reference tape) (-> Name @@ -3365,10 +3363,6 @@ (monad#each meta#monad normal_type parameters))]) (meta#return lux (type_reification abstraction parameters)))) -(the' .public type_must_have_singular_expansion - Error - "The expansion of the type-syntax has to yield a single element.") - (the' .private (expanded_type_reification normal_type @ binding parameters) (-> (-> Code ($ Meta Code)) Provenance Name ($ List Code) ($ Meta Code)) @@ -3383,7 +3377,7 @@ (meta#return lux (` (..type (, singular)))) else - (meta#failure ..type_must_have_singular_expansion))) + (meta#failure "The expansion of the type-syntax has to yield a single element."))) {#None} ((normal_type_reification normal_type {#Name @ binding} parameters) lux)))) @@ -3597,8 +3591,7 @@ ))] [[product#left left] - [product#right right]] - ) + [product#right right]]) (the' .private (generated_name prefix state) (-> Text @@ -4067,8 +4060,7 @@ (` ))))))] [[0b (if (, pre) 1b (, post)) or] - [1b (if (, pre) (, post) 0b) and]] - ) + [1b (if (, pre) (, post) 0b) and]]) ... https://en.wikipedia.org/wiki/Halting_problem (the .public (halt! message) @@ -4317,56 +4309,6 @@ {#None} {#Left "Not expecting any type."})))) -(the \n - Text - (.int_char# +10)) - -(the (provenance#as it) - (-> Provenance - Text) - (let [... https://en.wikipedia.org/wiki/Delimiter - delimiter "," - [file line column] it] - (text "@" - (text#as file) delimiter - (natural#as line) delimiter - (natural#as column)))) - -(the (provenance#with provenance error) - (-> Provenance - (Change Text)) - (text (provenance#as provenance) \n - error)) - -(the provenance#here - (macro (_ tokens compiler) - (when tokens - (list) - (let [[..#info _ - ..#source _ - ..#current_module _ - ..#modules _ - ..#scopes _ - ..#type_context _ - ..#seed _ - ..#expected _ - ..#provenance provenance - ..#eval _] compiler - [.#module module .#line line .#column column] provenance] - {#Right [compiler - (list (` (.is .Provenance - [.#module (, {..#Text ..provenance#dummy module}) - .#line (, {..#Natural ..provenance#dummy line}) - .#column (, {..#Natural ..provenance#dummy column})])))]}) - - _ - {#Left ..wrong_syntax}))) - -(the .public invalid_implementation_member - Error - (provenance#with (provenance#here) - "Invalid implementation member.")) - (the .public implementation (macro (_ tokens) (with_monad meta#monad @@ -4399,10 +4341,10 @@ (pure (list tag value)) _ - (failure (text "Unknown implementation member: " slot_name))) + (failure (text "Unknown member of implementation: " slot_name))) _ - (failure ..invalid_implementation_member)))) + (failure "Invalid member of implementation.")))) (list#conjoint tokens'))] (pure (list (code#tuple (list#conjoint members))))))) @@ -4459,11 +4401,6 @@ (?#and ?#simple_global_declaration ?#any)) -(the .public improper_type_definition - Error - (provenance#with (provenance#here) - "Improper type definition syntax.")) - (the (declaration_of_type it) (-> Code (Meta [Code (Maybe (Either (List Text) (List Text)))])) @@ -4479,7 +4416,7 @@ (meta#pure [type {#Some {#Left tags}}]) {#None} - (failure ..improper_type_definition)) + (failure ..wrong_syntax)) (list type {#Tuple _ slots}) (when (?#value slots (?#some ?#text)) @@ -4487,13 +4424,13 @@ (meta#pure [type {#Some {#Right slots}}]) {#None} - (failure ..improper_type_definition)) + (failure ..wrong_syntax)) (list type) (meta#pure [it {#None}]) _ - (failure ..improper_type_definition))) + (failure ..wrong_syntax))) else (meta#pure [it {#None}]))) @@ -4771,6 +4708,10 @@ (.text_size# input))] (.text_clip# after_offset after_length input)))))) +(the \n + Text + (.int_char# +10)) + (the (absolute_module_name nested? relative_root module) (-> Bit Text Text (Meta Text)) @@ -5390,15 +5331,7 @@ {#None} (failure ..wrong_syntax)))) -(the (imported_by? import_name module_name) - (-> Text Text - (Meta Bit)) - (with_monad meta#monad - [module (module module_name) - .let [[..#module_hash _ ..#module_aliases _ ..#definitions _ ..#imports imports ..#module_state _] module]] - (pure (list#member? imports import_name)))) - -(the .public refer +(the refer (macro (_ tokens) (when (?#value tokens (all ?#and @@ -5662,8 +5595,7 @@ (|>> ( 1)))] [[++ .i64_+#] - [-- .i64_-#]] - ) + [-- .i64_-#]]) (the (interleaved left right) (for_any (_ it) @@ -5829,6 +5761,17 @@ _ (failure ..wrong_syntax)))) +(the (provenance#as it) + (-> Provenance + Text) + (let [... https://en.wikipedia.org/wiki/Delimiter + delimiter "," + [file line column] it] + (text "@" + (text#as file) delimiter + (natural#as line) delimiter + (natural#as column)))) + (the .public undefined (let [provenance (is (Meta Provenance) (function (_ compiler) @@ -5945,8 +5888,7 @@ [[i64 ..I64] [natural ..Natural] [integer ..Integer] - [revolution ..Revolution]] - ) + [revolution ..Revolution]]) (the .public character (macro (_ tokens compiler) @@ -5993,8 +5935,7 @@ [c++ "C++"] [common_lisp "Common Lisp"] [php "PHP"] - [r "R"]] - ) + [r "R"]]) (the .public for (let [target (is (Meta Target) @@ -6219,8 +6160,7 @@ [[Analysis] [Synthesis] [Translation] - [Declaration]] - ) + [Declaration]]) (the .public alias (macro (_ tokens) diff --git a/stdlib/source/library/lux/abstract/functor.lux b/stdlib/source/library/lux/abstract/functor.lux index 335d5aca3..3f438966e 100644 --- a/stdlib/source/library/lux/abstract/functor.lux +++ b/stdlib/source/library/lux/abstract/functor.lux @@ -69,8 +69,7 @@ (the .public (recursive body) (for_any (_ it) - (-> (-> (Functor it) - (Functor it)) + (-> (Change (Functor it)) (Functor it))) (implementation (the (each value it) diff --git a/stdlib/source/library/lux/abstract/projection.lux b/stdlib/source/library/lux/abstract/projection.lux index 332271746..ee58e7165 100644 --- a/stdlib/source/library/lux/abstract/projection.lux +++ b/stdlib/source/library/lux/abstract/projection.lux @@ -245,8 +245,8 @@ (the .public (when condition next) (for_any (_ state it) - (-> Bit (Projection state it) - (Projection state it))) + (-> Bit + (Change (Projection state it)))) (function (_ state) (if condition (next state) diff --git a/stdlib/source/library/lux/data/format/json.lux b/stdlib/source/library/lux/data/format/json.lux index f650ff351..038dbf7b4 100644 --- a/stdlib/source/library/lux/data/format/json.lux +++ b/stdlib/source/library/lux/data/format/json.lux @@ -607,8 +607,7 @@ (the .public (recursive context) (for_any (_ it) - (-> (-> (Format JSON it) - (Format JSON it)) + (-> (Change (Format JSON it)) (Format JSON it))) (implementation (the (as it) diff --git a/stdlib/source/library/lux/error.lux b/stdlib/source/library/lux/error.lux index eff4856bf..fe0458d07 100644 --- a/stdlib/source/library/lux/error.lux +++ b/stdlib/source/library/lux/error.lux @@ -34,3 +34,4 @@ (the .public not_known) (the .public empty) (the .public no_instance) +(the .public not_available) diff --git a/stdlib/source/library/lux/macro/pattern.lux b/stdlib/source/library/lux/macro/pattern.lux index ccad068dd..486b41716 100644 --- a/stdlib/source/library/lux/macro/pattern.lux +++ b/stdlib/source/library/lux/macro/pattern.lux @@ -3,9 +3,7 @@ (.using [library - [lux (.except UnQuote unquote unquote_macro - Spliced_UnQuote spliced_unquote spliced_unquote_macro - or let |>) + [lux (.except or let |>) [abstract ["[0]" monad]] [control @@ -22,7 +20,7 @@ ["[0]" vocabulary] ["[0]" expansion]]) -(the with_template (.in_module# .prelude .with_template)) +(the with_template (.in_module# .prelude with_template)) (with_template [] [(the (.in_module# .prelude ))] @@ -59,8 +57,7 @@ [?#any] [?#name] [?#local] - [?#tuple]] - ) + [?#tuple]]) (the .public or (pattern diff --git a/stdlib/source/library/lux/math/number/64/rational.lux b/stdlib/source/library/lux/math/number/64/rational.lux index 315eaa538..652e9e503 100644 --- a/stdlib/source/library/lux/math/number/64/rational.lux +++ b/stdlib/source/library/lux/math/number/64/rational.lux @@ -246,7 +246,7 @@ (the arithmetic_of_module_2/2 (template.macro (_ ,*variables) [(every .public Exponent - Integer) + fraction.Exponent) ... https://en.wikipedia.org/wiki/Exponentiation ... https://en.wikipedia.org/wiki/Exponentiation_by_squaring diff --git a/stdlib/source/library/lux/math/number/big/fraction.lux b/stdlib/source/library/lux/math/number/big/fraction.lux index 02228bead..4328e918a 100644 --- a/stdlib/source/library/lux/math/number/big/fraction.lux +++ b/stdlib/source/library/lux/math/number/big/fraction.lux @@ -14,14 +14,16 @@ ["[0]" list ["?[1]" \\projection]]]] [math - ["[0]" random (.only Random) (.use "[1]#[0]" functor)]]]] + ["[0]" random (.only Random) (.use "[1]#[0]" functor)]] + [aspect + ["[0]" case]]]] [// ["//" natural] [// [/64 ["/" fraction]]]]) -(/.module //.Number //.small +(/.module //.Number (case.some //.small) //.= //.< //.greatest_common_divisor //.zero //.one //.+ //.- //.x //./ //.% diff --git a/stdlib/source/library/lux/math/number/big/integer.lux b/stdlib/source/library/lux/math/number/big/integer.lux index 703dc4d90..7141a0740 100644 --- a/stdlib/source/library/lux/math/number/big/integer.lux +++ b/stdlib/source/library/lux/math/number/big/integer.lux @@ -19,7 +19,9 @@ [function [predicate (.only Predicate)]] [math - ["[0]" random (.only Random)]]]] + ["[0]" random (.only Random)]] + [aspect + ["[0]" case (.only Case)]]]] [// ["//" natural] [// @@ -28,8 +30,8 @@ ["//_64" natural] ["/_64" integer]]]]) -(the with_template (.in_module# .prelude .with_template)) -(the macro (.in_module# .prelude .template#macro)) +(the with_template (.in_module# .prelude with_template)) +(the macro (.in_module# .prelude template#macro)) (with_template [,value ,character ,signum] [(the ,value @@ -84,23 +86,35 @@ /_64.Number (by /_64.interval minimum)) -(the .public (small it) - (-> /_64.Number - It) - (when it - ..most_small - [#signum ..negative - #absolute (|> (by /_64.interval maximum) - .natural - //.small - (//.+ //.one))] - - else - [#signum (/_64.negative? (/_64.signum it)) - #absolute (|> it - /_64.absolute - .natural - //.small)])) +(the .public small + (Case It /_64.Number) + (case.new (function (_ it) + (when (case.if //.small (its #absolute it)) + {.#Right absolute} + (if (//_64.< //_64.infinity absolute) + {.#Right (/_64.x (when (its #signum it) + signum.positive /_64.positive_one + signum.negative /_64.negative_one) + (.integer absolute))} + {.#Left it}) + + else + {.#Left it})) + (function (_ it) + (when it + ..most_small + [#signum ..negative + #absolute (|> (by /_64.interval maximum) + .natural + (case.some //.small) + (//.+ //.one))] + + else + [#signum (/_64.negative? (/_64.signum it)) + #absolute (|> it + /_64.absolute + .natural + (case.some //.small))])))) (the .public (normal it) (Change It) diff --git a/stdlib/source/library/lux/math/number/big/natural.lux b/stdlib/source/library/lux/math/number/big/natural.lux index be39e760d..cf6a4d5f4 100644 --- a/stdlib/source/library/lux/math/number/big/natural.lux +++ b/stdlib/source/library/lux/math/number/big/natural.lux @@ -38,8 +38,8 @@ (the It ..Number) -(the with_template (.in_module# .prelude .with_template)) -(the macro (.in_module# .prelude .template#macro)) +(the with_template (.in_module# .prelude with_template)) +(the macro (.in_module# .prelude template#macro)) (the zero' (macro (_) @@ -57,12 +57,22 @@ It (one')) -(the .public (small it) - (-> //.Number - Number) - (when it - 0 ..zero - _ (list it))) +(the .public small + (Case Number //.Number) + (case.new (function (_ it) + (when it + (..zero') + {.#Right //.zero} + + (list it) + {.#Right it} + + else + {.#Left it})) + (function (_ it) + (when it + //.zero ..zero + _ (list it))))) (the .public (random digits) (-> //.Number diff --git a/stdlib/source/library/lux/math/number/big/rational.lux b/stdlib/source/library/lux/math/number/big/rational.lux index f4a2214e4..8810dc400 100644 --- a/stdlib/source/library/lux/math/number/big/rational.lux +++ b/stdlib/source/library/lux/math/number/big/rational.lux @@ -14,7 +14,9 @@ ["[0]" list ["?[1]" \\projection]]]] [math - ["[0]" random (.only Random) (.use "[1]#[0]" functor)]]]] + ["[0]" random (.only Random) (.use "[1]#[0]" functor)]] + [aspect + ["[0]" case (.only Case)]]]] [// ["[0]" natural] ["[0]" integer] @@ -38,16 +40,24 @@ integer.= integer.< integer.+ integer.- integer.x integer./ integer.% integer.opposite integer.signum integer.greatest_common_divisor - integer.natural integer.small + integer.natural (case.some integer.small) integer.base_10 fraction.delimiter) -(the .public (small it) - (-> /.Number - ..Number) - (new (natural.small (/.denominator it)) - (integer.small (/.numerator it)))) +(the .public small + (Case ..Number /.Number) + (case.new (function (_ it) + (when [(case.if natural.small (..denominator it)) + (case.if integer.small (..numerator it))] + [{.#Right denominator} {.#Right numerator}] + {.#Right (/.new denominator numerator)} + + else + {.#Left it})) + (function (_ it) + (new (case.some natural.small (/.denominator it)) + (case.some integer.small (/.numerator it)))))) (the .public (random digits) (-> Natural diff --git a/stdlib/source/library/lux/meta/module.lux b/stdlib/source/library/lux/meta/module.lux index 1f9d64330..1e9bcbba1 100644 --- a/stdlib/source/library/lux/meta/module.lux +++ b/stdlib/source/library/lux/meta/module.lux @@ -6,15 +6,14 @@ [lux (.except Name all) [abstract ["[0]" monad]] - [error + ["[0]" error (.only) ["[0]" try]] [data ["[0]" text] [collection [list ["[0]" property]]]]]] - ["[0]" // (.only) - ["[0]" provenance]]) + ["[0]" //]) (every .public Name Text) @@ -32,12 +31,7 @@ {try.#Success [lux module]} failure - {try.#Failure (text "Unknown module: " name)}))) - -(the .public no_current - Error - (provenance.with (provenance.here) - "No current module.")) + {try.#Failure error.not_known}))) (the .public current_name (Meta Name) @@ -47,7 +41,7 @@ {try.#Success [lux current_module]} _ - {try.#Failure ..no_current}))) + {try.#Failure error.not_available}))) (the .public current (Meta [Name Module]) diff --git a/stdlib/source/library/lux/physics/2.lux b/stdlib/source/library/lux/physics/2.lux index f3b9d6bd0..3a84ef1d4 100644 --- a/stdlib/source/library/lux/physics/2.lux +++ b/stdlib/source/library/lux/physics/2.lux @@ -201,57 +201,3 @@ [+03.5e+10 brass] [+02.5e+10 aluminium] [+02.6e+10 quartz]]) - -(comment - ... https://en.wikipedia.org/wiki/Centripetal_force - (every .public Centripetal_Acceleration - /1.Vector) - - (the (square it) - (.Change /1.Vector) - (/.x it it)) - - (the .public (centripetal_acceleration radius velocity) - (-> Radius Velocity - Centripetal_Acceleration) - (/./ radius - (square (magnitude velocity)))) - - ... https://en.wikipedia.org/wiki/Frequency#Period_versus_frequency - (every .public Period - /1.Vector) - - (the .public (period radius velocity) - (-> Radius Velocity - Period) - (|> (magnitude velocity) - (/./ radius) - (/.x circle.tau))) - - ... https://en.wikipedia.org/wiki/Angular_velocity - (every .public Angular_Velocity - /1.Vector) - - (the .public (angular_velocity period) - (-> Period - Angular_Velocity) - (/./ period - circle.tau)) - - (every .public Speed - /1.Vector) - - (the .public (speed radius angular_velocity) - (-> Radius Angular_Velocity - Speed) - (/.x radius angular_velocity)) - - ... https://en.wikipedia.org/wiki/Acceleration#Circular_motion - (every .public Radial_Acceleration - /1.Vector) - - (the .public (radial_acceleration radius velocity) - (-> Radius Velocity - Radial_Acceleration) - (/1.opposite (centripetal_acceleration radius velocity))) - ) diff --git a/stdlib/source/library/lux/physics/2/motion/circle.lux b/stdlib/source/library/lux/physics/2/motion/circle.lux index 5b8e05ec8..393b11b63 100644 --- a/stdlib/source/library/lux/physics/2/motion/circle.lux +++ b/stdlib/source/library/lux/physics/2/motion/circle.lux @@ -7,7 +7,9 @@ [math [number [/64 - ["[0]" decimal]]]]]] + ["[0]" decimal]]] + [geometry + ["[0]" circle]]]]] [// ["[0]" line] ["/" // (.only) @@ -96,3 +98,62 @@ (-> /.Radius Velocity Centripetal_Acceleration) (decimal.x radius (square velocity))) + +... https://en.wikipedia.org/wiki/Frequency#Period_versus_frequency +(every .public Period + Scalar) + +(the .public (period radius velocity) + (-> /.Radius Velocity + Period) + (|> velocity + (decimal./ radius) + (decimal.x circle.tau))) + +... https://en.wikipedia.org/wiki/Frequency +(every .public Frequency + Scalar) + +(the .public (frequency period) + (-> Period + Frequency) + (decimal.reciprocal period)) + +... https://en.wikipedia.org/wiki/Wavenumber +(every .public Repetency + Scalar) + +(the .public (repetency wave_length) + (-> Scalar + Repetency) + (decimal./ wave_length + circle.tau)) + +(comment + ... https://en.wikipedia.org/wiki/Angular_velocity + (every .public Angular_Velocity + /1.Vector) + + (the .public (angular_velocity period) + (-> Period + Angular_Velocity) + (decimal./ period + circle.tau)) + + (every .public Speed + /1.Vector) + + (the .public (speed radius angular_velocity) + (-> Radius Angular_Velocity + Speed) + (decimal.x radius angular_velocity)) + + ... https://en.wikipedia.org/wiki/Acceleration#Circular_motion + (every .public Radial_Acceleration + /1.Vector) + + (the .public (radial_acceleration radius velocity) + (-> Radius Velocity + Radial_Acceleration) + (/1.opposite (centripetal_acceleration radius velocity))) + ) diff --git a/stdlib/source/library/lux/type.lux b/stdlib/source/library/lux/type.lux index c423f8ff7..d1c3e2cba 100644 --- a/stdlib/source/library/lux/type.lux +++ b/stdlib/source/library/lux/type.lux @@ -46,7 +46,7 @@ (every .public Variable Natural) -(the with_template (.in_module# .prelude .with_template)) +(the with_template (.in_module# .prelude with_template)) (with_template [ ] [(the .public ( type) @@ -64,7 +64,7 @@ [[flat_univ_q .universal] [flat_ex_q .existential]]) -(the template#macro (.in_module# .prelude .template#macro)) +(the template#macro (.in_module# .prelude template#macro)) (the function_type (.type_name# "function")) (`` (the .public Function diff --git a/stdlib/source/test/lux.lux b/stdlib/source/test/lux.lux index 680b46695..54a877512 100644 --- a/stdlib/source/test/lux.lux +++ b/stdlib/source/test/lux.lux @@ -42,7 +42,8 @@ ["[0]" code (.only) ["<[1]>" \\projection]]] [test - ["_" property (.only Test)]]]] + ["_" property (.only Test)]] + ["[0]" type]]] ... TODO: Must have 100% coverage on tests. ["[0]" / ["[1][0]" abstract] @@ -145,7 +146,8 @@ (the for_bit Test (monad.let random.monad - [expected random.natural + [judgement random.bit + expected random.natural dummy random.natural] (_.for [/.Bit /.if] (all _.and @@ -174,6 +176,9 @@ (_.coverage [/.not] (and (bit.= /.true (/.not /.false)) (bit.= /.false (/.not /.true)))) + (_.coverage [/.unless] + (same? (/.if judgement expected dummy) + (/.unless judgement dummy expected))) )))) (the for_try @@ -256,7 +261,12 @@ (let [(/.open "local#[0]") local_returner] (n.= expected (local#return [])))) (_.coverage [/.by] - (n.= expected (/.by local_returner return []))) + (n.= expected + (/.by local_returner return []))) + (_.coverage [/.with] + (n.= expected + (/.with local_returner + (return [])))) )))) (the for_module @@ -400,55 +410,38 @@ ..for_code/` ..for_code/`' )) - (_.for [/.UnQuote] - (all _.and - (_.coverage [/.unquote_macro] - (exec - (is /.Macro' - (/.unquote_macro /.,)) - (is /.Macro' - (/.unquote_macro /.,')) - true)) - (_.coverage [/.unquote] - (exec - (is /.UnQuote - (/.unquote (macro.macro (/.unquote_macro /.,)))) - (is /.UnQuote - (/.unquote (macro.macro (/.unquote_macro /.,')))) - true)) - (_.coverage [/., /.but] - (expansion.let [ (code.natural example_natural)] - (and (not (code.= - (/.' (/., )))) - (code.= - (/.` (/., ))) - (code.= - (/.`' (/., )))))) - (_.coverage [/.,* /.also] - (expansion.let [ (code.bit example_bit) - (code.natural example_natural) - (code.integer example_integer) - (code.tuple (list )) - [(/.,* (list ))]] - (and (not (code.= - (/.' ))) - (code.= - (/.` )) - (code.= - (/.`' ))))) - (_.coverage [/.,' /.verbatim] - (expansion.let [ (code.bit example_bit) - (code.natural example_natural) - (code.integer example_integer) - (/.' [(stack )]) - [(/.,' (stack ))]] - (and (not (code.= - (/.' ))) - (code.= - (/.` )) - (code.= - (/.`' ))))) - )) + (_.coverage [/., /.but] + (expansion.let [ (code.natural example_natural)] + (and (not (code.= + (/.' (/., )))) + (code.= + (/.` (/., ))) + (code.= + (/.`' (/., )))))) + (_.coverage [/.,* /.also] + (expansion.let [ (code.bit example_bit) + (code.natural example_natural) + (code.integer example_integer) + (code.tuple (list )) + [(/.,* (list ))]] + (and (not (code.= + (/.' ))) + (code.= + (/.` )) + (code.= + (/.`' ))))) + (_.coverage [/.,' /.verbatim] + (expansion.let [ (code.bit example_bit) + (code.natural example_natural) + (code.integer example_integer) + (/.' [(stack )]) + [(/.,' (stack ))]] + (and (not (code.= + (/.' ))) + (code.= + (/.` )) + (code.= + (/.`' ))))) ))) (the identity_macro @@ -616,8 +609,7 @@ expected/1 existential_type] (<| (_.for [/.Type /.#Nominal /.#Variable /.#Opaque /.#Reification /.#Named - /.#Parameter /.abstraction /.argument - /.#Quantification /.universal /.existential]) + /.#Parameter /.#Quantification]) (all _.and (_.coverage [/.is] (|> expected @@ -661,6 +653,17 @@ [#slot/0 (n.= expected_left expected_right) #slot/1 (.revolution expected_right)]) true)) + (_.coverage [/.type] + (and (type.= expected/0 + (/.type expected/0)) + (type.= (type.Sum expected/0 expected/1) + (/.type (Or expected/0 expected/1))) + (type.= (type.Product expected/0 expected/1) + (/.type [expected/0 expected/1])) + (type.= (type.Function expected/0 expected/1) + (/.type (-> expected/0 expected/1))) + (type.= {.#Reification expected/1 expected/0} + (/.type (expected/0 expected/1))))) )))) (the for_i64 @@ -692,18 +695,26 @@ Test (monad.let random.monad [expected_left random.natural - expected_right random.natural] - (_.coverage [/.-> /.function] - (and (let [actual (is (/.-> Natural Natural Natural) - (/.function (_ actual_left actual_right) - (n.x (++ actual_left) (-- actual_right))))] - (n.= (n.x (++ expected_left) (-- expected_right)) - (actual expected_left expected_right))) - (let [actual (is (/.-> [Natural Natural] Natural) - (/.function (_ [actual_left actual_right]) - (n.x (++ actual_left) (-- actual_right))))] - (n.= (n.x (++ expected_left) (-- expected_right)) - (actual [expected_left expected_right]))))))) + expected_right random.natural + + left (/type.random 0) + right (/type.random 0)] + (all _.and + (_.coverage [/.-> /.function] + (and (let [actual (is (/.-> Natural Natural Natural) + (/.function (_ actual_left actual_right) + (n.x (++ actual_left) (-- actual_right))))] + (n.= (n.x (++ expected_left) (-- expected_right)) + (actual expected_left expected_right))) + (let [actual (is (/.-> [Natural Natural] Natural) + (/.function (_ [actual_left actual_right]) + (n.x (++ actual_left) (-- actual_right))))] + (n.= (n.x (++ expected_left) (-- expected_right)) + (actual [expected_left expected_right]))))) + (_.coverage [/.<-] + (type.= (/.-> left right) + (/.<- right left))) + ))) (the option/0 "0") (the option/1 "1") @@ -827,13 +838,19 @@ mid (random.lower_cased 1) right (random.lower_cased 1) .let [expected (text.interposed "" (list left mid right))]] - (_.coverage [/.left_associative /.right_associative] - (expansion.let [ (/.left_associative .text left mid right) - (/.right_associative .text left mid right)] - (and (text.= - ) - (not (code.= (' ) - (' )))))))) + (all _.and + (_.coverage [/.left_associative /.right_associative] + (expansion.let [ (/.left_associative .text left mid right) + (/.right_associative .text left mid right)] + (and (text.= + ) + (not (code.= (' ) + (' )))))) + (_.coverage [/.all] + (same? /.right_associative /.all)) + (_.coverage [/.per] + (same? /.left_associative /.per)) + ))) (the for_expansion Test @@ -871,6 +888,9 @@ dummy)))) ))) +(alias [alias?'] + /.alias?) + (the for_value Test (monad.let random.monad @@ -948,6 +968,9 @@ (not (/.same? left not_left)))) (/.alias? /.same? /.alias?) (/.alias? /.same? /.identical?))) + (_.coverage [/.alias] + (/.alias? /.alias? + ..alias?')) (_.coverage [/.Rec] (let [stack (is (/.Rec NStack (Maybe [Natural NStack])) @@ -1019,13 +1042,17 @@ {.#Right +0} true _ false) )) - ... (_.coverage [/.pattern] - ... (/.when [..#left expected_natural ..#right expected_integer] - ... (!pair 0 +0) - ... true - - ... _ - ... false)) + (_.coverage [/.match?] + (and (/.match? 0 expected_natural) + (/.match? +0 expected_integer) + (/.match? (^.or .5 .25) expected_revolution) + (/.match? (^.or +0.5 +1.25) expected_decimal) + (/.match? (^.or "+0.5" "+1.25") expected_text) + (/.match? [0 +0] [expected_natural expected_integer]) + (/.match? [..#left 0 ..#right +0] [..#left expected_natural ..#right expected_integer]) + (/.match? {.#Left 0} (is (Either Natural Integer) {.#Left expected_natural})) + (/.match? {.#Right +0} (is (Either Natural Integer) {.#Right expected_integer})) + )) (_.coverage [/.let] (and (/.let [actual_natural expected_natural] (/.same? expected_natural actual_natural)) diff --git a/stdlib/source/test/lux/abstract/functor.lux b/stdlib/source/test/lux/abstract/functor.lux index d37d422bc..df9d2f3c4 100644 --- a/stdlib/source/test/lux/abstract/functor.lux +++ b/stdlib/source/test/lux/abstract/functor.lux @@ -119,6 +119,33 @@ shift random.natural] (<| (_.covering /._) (all _.and + (_.coverage [/.constant] + (same? left + (by /.constant each + (n.+ shift) + left))) + (_.coverage [/.variable] + (n.= (n.+ shift left) + (by /.variable each + (n.+ shift) + left))) + (_.coverage [/.Function /.function] + (n.= (n.+ shift left) + ((by (/.function /.variable) each + (n.+ shift) + function.identity) + left))) + (_.coverage [/.recursive] + (with (stack.equivalence n.equivalence) + (= (with stack.functor + (each (n.+ shift) (stack left right))) + (with (is (Functor (//.Recursive (for_any (_ self) + (//.Sum (//.Constant Any) + (//.Product //.Variable self))))) + (/.recursive + (|>> (/.product /.variable) + (/.sum /.constant)))) + (each (n.+ shift) (stack left right)))))) (_.coverage [/.sum] (and (when (by (/.sum maybe.functor stack.functor) each (n.+ shift) diff --git a/stdlib/source/test/lux/abstract/projection.lux b/stdlib/source/test/lux/abstract/projection.lux index 0065a38cd..5d78d909b 100644 --- a/stdlib/source/test/lux/abstract/projection.lux +++ b/stdlib/source/test/lux/abstract/projection.lux @@ -176,12 +176,21 @@ (?list.value (list (code.bit not0))) fails?)))) (_.coverage [/.not] - (and (|> (/.not .natural) - (/.value [0 (list (code.natural expected0))]) - fails?) - (|> (/.not .natural) - (/.value [0 (list (code.bit not0))]) - ..success?))) + (|> (/.not .natural) + (/.value [0 (list (code.bit not0))]) + ..success?)) + (_.coverage [/.did_not_fail] + (|> (/.not .natural) + (/.value [0 (list (code.natural expected0))]) + (match? {try.#Failure /.did_not_fail}))) + (_.coverage [/.when] + (|> (/.when true (by /.monad pure [])) + (/.value [0 (list)]) + ..success?)) + (_.coverage [/.does_not_meet_condition] + (|> (/.when false (by /.monad pure [])) + (/.value [0 (list)]) + (match? {try.#Failure /.does_not_meet_condition}))) ))) (the combinators_1 diff --git a/stdlib/source/test/lux/data/collection/array.lux b/stdlib/source/test/lux/data/collection/array.lux index 12ee2671e..43e102d07 100644 --- a/stdlib/source/test/lux/data/collection/array.lux +++ b/stdlib/source/test/lux/data/collection/array.lux @@ -319,7 +319,7 @@ (the .public test Test (<| (_.covering /._) - (_.for [.Array]) + (_.for [.Array' .Array]) (monad.let [! random.monad] [size ..bounded_size base random.natural diff --git a/stdlib/source/test/lux/data/collection/list.lux b/stdlib/source/test/lux/data/collection/list.lux index 9a47fb16c..c50b8da14 100644 --- a/stdlib/source/test/lux/data/collection/list.lux +++ b/stdlib/source/test/lux/data/collection/list.lux @@ -99,6 +99,7 @@ random.natural) arbitrary_member (by ! each (n.% expected_size) random.natural) difference random.natural]) + (_.for [.List]) (all _.and (_.for [/.equivalence] (equivalenceT.spec (/.equivalence n.equivalence) random_list)) @@ -123,7 +124,20 @@ (random.list size random.natural) (random.stack size random.natural)))) - + + (_.coverage [.list] + (and (when (is (List Any) (.list)) + (.list) + true + + else + false) + (when (.list expected_value) + (.list actual_value) + (same? expected_value expected_value) + + else + false))) (_.coverage [/.size] (n.= expected_size (/.size expected_list))) diff --git a/stdlib/source/test/lux/data/format/json.lux b/stdlib/source/test/lux/data/format/json.lux index 5012f141b..c15038505 100644 --- a/stdlib/source/test/lux/data/format/json.lux +++ b/stdlib/source/test/lux/data/format/json.lux @@ -29,7 +29,8 @@ [collection ["[0]" dictionary (.only Dictionary)] ["[0]" set] - ["[0]" list (.use "[1]#[0]" functor)]]] + ["[0]" list (.use "[1]#[0]" functor)] + ["[0]" stack]]] [logic ["[0]" bit]] [math @@ -49,11 +50,13 @@ ["[0]" code] ["[0]" static]] [time - ["[0]" date] ["[0]" instant (.only) ["[0]/[1]" \\test]] ["[0]" duration (.only) - ["[0]/[1]" \\test]]] + ["[0]/[1]" \\test]] + ["[0]" date] + ["[0]" day] + ["[0]" month]] [test ["_" property (.only Test)]]]] ["[0]" \\polytypic] @@ -349,6 +352,16 @@ (formatT.spec date.equivalence /.date date.random) (formatT.spec date.equivalence (\\polytypic.format date.Date) date.random) )) + (_.for [/.day] + (all _.and + (formatT.spec day.equivalence /.day day.random) + (formatT.spec day.equivalence (\\polytypic.format day.Day) day.random) + )) + (_.for [/.month] + (all _.and + (formatT.spec month.equivalence /.month month.random) + (formatT.spec month.equivalence (\\polytypic.format month.Month) month.random) + )) (_.for [/.list] (let [equivalence (list.equivalence natural.equivalence) random (random.list 2 random.natural)] @@ -371,6 +384,17 @@ (let [equivalence (all equivalence.product bit.equivalence text.equivalence revolution.equivalence) random (all random.and random.bit (random.unicode 2) random.revolution)] (formatT.spec equivalence (all /.product /.bit /.text /.revolution) random))) + (monad.let random.monad + [left random.natural + right random.natural] + (_.coverage [/.recursive] + (with (try.equivalence (stack.equivalence natural.equivalence)) + (= {try.#Success (stack left right)} + (with (is (Format JSON (Stack Natural)) + (/.recursive + (|>> (/.product /.natural) + (/.sum /.any)))) + (of (as (stack left right)))))))) (_.for [/.Case /.case /.or /.variant] (let [equivalence (all equivalence.sum bit.equivalence text.equivalence revolution.equivalence) random (all random.or random.bit (random.unicode 2) random.revolution)] diff --git a/stdlib/source/test/lux/error.lux b/stdlib/source/test/lux/error.lux index 11f558424..a6ecad9a4 100644 --- a/stdlib/source/test/lux/error.lux +++ b/stdlib/source/test/lux/error.lux @@ -35,7 +35,8 @@ ,standard (these /.not_valid /.not_known /.empty - /.no_instance)] + /.no_instance + /.not_available)] (these (the ,local (/.error (template.text [,id]))) diff --git a/stdlib/source/test/lux/math/number/64/decimal.lux b/stdlib/source/test/lux/math/number/64/decimal.lux index 5a81aec66..a7a05286d 100644 --- a/stdlib/source/test/lux/math/number/64/decimal.lux +++ b/stdlib/source/test/lux/math/number/64/decimal.lux @@ -254,8 +254,9 @@ (/.= (r.decimal (/.revolution expected)) (/.partial expected))) (_.coverage [/.whole] - (/.= (i.decimal (/.integer expected)) - (/.whole expected))) + (let [expected (/.% +1.0e+18 expected)] + (/.= (i.decimal (/.integer expected)) + (/.whole expected)))) (monad.let random.monad [left random.unit_decimal right random.unit_decimal] diff --git a/stdlib/source/test/lux/math/number/64/rational.lux b/stdlib/source/test/lux/math/number/64/rational.lux index d55e1514a..fdac7a91a 100644 --- a/stdlib/source/test/lux/math/number/64/rational.lux +++ b/stdlib/source/test/lux/math/number/64/rational.lux @@ -144,14 +144,16 @@ (and (/.= expected (/.x /.positive_one expected)) (/.= expected (/./ /.positive_one expected)))) (_.coverage [/.smallest] - (or (not (big.< (big.small /.smallest) - (big.small (/.absolute expected)))) + (or (not (big.< (case.some big.small /.smallest) + (case.some big.small (/.absolute expected)))) (/.= /.zero expected))) (_.coverage [/.most_positive] - (or (not (big.> (big.small /.most_positive) (big.small expected))) + (or (not (big.> (case.some big.small /.most_positive) + (case.some big.small expected))) (/.= /.infinity expected))) (_.coverage [/.most_negative] - (not (big.< (big.small /.most_negative) (big.small expected)))) + (not (big.< (case.some big.small /.most_negative) + (case.some big.small expected)))) (_.coverage [/.infinity] (and (/.= /.infinity (/./ /.zero /.positive_one)) diff --git a/stdlib/source/test/lux/math/number/big/fraction.lux b/stdlib/source/test/lux/math/number/big/fraction.lux index 69602ce32..70a46534d 100644 --- a/stdlib/source/test/lux/math/number/big/fraction.lux +++ b/stdlib/source/test/lux/math/number/big/fraction.lux @@ -53,7 +53,7 @@ (`` (all _.and (,, (template.with [,format ,unit] [(let [threshold (|> (its unit.#factor ,unit) - n.small + (case.some n.small) (case.some /.natural) /.reciprocal)] (all _.and diff --git a/stdlib/source/test/lux/math/number/big/integer.lux b/stdlib/source/test/lux/math/number/big/integer.lux index a6edc9760..3a1fedf4b 100644 --- a/stdlib/source/test/lux/math/number/big/integer.lux +++ b/stdlib/source/test/lux/math/number/big/integer.lux @@ -30,7 +30,9 @@ [meta ["[0]" static]] [test - ["_" property (.only Test)]]]] + ["_" property (.only Test)]] + [aspect + ["[0]" case]]]] [\\library ["[0]" / (.only) [/// @@ -161,7 +163,7 @@ )) (monad.let [! random.monad] [.let [random (|> (/.random 2) - (by ! each (|>> (/.% (/.small +1,000)) + (by ! each (|>> (/.% (case.some /.small +1,000)) /.absolute)) (random.only (/.> /.zero)))] left random diff --git a/stdlib/source/test/lux/math/number/big/natural.lux b/stdlib/source/test/lux/math/number/big/natural.lux index ce4c916bb..c766c44d6 100644 --- a/stdlib/source/test/lux/math/number/big/natural.lux +++ b/stdlib/source/test/lux/math/number/big/natural.lux @@ -471,7 +471,7 @@ ..lattice (_.coverage [/.small] (with (try.equivalence /.equivalence) - (= {try.#Success (/.small small)} + (= {try.#Success (case.some /.small small)} (by /.base_10 of (by natural.base_10 as small))))) (_.coverage [/.even? /.odd?] (bit.= (/.even? sample) diff --git a/stdlib/source/test/lux/math/number/big/rational.lux b/stdlib/source/test/lux/math/number/big/rational.lux index 6ae2e726e..59520329a 100644 --- a/stdlib/source/test/lux/math/number/big/rational.lux +++ b/stdlib/source/test/lux/math/number/big/rational.lux @@ -33,7 +33,9 @@ [test ["_" property (.only Test)]] [aspect - ["[0]" case]]]] + ["[0]" case]] + ["[0]" type + ["[1]" check]]]] [\\library ["[0]" / (.only) [// @@ -41,7 +43,11 @@ ["[0]" integer] [// ["[0]" /64 - ["[0][1]" integer]] + ["[1]/[0]" natural] + ["[1]/[0]" integer] + ["[1]/[0]" fraction] + ["[1]/[0]" rational (.only) + ["[1]T" \\test]]] [// ["[0]" unit]]]]]]) @@ -51,7 +57,7 @@ (,, (template.with [,format ,unit] [(let [threshold (|> (its unit.#factor ,unit) .integer - integer.small + (case.some integer.small) (case.some /.integer) /.reciprocal)] (all _.and @@ -108,11 +114,15 @@ (<| (_.covering /._) (_.for [/.Number /.random]) - (monad.let random.monad - [expected (/.random 2) + (monad.let [! random.monad] + [digits (by ! each (/64/natural.% 3) random.natural) + expected (/.random digits) - it_0 (/.random 2) - it_1 (/.random 2)]) + it_0 (/.random digits) + it_1 (/.random digits) + + expected_integer (integer.random digits) + expected_small /64/rationalT.random]) (all _.and ..each_interface @@ -134,6 +144,10 @@ (/.= /.zero (/.x /.zero expected)) (/.= /.infinity (/./ /.zero expected)))) + (_.coverage [/.neutral?] + (and (/.neutral? /.zero) + (bit.= (/.= /.zero expected) + (/.neutral? expected)))) (_.coverage [/.positive_one] (and (/.= expected (/.x /.positive_one expected)) (/.= expected (/./ /.positive_one expected)))) @@ -190,7 +204,7 @@ (/.new _1 integer.zero)))) (monad.let [! random.monad] [sample (/.random 2) - power (by ! each (integer/64.% +10) + power (by ! each (/64/integer.% +10) random.integer)] (all _.and (_.coverage [/.-] @@ -202,15 +216,17 @@ (_.coverage [/.reciprocal] (/.= /.positive_one (/.x sample (/.reciprocal sample)))) + (_.coverage [/.Exponent] + (type.< /64/fraction.Exponent /.Exponent)) (_.coverage [/.^] (and (/.= /.positive_one (/.^ +0 sample)) (/.= sample (/.^ +1 sample)) (/.= (/.reciprocal sample) (/.^ -1 sample)) (/.= (/.reciprocal (/.^ power sample)) - (/.^ (integer/64.opposite power) sample)) - (if (integer/64.< +0 power) - (/.= (list#mix /.x /.positive_one (list.repeated (.natural (integer/64.opposite power)) sample)) + (/.^ (/64/integer.opposite power) sample)) + (if (/64/integer.< +0 power) + (/.= (list#mix /.x /.positive_one (list.repeated (.natural (/64/integer.opposite power)) sample)) (/.reciprocal (/.^ power sample))) (/.= (list#mix /.x /.positive_one (list.repeated (.natural power) sample)) (/.^ power sample))))) @@ -256,6 +272,36 @@ (/.= expected)) (/.= (/.x expected expected) (/.inversion expected /.positive_one))))) + (_.coverage [/.minor] + (and (same? it_0 (/.minor it_0 it_0)) + (/.<= it_0 (/.minor it_0 it_1)) + (/.<= it_1 (/.minor it_0 it_1)))) + (_.coverage [/.major] + (and (same? it_0 (/.major it_0 it_0)) + (/.>= it_0 (/.major it_0 it_1)) + (/.>= it_1 (/.major it_0 it_1)))) + (_.coverage [/.numerator /.denominator] + (/.= it_0 + (/.new (/.denominator it_0) + (/.numerator it_0)))) + (_.coverage [/.integer] + (when (|> expected_integer + (case.some /.integer) + (case.if /.integer)) + {.#Right actual} + (integer.= expected_integer actual) + + else + false)) + (_.coverage [/.small] + (when (|> expected_small + (case.some /.small) + (case.if /.small)) + {.#Right actual} + (/64/rational.= expected_small actual) + + else + false)) ..unit ))) diff --git a/stdlib/source/test/lux/meta/module.lux b/stdlib/source/test/lux/meta/module.lux index 41c0e577a..81d8c80fd 100644 --- a/stdlib/source/test/lux/meta/module.lux +++ b/stdlib/source/test/lux/meta/module.lux @@ -70,22 +70,24 @@ expected_module] [imported_module_name imported_module]) - expected_lux (is Lux - [.#info [.#target target - .#version version - .#mode {.#Build} - .#configuration (list)] - .#source [provenance.dummy 0 source_code] - .#provenance provenance.dummy - .#current_module {.#Some expected_current_module} - .#modules expected_modules - .#scopes (stack) - .#type_context [.#ex_counter 0 - .#var_counter 0 - .#var_bindings (list)] - .#expected {.#Some {.#Nominal nominal_type (list)}} - .#seed expected_seed - .#eval (as_expected [])])]] + expected_lux_minus_module (is Lux + [.#info [.#target target + .#version version + .#mode {.#Build} + .#configuration (list)] + .#source [provenance.dummy 0 source_code] + .#provenance provenance.dummy + .#current_module {.#None} + .#modules expected_modules + .#scopes (stack) + .#type_context [.#ex_counter 0 + .#var_counter 0 + .#var_bindings (list)] + .#expected {.#Some {.#Nominal nominal_type (list)}} + .#seed expected_seed + .#eval (as_expected [])]) + expected_lux (has .#current_module {.#Some expected_current_module} + expected_lux_minus_module)]] (<| (_.for [.Module .#module_hash .#module_aliases .#definitions .#imports .#module_state]) (all _.and @@ -95,6 +97,11 @@ (!expect (^.multi {try.#Success [actual_current_module actual_module]} (and (text.= expected_current_module actual_current_module) (same? expected_module actual_module)))))) + (_.coverage [/.current_name] + (|> /.current_name + (//.value expected_lux) + (!expect (^.multi {try.#Success actual_current_module} + (text.= expected_current_module actual_current_module))))) (_.coverage [/.by_name] (|> (/.by_name expected_current_module) (//.value expected_lux) diff --git a/stdlib/source/test/lux/type.lux b/stdlib/source/test/lux/type.lux index 1926a0d68..5bb529102 100644 --- a/stdlib/source/test/lux/type.lux +++ b/stdlib/source/test/lux/type.lux @@ -399,230 +399,248 @@ (the .public test Test (<| (_.covering /._) - (all _.and - (_.for [/.equivalence /.=] - (static.when (same? /.equivalence /.=) - (equivalenceT.spec /.equivalence (..random 0)))) - - (monad.let [! random.monad] - [anonymousT (random.only (|>> (pipe.when {.#Named _ _} false - _ true)) - (..random 0)) - name/0 ..name - name/1 ..name - .let [namedT {.#Named name/0 anonymousT} - aliasedT {.#Named name/1 namedT}]] - (all _.and - (_.coverage [/.de_aliased] - (by /.equivalence = namedT (/.de_aliased aliasedT))) - (_.coverage [/.anonymous] - (by /.equivalence = anonymousT (/.anonymous aliasedT))))) - (monad.let [! random.monad] - [size (|> random.natural (by ! each (n.% 3))) - members (|> (..random 0) - (random.only (function (_ type) - (when type - (^.or (/.Sum left right) - (/.Product left right)) - false + (`` (all _.and + (_.for [/.equivalence /.=] + (static.when (same? /.equivalence /.=) + (equivalenceT.spec /.equivalence (..random 0)))) + + (monad.let [! random.monad] + [anonymousT (random.only (|>> (pipe.when {.#Named _ _} false + _ true)) + (..random 0)) + name/0 ..name + name/1 ..name + .let [namedT {.#Named name/0 anonymousT} + aliasedT {.#Named name/1 namedT}]] + (all _.and + (_.coverage [/.de_aliased] + (by /.equivalence = namedT (/.de_aliased aliasedT))) + (_.coverage [/.anonymous] + (by /.equivalence = anonymousT (/.anonymous aliasedT))))) + (monad.let [! random.monad] + [size (|> random.natural (by ! each (n.% 3))) + members (|> (..random 0) + (random.only (function (_ type) + (when type + (^.or (/.Sum left right) + (/.Product left right)) + false - _ - true))) - (list.repeated size) - (list.complete !)) - .let [(open "/#[0]") /.equivalence - (open "list#[0]") (list.equivalence /.equivalence)]] - (`` (all _.and - (,, (template.with [ ] - [(_.coverage [ ] - (let [flat (|> members - - )] - (or (list#= members flat) - (and (list#= (list) members) - (list#= (list ) flat)))))] + _ + true))) + (list.repeated size) + (list.complete !)) + .let [(open "/#[0]") /.equivalence + (open "list#[0]") (list.equivalence /.equivalence)]] + (`` (all _.and + (,, (template.with [ ] + [(_.coverage [ ] + (let [flat (|> members + + )] + (or (list#= members flat) + (and (list#= (list) members) + (list#= (list ) flat)))))] - [[/.variant /.flat_variant Nothing] - [/.tuple /.flat_tuple Any]])) - ))) - (_.coverage [/.reified] - (and (<| (maybe.else false) - (monad.let maybe.monad - [partial (/.reified (list Bit) Annotated) - full (/.reified (list Integer) partial)] - (pure (by /.equivalence = full (/.Product Bit Integer))))) - (|> (/.reified (list Bit) Text) - (pipe.when - {.#None} - true - - _ - false)))) - (monad.let [! random.monad] - [size (|> random.natural (by ! each (n.% 3))) - members (list.complete ! (list.repeated size (..random 0))) - extra (|> (..random 0) - (random.only (function (_ type) - (when type - (/.Function left right) - false - - {.#Reification _} - false - - _ - true)))) - .let [(open "/#[0]") /.equivalence - (open "list#[0]") (list.equivalence /.equivalence)]] - (all _.and - (_.coverage [/.function /.flat_function] - (let [[inputs output] (|> extra - (/.function members) - /.flat_function)] - (and (list#= members inputs) - (/.= extra output)))) - (_.coverage [/.reification /.flat_reification] - (let [[tfunc tparams] (|> extra - (/.reification members) - /.flat_reification)] - (n.= (list.size members) - (list.size tparams)))) - )) - (monad.let [! random.monad] - [size (|> random.natural (by ! each (|>> (n.% 3) ++))) - body_type (|> (..random 0) + [[/.variant /.flat_variant Nothing] + [/.tuple /.flat_tuple Any]])) + ))) + (_.coverage [/.reified] + (and (<| (maybe.else false) + (monad.let maybe.monad + [partial (/.reified (list Bit) Annotated) + full (/.reified (list Integer) partial)] + (pure (by /.equivalence = full (/.Product Bit Integer))))) + (|> (/.reified (list Bit) Text) + (pipe.when + {.#None} + true + + _ + false)))) + (monad.let [! random.monad] + [size (|> random.natural (by ! each (n.% 3))) + members (list.complete ! (list.repeated size (..random 0))) + extra (|> (..random 0) (random.only (function (_ type) (when type - (^.or {.#Quantification .universal _} - {.#Quantification .existential _}) + (/.Function left right) + false + + {.#Reification _} false _ true)))) - .let [(open "/#[0]") /.equivalence]] - (`` (all _.and - (,, (template.with [ ] - [(_.coverage [ ] - (let [[flat_size flat_body] (|> body_type ( size) )] - (and (n.= size flat_size) - (/.= body_type flat_body))))] - - [[/.univ_q /.flat_univ_q] - [/.ex_q /.flat_ex_q]])) - (_.coverage [/.quantified?] - (and (not (/.quantified? body_type)) - (|> body_type (/.univ_q size) /.quantified?) - (|> body_type (/.ex_q size) /.quantified?))) - ))) - (monad.let [! random.monad] - [depth (|> random.natural (by ! each (|>> (n.% 3) ++))) - element_type (|> (..random 0) - (random.only (function (_ type) - (when type - (@type.Array to_write to_read) - false + .let [(open "/#[0]") /.equivalence + (open "list#[0]") (list.equivalence /.equivalence)]] + (all _.and + (_.coverage [/.function /.flat_function] + (let [[inputs output] (|> extra + (/.function members) + /.flat_function)] + (and (list#= members inputs) + (/.= extra output)))) + (_.coverage [/.reification /.flat_reification] + (let [[tfunc tparams] (|> extra + (/.reification members) + /.flat_reification)] + (n.= (list.size members) + (list.size tparams)))) + )) + (monad.let [! random.monad] + [size (|> random.natural (by ! each (|>> (n.% 3) ++))) + body_type (|> (..random 0) + (random.only (function (_ type) + (when type + (^.or {.#Quantification .universal _} + {.#Quantification .existential _}) + false - _ - true)))) - .let [(open "/#[0]") /.equivalence]] - (all _.and - (_.coverage [/.array /.flat_array] - (let [[flat_depth flat_element] (|> element_type (/.array depth) /.flat_array)] - (and (n.= depth flat_depth) - (/.= element_type flat_element)))) - (_.coverage [/.array?] - (and (not (/.array? element_type)) - (/.array? (/.array depth element_type)))) - )) - (_.coverage [/.by_example] - (let [example (is (Maybe Natural) - {.#None})] - (/.= (type (List Natural)) - (/.by_example [it] - (is (Maybe it) - example) - (List it))))) - (monad.let random.monad - [sample random.natural] - (_.coverage [/.log!] - (exec - (/.log! sample) - true))) - (monad.let random.monad - [expected random.natural] - (_.coverage [/.sharing] - (n.= expected - (/.sharing [a] - (is (I64 a) - expected) - (is (I64 a) - (.i64 expected)))))) - (monad.let random.monad - [expected_left random.natural - expected_right random.natural] - (_.coverage [/.let] - (let [[actual_left actual_right] - (is (/.let [side Natural] - [side side]) - [expected_left expected_right])] - (and (same? expected_left actual_left) - (same? expected_right actual_right))))) - (monad.let random.monad - [.let [(open "/#[0]") /.equivalence] - left (..random 0) - right (..random 0)] - (all _.and - (_.coverage [/.code] - (bit.= (/.= left right) - (code.= (/.code left) (/.code right)))) - (_.coverage [/.absolute_text] - (bit.= (/.= left right) - (text.= (/.absolute_text left) (/.absolute_text right)))) - )) - ... (_.coverage [.type] - ... (and (when (type [expected/0 expected/1]) - ... {.#Product actual/0 actual/1} - ... (and (same? expected/0 actual/0) - ... (same? expected/1 actual/1)) + _ + true)))) + .let [(open "/#[0]") /.equivalence]] + (`` (all _.and + (,, (template.with [ ] + [(_.coverage [ ] + (let [[flat_size flat_body] (|> body_type ( size) )] + (and (n.= size flat_size) + (/.= body_type flat_body))))] - ... _ - ... false) - ... (when (type (/.Or expected/0 expected/1)) - ... {.#Sum actual/0 actual/1} - ... (and (same? expected/0 actual/0) - ... (same? expected/1 actual/1)) + [[/.univ_q /.flat_univ_q] + [/.ex_q /.flat_ex_q]])) + (_.coverage [/.quantified?] + (and (not (/.quantified? body_type)) + (|> body_type (/.univ_q size) /.quantified?) + (|> body_type (/.ex_q size) /.quantified?))) + ))) + (monad.let [! random.monad] + [depth (|> random.natural (by ! each (|>> (n.% 3) ++))) + element_type (|> (..random 0) + (random.only (function (_ type) + (when type + (@type.Array to_write to_read) + false - ... _ - ... false) - ... (when (type (-> expected/0 expected/1)) - ... {.#Function actual/0 actual/1} - ... (and (same? expected/0 actual/0) - ... (same? expected/1 actual/1)) + _ + true)))) + .let [(open "/#[0]") /.equivalence]] + (all _.and + (_.coverage [/.array /.flat_array] + (let [[flat_depth flat_element] (|> element_type (/.array depth) /.flat_array)] + (and (n.= depth flat_depth) + (/.= element_type flat_element)))) + (_.coverage [/.array?] + (and (not (/.array? element_type)) + (/.array? (/.array depth element_type)))) + )) + (_.coverage [/.by_example] + (let [example (is (Maybe Natural) + {.#None})] + (/.= (type (List Natural)) + (/.by_example [it] + (is (Maybe it) + example) + (List it))))) + (monad.let random.monad + [sample random.natural] + (_.coverage [/.log!] + (exec + (/.log! sample) + true))) + (monad.let random.monad + [expected random.natural] + (_.coverage [/.sharing] + (n.= expected + (/.sharing [a] + (is (I64 a) + expected) + (is (I64 a) + (.i64 expected)))))) + (monad.let random.monad + [expected_left random.natural + expected_right random.natural] + (_.coverage [/.let] + (let [[actual_left actual_right] + (is (/.let [side Natural] + [side side]) + [expected_left expected_right])] + (and (same? expected_left actual_left) + (same? expected_right actual_right))))) + (<| (monad.let random.monad + [left (..random 0) + right (random.only (|>> (/.= left) not) + (..random 0))]) + (all _.and + (_.coverage [/.code] + (bit.= (/.= left right) + (code.= (/.code left) (/.code right)))) + (_.coverage [/.Sum] + (/.= (Or left right) + (/.Sum left right))) + (_.coverage [/.Product] + (/.= (And left right) + (/.Product left right))) + (_.coverage [/.Function] + (/.= (-> left right) + (/.Function left right))) + (_.coverage [/.replaced] + (let [no_match + (/.= right + (/.replaced left left right)) - ... _ - ... false) - ... (when (type (expected/0 expected/1)) - ... {.#Reification actual/1 actual/0} - ... (and (same? expected/0 actual/0) - ... (same? expected/1 actual/1)) + direct_match + (/.= right + (/.replaced left right left))] + (and no_match + direct_match + (/.= (Or right right) + (/.replaced left right (Or left left))) + (/.= (And right right) + (/.replaced left right (And left left))) + (/.= (-> right right) + (/.replaced left right (-> left left))) + (/.= (type (right right)) + (/.replaced left right (type (left left)))) + (/.= (for_any (_ it) right) + (/.replaced left right (for_any (_ it) left))) + (/.= (for_some (_ it) right) + (/.replaced left right (for_some (_ it) left)))))) + (monad.let random.monad + [module (random.lower_cased 2) + proper (random.lower_cased 2) + .let [name (is Name + [module proper])]] + (_.coverage [/.absolute_text /.relative_text] + (and (text.= (by name.absolute as name) + (/.absolute_text {.#Named name left})) + (text.= (by (name.relative module) as name) + (/.relative_text module {.#Named name left}))))) + (_.coverage [/.as_text] + (same? /.absolute_text /.as_text)))) + (,, (template.with [,type ,0 ,1] + [(_.coverage [,type ,0 ,1] + (bit.= (not ,0) + ,1))] - ... _ - ... false))) + [[.Polarity .co_variant .contra_variant] + [.Quantification .universal .existential] + [.Parameter .abstraction .argument]])) - ..\\projection + ..\\projection - /nominal.test - /check.test - /dynamic.test - /quotient.test - /refinement.test - /linear.test - /unit.test - /variance.test - /poly.test - /row.test - /brand.test - /record.test - /function.test - (/environment.test (..random 0)) - ))) + /nominal.test + /check.test + /dynamic.test + /quotient.test + /refinement.test + /linear.test + /unit.test + /variance.test + /poly.test + /row.test + /brand.test + /record.test + /function.test + (/environment.test (..random 0)) + ))))