aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/abstract/monoid.lux
blob: 3600795fffd1c91b5328d02c9106da1c7426f7af (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
(.module:
  [lux #*
   data/text/format
   ["_" test (#+ Test)]
   [abstract/monad (#+ do)]
   [math
    ["r" random (#+ Random)]]
   [control
    ["." function]]]
  {1
   ["." / (#+ Monoid)
    [//
     [equivalence (#+ Equivalence)]]]})

(def: #export (spec (^open "/@.") (^open "/@.") gen-sample)
  (All [a] (-> (Equivalence a) (Monoid a) (Random a) Test))
  (do r.monad
    [sample gen-sample]
    (<| (_.context (%name (name-of /.Monoid)))
        ($_ _.and
            (_.test "Left identity."
                    (/@= sample (/@compose /@identity sample)))
            (_.test "Right identity."
                    (/@= sample (/@compose sample /@identity)))
            ))))