aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/data/bit.lux
blob: d064a736b4251f8e6c6f10818b8fd065824c0779 (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 #*
   [control
    ["M" monad (#+ Monad do)]]
   [data
    bit]
   [math
    ["r" random]]]
  lux/test)

(context: "Bit operations."
  (<| (times 100)
      (do @
        [value r.bit]
        (test "" (and (not (and value (not value)))
                      (or value (not value))

                      (not (:: disjunction identity))
                      (:: disjunction compose value (not value))
                      (:: conjunction identity)
                      (not (:: conjunction compose value (not value)))
                      
                      (:: equivalence = value (not (not value)))
                      (not (:: equivalence = value (not value)))

                      (not (:: equivalence = value ((complement id) value)))
                      (:: equivalence = value ((complement not) value))

                      (case (|> value
                                (:: codec encode)
                                (:: codec decode))
                        (#.Right dec-value)
                        (:: equivalence = value dec-value)

                        (#.Left _)
                        #0)
                      )))))