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
46
47
|
module Main where
import Data.Monoid
import Text.Parsec.Pos (SourcePos(..), newPos, sourceName, sourceLine, sourceColumn)
import qualified Data.Set as Set
import Test.QuickCheck
import Test.Tasty
import Test.Tasty.QuickCheck
import LambdaCube.Compiler.Infer
main = defaultMain $ testGroup "Compiler"
[ testGroup "Infer" [
testProperty "SI monoid left identity" (propMonoidLeftIdentity (arbitrary :: Gen SI))
, testProperty "SI monoid right identity" (propMonoidRightIdentity (arbitrary :: Gen SI))
, testProperty "SI monoid associativity" (propMonoidAssociativity (arbitrary :: Gen SI))
]
]
----------------------------------------------------------------- Arbitraries
instance Arbitrary SourcePos where
arbitrary = newPos <$> arbitrary <*> arbitrary <*> arbitrary
shrink pos
| n <- sourceName pos, l <- sourceLine pos, c <- sourceColumn pos
= [newPos n' l' c' | n' <- shrink n, l' <- shrink l, c' <- shrink c]
-- TODO: Diagonalize shrink
instance Arbitrary SI where
arbitrary = oneof [NoSI . Set.fromList <$> arbitrary, Range <$> arbitrary]
shrink (NoSI ds) = []
shrink (Range r) = NoSI (Set.empty):map Range (shrink r)
----------------------------------------------------------------- Properties
-- * Monoid
propMonoidLeftIdentity :: (Eq m, Monoid m, Show m) => Gen m -> Property
propMonoidLeftIdentity gen = forAll gen (\x -> x === mempty <> x)
propMonoidRightIdentity :: (Eq m, Monoid m, Show m) => Gen m -> Property
propMonoidRightIdentity gen = forAll gen (\x -> x === x <> mempty)
propMonoidAssociativity :: (Arbitrary m, Eq m, Monoid m, Show m) => Gen m -> Property
propMonoidAssociativity gen = forAll gen (\x y z -> (x <> y) <> z === x <> (y <> z))
|