From df0e015145981602b3f97113bcfa586b4f6d0757 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sun, 20 Nov 2022 18:55:23 -0400 Subject: Fixed a bug when optimization record access. --- stdlib/source/test/lux/control/parser.lux | 6 +- stdlib/source/test/lux/data/color.lux | 10 +-- stdlib/source/test/lux/data/color/cmyk.lux | 90 ++++++++++++++++++++++ .../meta/compiler/language/lux/analysis/scope.lux | 2 +- .../meta/compiler/language/lux/phase/extension.lux | 2 +- stdlib/source/test/lux/meta/compiler/phase.lux | 6 +- stdlib/source/test/lux/meta/extension.lux | 10 +-- 7 files changed, 107 insertions(+), 19 deletions(-) create mode 100644 stdlib/source/test/lux/data/color/cmyk.lux (limited to 'stdlib/source/test') diff --git a/stdlib/source/test/lux/control/parser.lux b/stdlib/source/test/lux/control/parser.lux index 10e897f03..7a8a37245 100644 --- a/stdlib/source/test/lux/control/parser.lux +++ b/stdlib/source/test/lux/control/parser.lux @@ -357,12 +357,12 @@ (|> (list) (/.result (/.failure failure)) (should_fail failure))) - (_.coverage [/.lifted] + (_.coverage [/.of_try] (and (|> (list) - (/.result (/.lifted {try.#Success expected})) + (/.result (/.of_try {try.#Success expected})) (match actual (n.= expected actual))) (|> (list) - (/.result (/.lifted {try.#Failure failure})) + (/.result (/.of_try {try.#Failure failure})) (should_fail failure)))) (_.coverage [/.assertion] (and (|> (list (code.bit #1) (code.int +123)) diff --git a/stdlib/source/test/lux/data/color.lux b/stdlib/source/test/lux/data/color.lux index e53d5d0b7..7434e8c15 100644 --- a/stdlib/source/test/lux/data/color.lux +++ b/stdlib/source/test/lux/data/color.lux @@ -24,6 +24,7 @@ ["[0]" rgb]]] ["[0]" / ["[1][0]" rgb] + ["[1][0]" cmyk] ["[1][0]" named] ["[1][0]" terminal]]) @@ -86,18 +87,14 @@ (|> expected /.hsb /.of_hsb (distance/3 expected) (f.<= ..rgb_error_margin))) - (_.coverage [/.CMYK /.cmyk /.of_cmyk] - (|> expected /.cmyk /.of_cmyk - (distance/3 expected) - (f.<= ..rgb_error_margin))) )) (def transformation Test (do random.monad [colorful (|> ..random - (random.only (function (_ color) (|> (distance/3 color /.black) (f.>= +100.0)))) - (random.only (function (_ color) (|> (distance/3 color /.white) (f.>= +100.0))))) + (random.only (function (_ color) (and (|> (distance/3 color /.black) (f.>= +100.0)) + (|> (distance/3 color /.white) (f.>= +100.0)))))) mediocre (|> ..random (random.only (|>> saturation ((function (_ saturation) @@ -217,6 +214,7 @@ )) /rgb.test + /cmyk.test /named.test /terminal.test )))) diff --git a/stdlib/source/test/lux/data/color/cmyk.lux b/stdlib/source/test/lux/data/color/cmyk.lux new file mode 100644 index 000000000..4a9736762 --- /dev/null +++ b/stdlib/source/test/lux/data/color/cmyk.lux @@ -0,0 +1,90 @@ +(.require + [library + [lux (.except) + [abstract + [monad (.only do)] + [\\specification + ["[0]S" equivalence]]] + [control + ["[0]" try (.use "[1]#[0]" functor)] + ["[0]" exception]] + [math + ["[0]" random (.only Random)] + [number + ["f" frac]]] + [test + ["_" property (.only Test)]]]] + [\\library + ["[0]" / (.only) + [// + ["[0]" rgb]]]] + [// + ["[0]T" rgb]]) + +(def .public value + (Random /.Value) + (random.one (|>> /.value try.maybe) + random.safe_frac)) + +(def .public random + (Random /.CMYK) + (do random.monad + [cyan ..value + magenta ..value + yellow ..value + key ..value] + (in [/.#cyan cyan + /.#magenta magenta + /.#yellow yellow + /.#key key]))) + +(def .public test + Test + (<| (_.covering /._) + (do [! random.monad] + [expected_value ..value + expected_rgb rgbT.random + expected_cmyk ..random]) + (all _.and + (_.for [/.Value] + (all _.and + (_.coverage [/.number /.value] + (|> expected_value + /.number + /.value + (try#each (|>> /.number + (f.= (/.number expected_value)))) + (try.else false))) + (_.coverage [/.least] + (when (/.value (f.+ +0.001 (/.number /.least))) + {try.#Failure _} false + {try.#Success _} true)) + (_.coverage [/.most] + (when (/.value (f.- +0.001 (/.number /.most))) + {try.#Failure _} false + {try.#Success _} true)) + (_.coverage [/.invalid] + (and (when (/.value (f.- +0.001 (/.number /.least))) + {try.#Failure it} (exception.match? /.invalid it) + {try.#Success _} false) + (when (/.value (f.+ +0.001 (/.number /.most))) + {try.#Failure it} (exception.match? /.invalid it) + {try.#Success _} false))) + )) + (_.for [/.CMYK + /.#cyan /.#magenta /.#yellow /.#key] + (all _.and + (_.for [/.equivalence] + (equivalenceS.spec /.equivalence ..random)) + + (_.coverage [/.cmyk /.rgb] + (and (|> expected_rgb + /.cmyk + /.rgb + (at rgb.equivalence = expected_rgb)) + (|> expected_cmyk + /.rgb + /.cmyk + (at /.equivalence = expected_cmyk)))) + )) + ))) diff --git a/stdlib/source/test/lux/meta/compiler/language/lux/analysis/scope.lux b/stdlib/source/test/lux/meta/compiler/language/lux/analysis/scope.lux index f4fd18a31..0e833953f 100644 --- a/stdlib/source/test/lux/meta/compiler/language/lux/analysis/scope.lux +++ b/stdlib/source/test/lux/meta/compiler/language/lux/analysis/scope.lux @@ -143,7 +143,7 @@ (do //phase.monad [var/0' (/.variable name/0) [scope/1 var/0''] (/.with (/.variable name/0))] - (<| //phase.lifted + (<| //phase.of_try try.of_maybe (do maybe.monad [var/0' var/0' diff --git a/stdlib/source/test/lux/meta/compiler/language/lux/phase/extension.lux b/stdlib/source/test/lux/meta/compiler/language/lux/phase/extension.lux index 138dd3f82..f108a9334 100644 --- a/stdlib/source/test/lux/meta/compiler/language/lux/phase/extension.lux +++ b/stdlib/source/test/lux/meta/compiler/language/lux/phase/extension.lux @@ -216,7 +216,7 @@ /.#state state]) (try.else false)) (|> (is (/.Operation Int Nat Nat Nat) - (/.lifted (phase.lifted {try.#Failure expected_error}))) + (/.lifted (phase.of_try {try.#Failure expected_error}))) (phase.result [/.#bundle /.empty /.#state state]) (pipe.when diff --git a/stdlib/source/test/lux/meta/compiler/phase.lux b/stdlib/source/test/lux/meta/compiler/phase.lux index 963dd07fd..d3b55aaf3 100644 --- a/stdlib/source/test/lux/meta/compiler/phase.lux +++ b/stdlib/source/test/lux/meta/compiler/phase.lux @@ -60,15 +60,15 @@ _ false))) - (_.coverage [/.lifted] - (and (|> (/.lifted {try.#Failure expected_error}) + (_.coverage [/.of_try] + (and (|> (/.of_try {try.#Failure expected_error}) (/.result state) (pipe.when {try.#Failure actual_error} (same? expected_error actual_error) _ false)) - (|> (/.lifted {try.#Success expected}) + (|> (/.of_try {try.#Success expected}) (at /.functor each (same? expected)) (/.result state) (try.else false)))) diff --git a/stdlib/source/test/lux/meta/extension.lux b/stdlib/source/test/lux/meta/extension.lux index 4391469e0..64905a9f2 100644 --- a/stdlib/source/test/lux/meta/extension.lux +++ b/stdlib/source/test/lux/meta/extension.lux @@ -149,21 +149,21 @@ (do [! phase.monad] [.let [[_ self] (symbol ..my_declaration)] analysis_phase declaration.analysis - expressionA (<| declaration.lifted_analysis + expressionA (<| declaration.of_analysis (type.expecting .Any) (analysis_phase archive expression)) - lux (declaration.lifted_analysis meta.compiler_state) + lux (declaration.of_analysis meta.compiler_state) synthesis_phase declaration.synthesis - expressionS (declaration.lifted_synthesis + expressionS (declaration.of_synthesis (synthesis_phase lux archive expressionA)) translation_phase declaration.translation - expressionG (declaration.lifted_translation + expressionG (declaration.of_translation (translation_phase lux archive expressionS)) - _ (declaration.lifted_translation + _ (declaration.of_translation (translation.with_new_context archive unit.none (do ! [[module_id artifact_id] (translation.context archive) -- cgit v1.2.3