aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/data/bit.lux
blob: 6f281818dea6eca952c08bc7e7a92cc5ba08cbd8 (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 #spec]
     [/
      ["$." 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))))
            ))))