From 82a64ef64602227daefc3ff96908d6c1b2303b61 Mon Sep 17 00:00:00 2001 From: Akshay Date: Wed, 14 Oct 2020 14:15:45 +0530 Subject: add PBTs for arithmetic operators - commutativity of addition - commutativity of multiplication --- tests/Properties.hs | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) (limited to 'tests/Properties.hs') 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 @@ {-# LANGUAGE TemplateHaskell #-} -module Properties where +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 --- some tests would go here hopefully +addition = fromJust $ lookup "+" primitives +multiplication = fromJust $ lookup "*" primitives --- a filler test to test the test suite :^) -qsort :: (Ord a) => [a] -> [a] -qsort [] = [] -qsort [x] = [x] -qsort (x:xs) = qsort left ++ [x] ++ qsort right - where left = filter (<= x) xs - right = filter (> x) xs +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 -checkList :: (Ord a) => [a] -> Bool -checkList = ordered . qsort - where ordered [] = True - ordered [x] = True - ordered (x:y:xs) = x <= y && ordered (y:xs) +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 return [] -tests = $quickCheckAll +runTests = $quickCheckAll -- cgit v1.2.3