aboutsummaryrefslogtreecommitdiff
path: root/stdlib
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--stdlib/source/lux/data/number.lux4
-rw-r--r--stdlib/test/test/lux/math/logic/fuzzy.lux44
-rw-r--r--stdlib/test/test/lux/math/simple.lux3
3 files changed, 28 insertions, 23 deletions
diff --git a/stdlib/source/lux/data/number.lux b/stdlib/source/lux/data/number.lux
index 9f2c01d0e..418e84a14 100644
--- a/stdlib/source/lux/data/number.lux
+++ b/stdlib/source/lux/data/number.lux
@@ -181,6 +181,10 @@
(def: (hash value)
(_lux_proc ["real" "hash"] [value])))
+(struct: #export _ (Hash Deg)
+ (def: eq Eq<Deg>)
+ (def: hash (|>. (:! Nat))))
+
## [Values & Syntax]
(do-template [<struct> <base> <char-set> <error>]
[(struct: #export <struct> (Codec Text Nat)
diff --git a/stdlib/test/test/lux/math/logic/fuzzy.lux b/stdlib/test/test/lux/math/logic/fuzzy.lux
index 284fffa4b..73530f35b 100644
--- a/stdlib/test/test/lux/math/logic/fuzzy.lux
+++ b/stdlib/test/test/lux/math/logic/fuzzy.lux
@@ -12,12 +12,15 @@
continuous))
lux/test)
-(do-template [<desc> <gen> <triangle> <lt> <lte> <gt> <gte>]
+(do-template [<desc> <hash> <gen> <triangle> <lt> <lte> <gt> <gte>]
[(test: (format "[" <desc> "] " "Triangles")
- #seed +1981055421923629192
- [x <gen>
- y <gen>
- z <gen>
+ [values (R;set <hash> +3 <gen>)
+ #let [[x y z] (case (set;to-list values)
+ (^ (list x y z))
+ [x y z]
+
+ _
+ (undefined))]
sample <gen>
#let [[bottom middle top] (case (list;sort <lt> (list x y z))
(^ (list bottom middle top))
@@ -45,17 +48,19 @@
(<gte> top sample))))
))]
- ["Real" R;real &;r.triangle r.< r.<= r.> r.>=]
- ["Deg" R;deg &;d.triangle d.< d.<= d.> d.>=]
+ ["Real" number;Hash<Real> R;real &;r.triangle r.< r.<= r.> r.>=]
+ ["Deg" number;Hash<Deg> R;deg &;d.triangle d.< d.<= d.> d.>=]
)
-(do-template [<desc> <gen> <trapezoid> <lt> <lte> <gt> <gte>]
+(do-template [<desc> <hash> <gen> <trapezoid> <lt> <lte> <gt> <gte>]
[(test: (format "[" <desc> "] " "Trapezoids")
- #seed +8418494856347027801
- [w <gen>
- x <gen>
- y <gen>
- z <gen>
+ [values (R;set <hash> +4 <gen>)
+ #let [[w x y z] (case (set;to-list values)
+ (^ (list w x y z))
+ [w x y z]
+
+ _
+ (undefined))]
sample <gen>
#let [[bottom middle-bottom middle-top top] (case (list;sort <lt> (list w x y z))
(^ (list bottom middle-bottom middle-top top))
@@ -89,19 +94,16 @@
(<gte> top sample))))
))]
- ["Real" R;real &;r.trapezoid r.< r.<= r.> r.>=]
- ["Deg" R;deg &;d.trapezoid d.< d.<= d.> d.>=]
+ ["Real" number;Hash<Real> R;real &;r.trapezoid r.< r.<= r.> r.>=]
+ ["Deg" number;Hash<Deg> R;deg &;d.trapezoid d.< d.<= d.> d.>=]
)
(test: "Gaussian"
- #seed +1000679812414
- [deviation R;real
+ [deviation (|> R;real (R;filter (r.> 0.0)))
center R;real
#let [gaussian (&;gaussian deviation center)]]
- ($_ seq
- (assert "The center value will always have maximum membership."
- (d.= ~true (&;membership center gaussian)))
- ))
+ (assert "The center value will always have maximum membership."
+ (d.= ~true (&;membership center gaussian))))
(def: gen-triangle
(R;Random (&;Fuzzy Real))
diff --git a/stdlib/test/test/lux/math/simple.lux b/stdlib/test/test/lux/math/simple.lux
index 9aec7f1fc..67d8bf8d0 100644
--- a/stdlib/test/test/lux/math/simple.lux
+++ b/stdlib/test/test/lux/math/simple.lux
@@ -14,7 +14,6 @@
(do-template [<category> <generator> <=> <+> <-> <*> </> <%> <0>]
[(test: (format <category> " arihtmetic")
- #seed +1786783812616344121
[x <generator>
y (|> <generator> (R;filter (. not (<=> <0>))))]
($_ seq
@@ -33,7 +32,7 @@
["Nat" R;nat n.= n.+ n.- n.* n./ n.% +0]
["Int" R;int i.= i.+ i.- i.* i./ i.% 0]
["Real" R;real r.= r.+ r.- r.* r./ r.% 0.0]
- ["Deg" R;deg d.= d.+ d.- d.* d./ d.% .0]
+ ["Deg" R;deg d.= d.+ d.- d.* d./ d.% .0]
)
(do-template [<category> <generator> <lt> <lte> <gt> <gte>]