-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTest.hs
51 lines (37 loc) · 1.35 KB
/
Test.hs
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE OverloadedStrings #-}
module Tests where
import qualified Data.Text as T
import Test.QuickCheck
-- import Test.QuickCheck.Modifiers (NonEmptyList (..))
import Polishnt
prop_add_length :: Double -> Stack -> Bool
prop_add_length n xs = length (addNumberStack xs n) == length xs + 1
prop_added_to_stack :: Double -> Stack -> Bool
prop_added_to_stack n xs = head (addNumberStack xs n) == toRational n
prop_discard :: Stack -> Property
prop_discard stack@(_:xs) = property $ discardElement stack == xs
prop_discard _ = property Discard
prop_xy :: Stack -> Property
prop_xy stack@(x:y:xs) = property $ xyStack stack == y : x : xs
prop_xy _ = property Discard
prop_add :: Double -> Double -> Bool
prop_add = test_binary "+" (+)
prop_div :: Double -> Positive Double -> Bool
prop_div a (Positive b) = test_binary "/" (/) a b
prop_mul :: Double -> Double -> Bool
prop_mul = test_binary "*" (*)
prop_sub :: Double -> Double -> Bool
prop_sub = test_binary "-" (-)
test_binary ::
T.Text -> (Rational -> Rational -> Rational) -> Double -> Double -> Bool
test_binary op op' a b =
head (perform (addNumberStack (addNumberStack [] a) b) op) ==
toRational (op' a' b')
where
a' = toRational a
b' = toRational b
return []
runTests :: IO Bool
runTests =
$forAllProperties $ quickCheckWithResult (stdArgs {maxSuccess = 10000})