-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tests.hs
62 lines (50 loc) · 1.99 KB
/
Tests.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
52
53
54
55
56
57
58
59
60
61
62
{-
- Tests to FilePPM
-}
module Tests (todosTestes) where
import FilePPM
import Test.QuickCheck
getFirst :: (Int, Int, Int) -> Int
getFirst (a,_,_) = a
getSecond :: (Int, Int, Int) -> Int
getSecond (_,b,_) = b
{-
- Verifies that inverted property:
- An image inverted twice is the same image
-}
prop_InvertTwice :: FilePPM -> Bool
prop_InvertTwice image = verticalFlip (verticalFlip image) == image
&& horizontalFlip (horizontalFlip image) == image
{-
- Verifies that every image has the same number of
- pixels that the multiplication of the file's dimensions
-}
prop_DimensoesCorretas :: FilePPM -> Bool
prop_DimensoesCorretas image = width * height == (sum $ map length pixeis)
where width = getFirst $ header image
height = getSecond $ header image
pixeis = getPixeis image
{-
- Verifies that take half of one of its dimensions, the
- ration is the same:
- Due to the fact of dividing odd numbers by 2, you lose
- your price. It is therefore considered, for the tests,
- that both the height and the width have to be pairs
-}
prop_RacioIgual :: FilePPM -> Property
prop_RacioIgual image = even originalWidth && even originalHeight ==>
classify (originalWidth == 1 && originalHeight == 1) "trivial" $
abs (originalRacio - newRacio) < 0.00001
where
originalRacio = (fromIntegral originalWidth :: Float)/(fromIntegral originalHeight :: Float)
newRacio = (\img -> (fromIntegral (getFirst (header img)) :: Float)
/(fromIntegral (getSecond (header img)) :: Float)) newImage
newImage = halfWidth (halfHeight (image))
originalWidth = (getFirst (header image))
originalHeight = (getSecond (header image))
------- EXECUTE THE TESTES -------
todosTestes :: IO ()
todosTestes = do
quickCheck prop_InvertTwice
quickCheck prop_DimensoesCorretas
quickCheck prop_RacioIgual