diff options
author | Andor Penzes <andor.penzes@gmail.com> | 2016-01-07 11:51:07 +0100 |
---|---|---|
committer | Andor Penzes <andor.penzes@gmail.com> | 2016-01-07 11:51:21 +0100 |
commit | 95589d8e5a5738f227c6697aabab970d80070e37 (patch) | |
tree | 810605ddd95164b3c9df74c4c067e1d2dca8704c /test/UnitTests.hs | |
parent | 63cc26dc33374722148e1339a1afe770f943d360 (diff) |
raname Main.hs to UnitTests.hs
Diffstat (limited to 'test/UnitTests.hs')
-rw-r--r-- | test/UnitTests.hs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/test/UnitTests.hs b/test/UnitTests.hs new file mode 100644 index 00000000..59a95601 --- /dev/null +++ b/test/UnitTests.hs | |||
@@ -0,0 +1,42 @@ | |||
1 | module Main where | ||
2 | |||
3 | import Data.Monoid | ||
4 | import Text.Parsec.Pos (SourcePos(..), newPos, sourceName, sourceLine, sourceColumn) | ||
5 | |||
6 | import Test.QuickCheck | ||
7 | import Test.Tasty | ||
8 | import Test.Tasty.QuickCheck | ||
9 | |||
10 | import Infer | ||
11 | |||
12 | |||
13 | main = defaultMain $ testGroup "Compiler" | ||
14 | [ testGroup "Infer" [ | ||
15 | testProperty "SI Monoid Identity" (propMonoidIdentity (arbitrary :: Gen SI)) | ||
16 | , testProperty "SI Monoid Associativity" (propMonoidAssociativity (arbitrary :: Gen SI)) | ||
17 | ] | ||
18 | ] | ||
19 | |||
20 | ----------------------------------------------------------------- Arbitraries | ||
21 | |||
22 | instance Arbitrary SourcePos where | ||
23 | arbitrary = newPos <$> arbitrary <*> arbitrary <*> arbitrary | ||
24 | shrink pos | ||
25 | | n <- sourceName pos, l <- sourceLine pos, c <- sourceColumn pos | ||
26 | = [newPos n' l' c' | n' <- shrink n, l' <- shrink l, c' <- shrink c] | ||
27 | -- TODO: Diagonalize shrink | ||
28 | |||
29 | instance Arbitrary SI where | ||
30 | arbitrary = oneof [return NoSI, Range <$> arbitrary] | ||
31 | shrink NoSI = [] | ||
32 | shrink (Range r) = NoSI:map Range (shrink r) | ||
33 | |||
34 | ----------------------------------------------------------------- Properties | ||
35 | |||
36 | -- * Monoid | ||
37 | |||
38 | propMonoidIdentity :: (Eq m, Monoid m, Show m) => Gen m -> Property | ||
39 | propMonoidIdentity gen = forAll gen (\x -> x === x <> mempty) | ||
40 | |||
41 | propMonoidAssociativity :: (Arbitrary m, Eq m, Monoid m, Show m) => Gen m -> Property | ||
42 | propMonoidAssociativity gen = forAll gen (\x y z -> (x <> y) <> z == x <> (y <> z)) | ||