diff options
-rw-r--r-- | stdlib/source/lux/data/number.lux | 8 | ||||
-rw-r--r-- | stdlib/test/test/lux/data/number.lux | 29 |
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>] |