aboutsummaryrefslogtreecommitdiff
path: root/tests/Properties.hs
blob: 867d0e9f81116d33fc6473b7aed3919d5dd07aba (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
{-# 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