aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEduardo Julian2019-03-30 00:16:35 -0400
committerEduardo Julian2019-03-30 00:16:35 -0400
commit841778afcbdba83edd1e5d90049221b7ac1776dc (patch)
treeb2619a80a3b376799273377e18187d5d029f508e
parent6bb6029f426ecb2da772f6f9c70cdb81c897f0db (diff)
Fixed some more tests.
Diffstat (limited to '')
-rw-r--r--stdlib/source/lux/data/number/rev.lux5
-rw-r--r--stdlib/source/lux/math/random.lux12
-rw-r--r--stdlib/source/test/lux.lux3
-rw-r--r--stdlib/source/test/lux/data/color.lux16
-rw-r--r--stdlib/source/test/lux/data/number/complex.lux23
-rw-r--r--stdlib/source/test/lux/math.lux8
6 files changed, 38 insertions, 29 deletions
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 <struct> (Codec Text Rev)
(def: (encode value)
(let [raw-output (:: <codec> encode (:coerce Nat value))
- max-num-chars (n// <char-bit-size> 64)
+ max-num-chars (n/+ (n// <char-bit-size> 64)
+ (case (n/% <char-bit-size> 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 <gen>]
(wrap (<ctor> 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 [<field>]
[(def: (<field> color)
- (-> /.Color Frac)
+ (-> Color Frac)
(let [[hue saturation luminance] (/.to-hsl color)]
<field>))]
@@ -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")