aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/abstract/hash.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/test/lux/abstract/hash.lux')
-rw-r--r--stdlib/source/test/lux/abstract/hash.lux37
1 files changed, 37 insertions, 0 deletions
diff --git a/stdlib/source/test/lux/abstract/hash.lux b/stdlib/source/test/lux/abstract/hash.lux
new file mode 100644
index 000000000..d829d489e
--- /dev/null
+++ b/stdlib/source/test/lux/abstract/hash.lux
@@ -0,0 +1,37 @@
+(.module:
+ [lux #*
+ ["_" test (#+ Test)]
+ [abstract
+ [monad (#+ do)]
+ {[0 #spec]
+ [/
+ [functor
+ ["$." contravariant]]]}]
+ [data
+ [number
+ ["n" nat]
+ ["i" int]]]
+ [math
+ ["." random (#+ Random)]]]
+ {1
+ ["." /]})
+
+(def: #export test
+ Test
+ (do random.monad
+ [left random.int
+ right random.nat]
+ (<| (_.covering /._)
+ ($_ _.and
+ (_.cover [/.sum]
+ (let [hash (/.sum i.hash n.hash)]
+ (and (n.= (\ i.hash hash left)
+ (\ hash hash (#.Left left)))
+ (n.= (\ n.hash hash right)
+ (\ hash hash (#.Right right))))))
+ (_.cover [/.product]
+ (let [hash (/.product i.hash n.hash)]
+ (n.= (n.+ (\ i.hash hash left)
+ (\ n.hash hash right))
+ (\ hash hash [left right]))))
+ ))))