aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/data/bit.lux
blob: 7dda82016b8f53fe25313fe559fc6b15d37abd6d (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 #*
   ["%" data/text/format (#+ format)]
   ["_" test (#+ Test)]
   ["r" math/random]
   [abstract
    [monad (#+ do)]
    {[0 #test]
     [/
      ["$." equivalence]
      ["$." monoid]
      ["$." codec]]}]
   [control
    ["." function]]]
  {1
   ["." /]})

(def: #export test
  Test
  (<| (_.context (%.name (name-of .Bit)))
      (do r.monad
        [value r.bit]
        ($_ _.and
            ($equivalence.spec /.equivalence r.bit)
            ($codec.spec /.equivalence /.codec r.bit)
            (<| (_.context "Disjunction.")
                ($monoid.spec /.equivalence /.disjunction r.bit))
            (<| (_.context "Conjunction.")
                ($monoid.spec /.equivalence /.conjunction r.bit))
            (_.test "A value cannot be true and false at the same time."
                    (not (and value (not value))))
            (_.test "A value must be either true or false at any time."
                    (or value (not value)))
            (_.test "Can create the complement of a predicate."
                    (and (not (:: /.equivalence = value ((/.complement function.identity) value)))
                         (:: /.equivalence = value ((/.complement not) value))))
            ))))