diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/test/lux/math.lux | 117 |
1 files changed, 59 insertions, 58 deletions
diff --git a/stdlib/source/test/lux/math.lux b/stdlib/source/test/lux/math.lux index fcd4a1134..c11380015 100644 --- a/stdlib/source/test/lux/math.lux +++ b/stdlib/source/test/lux/math.lux @@ -31,63 +31,64 @@ (def: #export test Test - ($_ _.and - (<| (_.context "Trigonometry") - (do r.monad - [angle (|> r.safe-frac (:: @ map (f/* /.tau)))] - ($_ _.and - (_.test "Sine and arc-sine are inverse functions." - (trigonometric-symmetry /.sin /.asin angle)) - (_.test "Cosine and arc-cosine are inverse functions." - (trigonometric-symmetry /.cos /.acos angle)) - (_.test "Tangent and arc-tangent are inverse functions." - (trigonometric-symmetry /.tan /.atan angle)) - ))) - (<| (_.context "Rounding") - (do r.monad - [sample (|> r.safe-frac (:: @ map (f/* +1000.0)))] - ($_ _.and - (_.test "The ceiling will be an integer value, and will be >= the original." - (let [ceil'd (/.ceil sample)] - (and (|> ceil'd frac-to-int int-to-frac (f/= ceil'd)) - (f/>= sample ceil'd) - (f/<= +1.0 (f/- sample ceil'd))))) - (_.test "The floor will be an integer value, and will be <= the original." - (let [floor'd (/.floor sample)] - (and (|> floor'd frac-to-int int-to-frac (f/= floor'd)) - (f/<= sample floor'd) - (f/<= +1.0 (f/- floor'd sample))))) - (_.test "The round will be an integer value, and will be < or > or = the original." - (let [round'd (/.round sample)] - (and (|> round'd frac-to-int int-to-frac (f/= round'd)) - (f/<= +1.0 (frac@abs (f/- sample round'd)))))) - ))) - (<| (_.context "Exponentials and logarithms") - (do r.monad - [sample (|> r.safe-frac (:: @ map (f/* +10.0)))] - (_.test "Logarithm is the inverse of exponential." - (|> sample /.exp /.log (within? +1.0e-15 sample))))) - (<| (_.context "Greatest-Common-Divisor and Least-Common-Multiple") - (do r.monad - [#let [gen-nat (|> r.nat (:: @ map (|>> (n/% 1000) (n/max 1))))] - x gen-nat - y gen-nat] - ($_ _.and - (_.test "GCD" - (let [gcd (/.n/gcd x y)] - (and (n/= 0 (n/% gcd x)) - (n/= 0 (n/% gcd y)) - (n/>= 1 gcd)))) + (<| (_.context (%name (name-of /._))) + ($_ _.and + (<| (_.context "Trigonometry") + (do r.monad + [angle (|> r.safe-frac (:: @ map (f/* /.tau)))] + ($_ _.and + (_.test "Sine and arc-sine are inverse functions." + (trigonometric-symmetry /.sin /.asin angle)) + (_.test "Cosine and arc-cosine are inverse functions." + (trigonometric-symmetry /.cos /.acos angle)) + (_.test "Tangent and arc-tangent are inverse functions." + (trigonometric-symmetry /.tan /.atan angle)) + ))) + (<| (_.context "Rounding") + (do r.monad + [sample (|> r.safe-frac (:: @ map (f/* +1000.0)))] + ($_ _.and + (_.test "The ceiling will be an integer value, and will be >= the original." + (let [ceil'd (/.ceil sample)] + (and (|> ceil'd frac-to-int int-to-frac (f/= ceil'd)) + (f/>= sample ceil'd) + (f/<= +1.0 (f/- sample ceil'd))))) + (_.test "The floor will be an integer value, and will be <= the original." + (let [floor'd (/.floor sample)] + (and (|> floor'd frac-to-int int-to-frac (f/= floor'd)) + (f/<= sample floor'd) + (f/<= +1.0 (f/- floor'd sample))))) + (_.test "The round will be an integer value, and will be < or > or = the original." + (let [round'd (/.round sample)] + (and (|> round'd frac-to-int int-to-frac (f/= round'd)) + (f/<= +1.0 (frac@abs (f/- sample round'd)))))) + ))) + (<| (_.context "Exponentials and logarithms") + (do r.monad + [sample (|> r.safe-frac (:: @ map (f/* +10.0)))] + (_.test "Logarithm is the inverse of exponential." + (|> sample /.exp /.log (within? +1.0e-15 sample))))) + (<| (_.context "Greatest-Common-Divisor and Least-Common-Multiple") + (do r.monad + [#let [gen-nat (|> r.nat (:: @ map (|>> (n/% 1000) (n/max 1))))] + x gen-nat + y gen-nat] + ($_ _.and + (_.test "GCD" + (let [gcd (/.n/gcd x y)] + (and (n/= 0 (n/% gcd x)) + (n/= 0 (n/% gcd y)) + (n/>= 1 gcd)))) - (_.test "LCM" - (let [lcm (/.n/lcm x y)] - (and (n/= 0 (n/% x lcm)) - (n/= 0 (n/% y lcm)) - (n/<= (n/* x y) lcm)))) - ))) + (_.test "LCM" + (let [lcm (/.n/lcm x y)] + (and (n/= 0 (n/% x lcm)) + (n/= 0 (n/% y lcm)) + (n/<= (n/* x y) lcm)))) + ))) - /infix.test - /modular.test - /logic/continuous.test - /logic/fuzzy.test - )) + /infix.test + /modular.test + /logic/continuous.test + /logic/fuzzy.test + ))) |