aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/abstract/hash.lux
blob: d829d489eeb130359f6498f3670473b7d0e30d91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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]))))
            ))))