diff options
-rw-r--r-- | lisk.cabal | 6 | ||||
-rw-r--r-- | src/Error/Base.hs | 3 | ||||
-rw-r--r-- | tests/Main.hs | 4 | ||||
-rw-r--r-- | tests/Properties.hs | 38 |
4 files changed, 27 insertions, 24 deletions
@@ -18,11 +18,11 @@ extra-source-files: CHANGELOG.md | |||
18 | 18 | ||
19 | library | 19 | library |
20 | default-language: Haskell2010 | 20 | default-language: Haskell2010 |
21 | hs-source-dirs: src | ||
21 | build-depends: | 22 | build-depends: |
22 | base == 4.*, | 23 | base == 4.*, |
23 | parsec == 3.*, | 24 | parsec == 3.*, |
24 | mtl >= 2.1 | 25 | mtl >= 2.1 |
25 | hs-source-dirs: src | ||
26 | exposed-modules: | 26 | exposed-modules: |
27 | Parser, | 27 | Parser, |
28 | Evaluator, | 28 | Evaluator, |
@@ -33,22 +33,22 @@ library | |||
33 | executable lisk | 33 | executable lisk |
34 | default-language: Haskell2010 | 34 | default-language: Haskell2010 |
35 | main-is: Main.hs | 35 | main-is: Main.hs |
36 | hs-source-dirs: bin | ||
36 | build-depends: | 37 | build-depends: |
37 | base == 4.*, | 38 | base == 4.*, |
38 | parsec == 3.*, | 39 | parsec == 3.*, |
39 | readline >= 1.0, | 40 | readline >= 1.0, |
40 | mtl >= 2.1, | 41 | mtl >= 2.1, |
41 | lisk | 42 | lisk |
42 | hs-source-dirs: bin | ||
43 | 43 | ||
44 | test-suite properties | 44 | test-suite properties |
45 | default-language: Haskell2010 | 45 | default-language: Haskell2010 |
46 | type: exitcode-stdio-1.0 | 46 | type: exitcode-stdio-1.0 |
47 | main-is: Main.hs | 47 | main-is: Main.hs |
48 | hs-source-dirs: tests | 48 | hs-source-dirs: tests |
49 | other-modules: Properties | ||
49 | build-depends: | 50 | build-depends: |
50 | base == 4.*, | 51 | base == 4.*, |
51 | parsec == 3.*, | 52 | parsec == 3.*, |
52 | QuickCheck >= 2.1 && < 3, | 53 | QuickCheck >= 2.1 && < 3, |
53 | lisk | 54 | lisk |
54 | other-modules: Properties | ||
diff --git a/src/Error/Base.hs b/src/Error/Base.hs index b6ae9a3..509377b 100644 --- a/src/Error/Base.hs +++ b/src/Error/Base.hs | |||
@@ -5,12 +5,9 @@ module Error.Base ( | |||
5 | ) where | 5 | ) where |
6 | 6 | ||
7 | import Control.Monad.Except | 7 | import Control.Monad.Except |
8 | import Data.List (intercalate, nub) | ||
9 | import Parser | 8 | import Parser |
10 | import Text.Parsec | 9 | import Text.Parsec |
11 | import Text.Parsec.Error | 10 | import Text.Parsec.Error |
12 | import Text.Parsec.Pos | ||
13 | import Text.Parsec.String (Parser) | ||
14 | import Text.ParserCombinators.Parsec | 11 | import Text.ParserCombinators.Parsec |
15 | 12 | ||
16 | data LispError = Parse ParseError | 13 | data LispError = Parse ParseError |
diff --git a/tests/Main.hs b/tests/Main.hs index c4e0d9b..87dedbc 100644 --- a/tests/Main.hs +++ b/tests/Main.hs | |||
@@ -1,6 +1,6 @@ | |||
1 | module Main where | 1 | module Main where |
2 | 2 | ||
3 | import Properties | 3 | import Properties (runTests) |
4 | import Test.QuickCheck | 4 | import Test.QuickCheck |
5 | 5 | ||
6 | main = tests | 6 | main = runTests |
diff --git a/tests/Properties.hs b/tests/Properties.hs index e50c7e8..b9550c0 100644 --- a/tests/Properties.hs +++ b/tests/Properties.hs | |||
@@ -1,25 +1,31 @@ | |||
1 | {-# LANGUAGE TemplateHaskell #-} | 1 | {-# LANGUAGE TemplateHaskell #-} |
2 | module Properties where | 2 | module Properties ( |
3 | runTests | ||
4 | ) where | ||
3 | 5 | ||
6 | import Data.Maybe (fromJust) | ||
7 | import Error.Base (unwrap) | ||
8 | import Evaluator (eval) | ||
9 | import Operators (primitives) | ||
4 | import Parser (Expr (..), parseLispValue, parseQuote) | 10 | import Parser (Expr (..), parseLispValue, parseQuote) |
5 | |||
6 | import Test.QuickCheck | 11 | import Test.QuickCheck |
7 | 12 | ||
8 | -- some tests would go here hopefully | 13 | addition = fromJust $ lookup "+" primitives |
14 | multiplication = fromJust $ lookup "*" primitives | ||
9 | 15 | ||
10 | -- a filler test to test the test suite :^) | 16 | prop_commutativeAdd :: [Integer] -> Property |
11 | qsort :: (Ord a) => [a] -> [a] | 17 | prop_commutativeAdd xs = |
12 | qsort [] = [] | 18 | not (null xs) ==> rhs == lhs |
13 | qsort [x] = [x] | 19 | where rhs = (unwrap . addition) exprs |
14 | qsort (x:xs) = qsort left ++ [x] ++ qsort right | 20 | lhs = (unwrap . addition . reverse) exprs |
15 | where left = filter (<= x) xs | 21 | exprs = map IntLiteral xs |
16 | right = filter (> x) xs | ||
17 | 22 | ||
18 | checkList :: (Ord a) => [a] -> Bool | 23 | prop_commutativeMul :: [Integer] -> Property |
19 | checkList = ordered . qsort | 24 | prop_commutativeMul xs = |
20 | where ordered [] = True | 25 | not (null xs) ==> rhs == lhs |
21 | ordered [x] = True | 26 | where rhs = (unwrap . multiplication) exprs |
22 | ordered (x:y:xs) = x <= y && ordered (y:xs) | 27 | lhs = (unwrap . multiplication . reverse) exprs |
28 | exprs = map IntLiteral xs | ||
23 | 29 | ||
24 | return [] | 30 | return [] |
25 | tests = $quickCheckAll | 31 | runTests = $quickCheckAll |