From 83140c8ff4e91d622da1c549daad22f7c368bc8f Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sun, 25 Dec 2016 13:29:42 -0400 Subject: - Fixed a bug where the Frac max value was getting confused with the min value. - Updated the lux/data/number tests. --- stdlib/source/lux/data/number.lux | 8 ++++---- 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 ) (def: 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 [ ] [(struct: #export (Monoid ) 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/" Monoid Eq] text/format) (math ["R" random]) pipe) @@ -31,17 +31,22 @@ (do-template [category rand-gen ] [(test: (format "[" category "] " "Number") - [x rand-gen] - (assert "" (let [(^open) ] - (and (>= x (abs x)) - (<= x (negate (abs x))) - (= x (* (signum x) - (abs x)))))))] - - ["Nat" R;nat Number] + [x rand-gen + #let [(^open) ]] + (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] ["Int" R;int Number] ["Real" R;real Number] - ## ["Frac" R;frac Number] + ["Frac" R;frac Number] ) (do-template [category rand-gen ] @@ -74,7 +79,7 @@ ["Int" R;int Number Bounded (lambda [_] true)] ## Both min and max values will be positive (thus, greater than zero) ["Real" R;real Number Bounded (r.> 0.0)] - ## ["Frac" R;frac Number Bounded (lambda [_] true)] + ["Frac" R;frac Number Bounded (lambda [_] true)] ) (do-template [category rand-gen ] @@ -121,7 +126,7 @@ ["Nat" R;nat Number Codec] ["Int" R;int Number Codec] ["Real" R;real Number Codec] - ## ["Frac" R;frac Number Codec] + ["Frac" R;frac Number Codec] ) (do-template [ ] -- cgit v1.2.3