From 09a29c952edb851e13edd454bd118c1c1ae83ade Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Fri, 25 Nov 2022 01:26:00 -0400 Subject: Added support for saturation arithmetic. --- stdlib/source/test/lux/debug.lux | 7 ++- stdlib/source/test/lux/math.lux | 5 ++- .../source/test/lux/math/arithmetic/saturation.lux | 51 ++++++++++++++++++++++ 3 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 stdlib/source/test/lux/math/arithmetic/saturation.lux (limited to 'stdlib/source/test') diff --git a/stdlib/source/test/lux/debug.lux b/stdlib/source/test/lux/debug.lux index 17a0a1a31..bf54deb21 100644 --- a/stdlib/source/test/lux/debug.lux +++ b/stdlib/source/test/lux/debug.lux @@ -295,7 +295,9 @@ output _ (io.run! (sys::stdout old))] [(io/StringIO::getvalue buffer) - output]))])) + output]) + @.lua ["" + ])])) (def .public test Test @@ -330,7 +332,8 @@ /.inspection) true)) (_.coverage [/.log!] - (let [[actual_message _] (with_out (/.log! expected_message))] + (let [[actual_message _] (with_out + (/.log! expected_message))] (text#= (format expected_message text.\n) actual_message))) )))) diff --git a/stdlib/source/test/lux/math.lux b/stdlib/source/test/lux/math.lux index db993c324..6cee94642 100644 --- a/stdlib/source/test/lux/math.lux +++ b/stdlib/source/test/lux/math.lux @@ -29,7 +29,9 @@ ["[1][0]" random] ["[1][0]" logic ["[1]/[0]" continuous] - ["[1]/[0]" fuzzy]]]) + ["[1]/[0]" fuzzy]] + ["[1][0]" arithmetic + ["[1]/[0]" saturation]]]) (def ratio/0 Ratio @@ -145,4 +147,5 @@ /random.test /logic/continuous.test /logic/fuzzy.test + /arithmetic/saturation.test )))) diff --git a/stdlib/source/test/lux/math/arithmetic/saturation.lux b/stdlib/source/test/lux/math/arithmetic/saturation.lux new file mode 100644 index 000000000..3ef3adb94 --- /dev/null +++ b/stdlib/source/test/lux/math/arithmetic/saturation.lux @@ -0,0 +1,51 @@ +(.require + [library + [lux (.except) + [abstract + [monad (.only do)]] + [math + ["[0]" random (.only Random)] + [number + ["n" nat]]] + [test + ["_" property (.only Test)]]]] + [\\library + ["[0]" /]]) + +(def (within_boundaries? [min max] it) + (-> [Nat Nat] Nat + Bit) + (and (n.<= max it) + (n.>= min it))) + +(def .public test + Test + (<| (_.covering /._) + (do [! random.monad] + [left random.nat + right random.nat + .let [max (n.max left right) + min (n.min left right)] + + parameter (random.only (n.> 0) random.nat) + subject random.nat]) + (all _.and + (_.coverage [/.arithmetic] + (let [boundaries_are_respected! + (let [(open "/#[0]") (/.arithmetic n.order [min max] n.arithmetic)] + (and (within_boundaries? [min max] (/#+ parameter subject)) + (within_boundaries? [min max] (/#- parameter subject)) + (within_boundaries? [min max] (/#* parameter subject)) + (within_boundaries? [min max] (/#/ parameter subject)) + (within_boundaries? [min max] (/#% parameter subject)))) + + the_order_of_the_boundaries_does_not_matter! + (let [(open "/#[0]") (/.arithmetic n.order [max min] n.arithmetic)] + (and (within_boundaries? [min max] (/#+ parameter subject)) + (within_boundaries? [min max] (/#- parameter subject)) + (within_boundaries? [min max] (/#* parameter subject)) + (within_boundaries? [min max] (/#/ parameter subject)) + (within_boundaries? [min max] (/#% parameter subject))))] + (and boundaries_are_respected! + the_order_of_the_boundaries_does_not_matter!))) + ))) -- cgit v1.2.3