From 841778afcbdba83edd1e5d90049221b7ac1776dc Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sat, 30 Mar 2019 00:16:35 -0400 Subject: Fixed some more tests. --- stdlib/source/lux/data/number/rev.lux | 5 ++++- stdlib/source/lux/math/random.lux | 12 ++++++++++-- stdlib/source/test/lux.lux | 3 +-- stdlib/source/test/lux/data/color.lux | 16 ++++++++-------- stdlib/source/test/lux/data/number/complex.lux | 23 +++++++++++------------ stdlib/source/test/lux/math.lux | 8 ++++---- 6 files changed, 38 insertions(+), 29 deletions(-) (limited to 'stdlib/source') diff --git a/stdlib/source/lux/data/number/rev.lux b/stdlib/source/lux/data/number/rev.lux index fcd2e223c..7a8fe53da 100644 --- a/stdlib/source/lux/data/number/rev.lux +++ b/stdlib/source/lux/data/number/rev.lux @@ -59,7 +59,10 @@ (structure: #export (Codec Text Rev) (def: (encode value) (let [raw-output (:: encode (:coerce Nat value)) - max-num-chars (n// 64) + max-num-chars (n/+ (n// 64) + (case (n/% 64) + 0 0 + _ 1)) raw-size ("lux text size" raw-output) zero-padding (loop [zeroes-left (n/- raw-size max-num-chars) output ""] diff --git a/stdlib/source/lux/math/random.lux b/stdlib/source/lux/math/random.lux index 24fa17dbe..d998168d4 100644 --- a/stdlib/source/lux/math/random.lux +++ b/stdlib/source/lux/math/random.lux @@ -113,6 +113,14 @@ (Random Frac) (:: ..monad map frac.bits-to-frac ..nat)) +(def: #export safe-frac + (Random Frac) + (:: ..monad map + (|>> (i/% +1,000,000) + .int-to-frac + (f// +1,000,000.0)) + ..int)) + (def: #export (char set) (-> unicode.Set (Random Char)) (let [summary (finger.tag set) @@ -156,8 +164,8 @@ right ] (wrap ( left right))))] - [ratio r.Ratio r.ratio nat] - [complex c.Complex c.complex frac] + [ratio r.Ratio r.ratio ..nat] + [complex c.Complex c.complex ..safe-frac] ) (def: #export (and left right) diff --git a/stdlib/source/test/lux.lux b/stdlib/source/test/lux.lux index a52c70fd4..f830f8215 100644 --- a/stdlib/source/test/lux.lux +++ b/stdlib/source/test/lux.lux @@ -375,6 +375,5 @@ (program: args (<| io _.run! - ## (_.times 100) - (_.seed 4035274984803317370) + (_.times 100) ..test)) diff --git a/stdlib/source/test/lux/data/color.lux b/stdlib/source/test/lux/data/color.lux index f5ac95d90..ed69ddf7c 100644 --- a/stdlib/source/test/lux/data/color.lux +++ b/stdlib/source/test/lux/data/color.lux @@ -11,12 +11,12 @@ [number ["." frac ("#@." number)]]] ["." math - ["r" random]]] + ["r" random (#+ Random)]]] {1 - ["." /]}) + ["." / (#+ Color)]}) -(def: color - (r.Random /.Color) +(def: #export color + (Random Color) (|> ($_ r.and r.nat r.nat r.nat) (:: r.monad map /.from-rgb))) @@ -27,7 +27,7 @@ (def: square (-> Frac Frac) (math.pow +2.0)) (def: (distance from to) - (-> /.Color /.Color Frac) + (-> Color Color Frac) (let [[fr fg fb] (/.to-rgb from) [tr tg tb] (/.to-rgb to)] (math.pow +0.5 ($_ f/+ @@ -42,7 +42,7 @@ (do-template [] [(def: ( color) - (-> /.Color Frac) + (-> Color Frac) (let [[hue saturation luminance] (/.to-hsl color)] ))] @@ -52,7 +52,7 @@ (def: #export test Test - (<| (_.context (%name (name-of /.Color))) + (<| (_.context (%name (name-of /._))) (do r.monad [any ..color colorful (|> color @@ -63,7 +63,7 @@ ((function (_ saturation) (and (f/>= +0.25 saturation) (f/<= +0.75 saturation))))))) - ratio (|> r.frac (r.filter (f/>= +0.5)))] + ratio (|> r.safe-frac (r.filter (f/>= +0.5)))] ($_ _.and ($equivalence.spec /.equivalence ..color) (_.test "Can convert to/from HSL." diff --git a/stdlib/source/test/lux/data/number/complex.lux b/stdlib/source/test/lux/data/number/complex.lux index 19db6081d..a1fc7beca 100644 --- a/stdlib/source/test/lux/data/number/complex.lux +++ b/stdlib/source/test/lux/data/number/complex.lux @@ -35,7 +35,7 @@ (Random Frac) (do r.monad [factor (|> r.nat (:: @ map (|>> (n/% 1000) (n/max 1)))) - measure (|> r.frac (r.filter (f/> +0.0)))] + measure (|> r.safe-frac (r.filter (f/> +0.0)))] (wrap (f/* (|> factor .int int-to-frac) measure)))) @@ -158,17 +158,16 @@ (def: trigonometry Test - (<| (_.seed 17274883666004960943) - (do r.monad - [angle (|> ..complex (:: @ map (|>> (update@ #/.real (f/% +1.0)) - (update@ #/.imaginary (f/% +1.0)))))] - ($_ _.and - (_.test "Arc-sine is the inverse of sine." - (trigonometric-symmetry /.sin /.asin angle)) - (_.test "Arc-cosine is the inverse of cosine." - (trigonometric-symmetry /.cos /.acos angle)) - (_.test "Arc-tangent is the inverse of tangent." - (trigonometric-symmetry /.tan /.atan angle)))))) + (do r.monad + [angle (|> ..complex (:: @ map (|>> (update@ #/.real (f/% +1.0)) + (update@ #/.imaginary (f/% +1.0)))))] + ($_ _.and + (_.test "Arc-sine is the inverse of sine." + (trigonometric-symmetry /.sin /.asin angle)) + (_.test "Arc-cosine is the inverse of cosine." + (trigonometric-symmetry /.cos /.acos angle)) + (_.test "Arc-tangent is the inverse of tangent." + (trigonometric-symmetry /.tan /.atan angle))))) (def: exponentiation&logarithm Test diff --git a/stdlib/source/test/lux/math.lux b/stdlib/source/test/lux/math.lux index 79143b815..a659e8095 100644 --- a/stdlib/source/test/lux/math.lux +++ b/stdlib/source/test/lux/math.lux @@ -2,7 +2,7 @@ [lux #* data/text/format ["_" test (#+ Test)] - ["r" math/random] + ["r" math/random (#+ Random)] [control [monad (#+ Monad do)]] [data @@ -35,7 +35,7 @@ ($_ _.and (<| (_.context "Trigonometry") (do r.monad - [angle (|> r.frac (:: @ map (f/* /.tau)))] + [angle (|> r.safe-frac (:: @ map (f/* /.tau)))] ($_ _.and (_.test "Sine and arc-sine are inverse functions." (trigonometric-symmetry /.sin /.asin angle)) @@ -46,7 +46,7 @@ ))) (<| (_.context "Rounding") (do r.monad - [sample (|> r.frac (:: @ map (f/* +1000.0)))] + [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)] @@ -65,7 +65,7 @@ ))) (<| (_.context "Exponentials and logarithms") (do r.monad - [sample (|> r.frac (:: @ map (f/* +10.0)))] + [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") -- cgit v1.2.3