/
Plus.purs
45 lines (35 loc) · 1.06 KB
/
Plus.purs
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
38
39
40
41
42
43
44
45
module Test.QuickCheck.Laws.Control.Plus where
import Prelude
import Control.Alt ((<|>))
import Control.Plus (class Plus, empty)
import Effect (Effect)
import Effect.Console (log)
import Test.QuickCheck (quickCheck')
import Test.QuickCheck.Arbitrary (class Arbitrary)
import Test.QuickCheck.Laws (A, B)
import Type.Proxy (Proxy2)
-- | - Left identity: `empty <|> x == x`
-- | - Right identity: `x <|> empty == x`
-- | - Annihilation: `f <$> empty == empty`
checkPlus
∷ ∀ f
. Plus f
⇒ Arbitrary (f A)
⇒ Eq (f A)
⇒ Eq (f B)
⇒ Proxy2 f
→ Effect Unit
checkPlus _ = do
log "Checking 'Left identity' law for Plus"
quickCheck' 1000 leftIdentity
log "Checking 'Right identity' law for Plus"
quickCheck' 1000 rightIdentity
log "Checking 'Annihilation' law for Plus"
quickCheck' 1000 annihilation
where
leftIdentity ∷ f A → Boolean
leftIdentity x = (empty <|> x) == x
rightIdentity ∷ f A → Boolean
rightIdentity x = (x <|> empty) == x
annihilation ∷ (A → B) → Boolean
annihilation f = (f <$> empty) == (empty ∷ f B)