aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/test')
-rw-r--r--stdlib/source/test/lux/debug.lux7
-rw-r--r--stdlib/source/test/lux/math.lux5
-rw-r--r--stdlib/source/test/lux/math/arithmetic/saturation.lux51
3 files changed, 60 insertions, 3 deletions
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 <body>
_ (io.run! (sys::stdout old))]
[(io/StringIO::getvalue buffer)
- output]))]))
+ output])
+ @.lua [""
+ <body>])]))
(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!)))
+ )))