aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEduardo Julian2016-12-25 13:29:42 -0400
committerEduardo Julian2016-12-25 13:29:42 -0400
commit83140c8ff4e91d622da1c549daad22f7c368bc8f (patch)
treed47143ae745fbf6f2bc3a6fe31eb6174388b585b
parent70cc416bbf70fd7585ee9f374d6f7e5b7609d082 (diff)
- Fixed a bug where the Frac max value was getting confused with the min value.
- Updated the lux/data/number tests.
Diffstat (limited to '')
-rw-r--r--stdlib/source/lux/data/number.lux8
-rw-r--r--stdlib/test/test/lux/data/number.lux29
2 files changed, 21 insertions, 16 deletions
diff --git a/stdlib/source/lux/data/number.lux b/stdlib/source/lux/data/number.lux
index 8b3081d14..7d33da387 100644
--- a/stdlib/source/lux/data/number.lux
+++ b/stdlib/source/lux/data/number.lux
@@ -107,10 +107,10 @@
(def: top <top>)
(def: bottom <bottom>))]
- [ Nat (_lux_proc ["nat" "max-value"] []) (_lux_proc ["nat" "min-value"] [])]
- [ Int (_lux_proc ["jvm" "getstatic:java.lang.Long:MAX_VALUE"] []) (_lux_proc ["jvm" "getstatic:java.lang.Long:MIN_VALUE"] [])]
- [Real (_lux_proc ["jvm" "getstatic:java.lang.Double:MAX_VALUE"] []) (_lux_proc ["jvm" "getstatic:java.lang.Double:MIN_VALUE"] [])]
- [Frac (_lux_proc ["frac" "max-value"] []) (_lux_proc ["frac" "max-value"] [])])
+ [ Nat (_lux_proc ["nat" "max-value"] []) (_lux_proc ["nat" "min-value"] [])]
+ [ Int (_lux_proc ["jvm" "getstatic:java.lang.Long:MAX_VALUE"] []) (_lux_proc ["jvm" "getstatic:java.lang.Long:MIN_VALUE"] [])]
+ [Real (_lux_proc ["jvm" "getstatic:java.lang.Double:MAX_VALUE"] []) (_lux_proc ["jvm" "getstatic:java.lang.Double:MIN_VALUE"] [])]
+ [Frac (_lux_proc ["frac" "max-value"] []) (_lux_proc ["frac" "min-value"] [])])
(do-template [<name> <type> <unit> <append>]
[(struct: #export <name> (Monoid <type>)
diff --git a/stdlib/test/test/lux/data/number.lux b/stdlib/test/test/lux/data/number.lux
index dcd27745e..d5d60a9ce 100644
--- a/stdlib/test/test/lux/data/number.lux
+++ b/stdlib/test/test/lux/data/number.lux
@@ -8,7 +8,7 @@
(lux (codata [io])
(control monad)
(data number
- [text "Text/" Monoid<Text>]
+ [text "Text/" Monoid<Text> Eq<Text>]
text/format)
(math ["R" random])
pipe)
@@ -31,17 +31,22 @@
(do-template [category rand-gen <Number>]
[(test: (format "[" category "] " "Number")
- [x rand-gen]
- (assert "" (let [(^open) <Number>]
- (and (>= x (abs x))
- (<= x (negate (abs x)))
- (= x (* (signum x)
- (abs x)))))))]
-
- ["Nat" R;nat Number<Nat>]
+ [x rand-gen
+ #let [(^open) <Number>]]
+ (assert "" (and (>= x (abs x))
+ ## abs(0.0) == 0.0 && negate(abs(0.0)) == -0.0
+ (or (Text/= "Real" category)
+ (not (= x (negate x))))
+ (= x (negate (negate x)))
+ ## There is loss of precision when multiplying
+ (or (Text/= "Frac" category)
+ (= x (* (signum x)
+ (abs x)))))))]
+
+ ## ["Nat" R;nat Number<Nat>]
["Int" R;int Number<Int>]
["Real" R;real Number<Real>]
- ## ["Frac" R;frac Number<Frac>]
+ ["Frac" R;frac Number<Frac>]
)
(do-template [category rand-gen <Enum> <Number>]
@@ -74,7 +79,7 @@
["Int" R;int Number<Int> Bounded<Int> (lambda [_] true)]
## Both min and max values will be positive (thus, greater than zero)
["Real" R;real Number<Real> Bounded<Real> (r.> 0.0)]
- ## ["Frac" R;frac Number<Frac> Bounded<Frac> (lambda [_] true)]
+ ["Frac" R;frac Number<Frac> Bounded<Frac> (lambda [_] true)]
)
(do-template [category rand-gen <Number> <Monoid> <cap> <test>]
@@ -121,7 +126,7 @@
["Nat" R;nat Number<Nat> Codec<Text,Nat>]
["Int" R;int Number<Int> Codec<Text,Int>]
["Real" R;real Number<Real> Codec<Text,Real>]
- ## ["Frac" R;frac Number<Frac> Codec<Text,Frac>]
+ ["Frac" R;frac Number<Frac> Codec<Text,Frac>]
)
(do-template [<category> <rand-gen> <Number> <Codec>]