aboutsummaryrefslogtreecommitdiff
path: root/tests/Properties.hs
blob: 03a7e9a45444ad44c0c36f8445c1e1bb5577170a (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
26
27
28
29
30
31
{-# LANGUAGE TemplateHaskell #-}
module Properties (
                  runTests
                  ) where

import           Data.Maybe      (fromJust)
import           Error.Base      (unwrap)
import           Evaluator       (eval)
import           Operators       (primitives)
import           Parser          (Expr (..), parseLispValue, parseQuote)
import           Test.QuickCheck


prop_commutativeAdd :: [Integer] -> Property
prop_commutativeAdd xs =
    not (null xs) ==> rhs == lhs
        where rhs = (unwrap . addition) exprs
              lhs = (unwrap . addition . reverse) exprs
              exprs = map IntLiteral xs
              addition = fromJust $ lookup "+" primitives

prop_commutativeMul :: [Integer] -> Property
prop_commutativeMul xs =
    not (null xs) ==> rhs == lhs
        where rhs = (unwrap . multiplication) exprs
              lhs = (unwrap . multiplication . reverse) exprs
              exprs = map IntLiteral xs
              multiplication = fromJust $ lookup "*" primitives

return []
runTests = $quickCheckAll