Repository navigation
Expand file tree
/
Copy pathTestGameLogic.elm
More file actions
93 lines (69 loc) · 2.92 KB
/
Copy pathTestGameLogic.elm
File metadata and controls
93 lines (69 loc) · 2.92 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
module TestGameLogic exposing (suite)
import Expect
import Fuzz exposing (Fuzzer)
import Pages.Quarto as Q exposing (Colour(..), Gamepiece, Pattern(..), Shape(..), Size(..))
import Test exposing (Test, describe, fuzz)
-- TESTS ON CALCULATING GAME WIN LOGIC
shapeFuzzer : Float -> Float -> Fuzzer Shape
shapeFuzzer freq1 freq2 =
Fuzz.frequency
[ ( freq1, Fuzz.constant Square )
, ( freq2, Fuzz.constant Circle )
]
colourFuzzer : Float -> Float -> Fuzzer Colour
colourFuzzer freq1 freq2 =
Fuzz.frequency
[ ( freq1, Fuzz.constant Colour1 )
, ( freq2, Fuzz.constant Colour2 )
]
sizeFuzzer : Float -> Float -> Fuzzer Size
sizeFuzzer freq1 freq2 =
Fuzz.frequency
[ ( freq1, Fuzz.constant Small )
, ( freq2, Fuzz.constant Large )
]
patternFuzzer : Float -> Float -> Fuzzer Pattern
patternFuzzer freq1 freq2 =
Fuzz.frequency
[ ( freq1, Fuzz.constant Solid )
, ( freq2, Fuzz.constant Hollow )
]
gamepieceFuzzer : Fuzzer Shape -> Fuzzer Colour -> Fuzzer Pattern -> Fuzzer Size -> Fuzzer Gamepiece
gamepieceFuzzer =
Fuzz.map4 Gamepiece
winningGamepiecesFuzzer : Fuzzer (List Gamepiece)
winningGamepiecesFuzzer =
let
constantShape =
gamepieceFuzzer (shapeFuzzer 1 0) (colourFuzzer 1 1) (patternFuzzer 1 1) (sizeFuzzer 1 1)
constantColour =
gamepieceFuzzer (shapeFuzzer 1 1) (colourFuzzer 1 0) (patternFuzzer 1 1) (sizeFuzzer 1 1)
constantPattern =
gamepieceFuzzer (shapeFuzzer 1 1) (colourFuzzer 1 1) (patternFuzzer 1 0) (sizeFuzzer 1 1)
constantSize =
gamepieceFuzzer (shapeFuzzer 1 1) (colourFuzzer 1 1) (patternFuzzer 1 0) (sizeFuzzer 1 1)
in
Fuzz.oneOf [ constantShape, constantColour, constantPattern, constantSize ]
|> Fuzz.map (\gamepiece -> [ gamepiece, gamepiece, gamepiece, gamepiece ])
losingGamepiecesFuzzer : Fuzzer (List Gamepiece)
losingGamepiecesFuzzer =
let
firstGamepiece =
gamepieceFuzzer (shapeFuzzer 1 0) (colourFuzzer 1 0) (patternFuzzer 1 0) (sizeFuzzer 1 0)
secondGamepiece =
gamepieceFuzzer (shapeFuzzer 0 1) (colourFuzzer 0 1) (patternFuzzer 0 1) (sizeFuzzer 0 1)
in
Fuzz.tuple ( firstGamepiece, secondGamepiece )
|> Fuzz.map (\( first, second ) -> [ first, second, first, second ])
suite : Test
suite =
describe "Game Logic"
[ fuzz winningGamepiecesFuzzer "testing four cells that all share a matching dimension" <|
\gamepieceList ->
Q.matchingDimensions gamepieceList
|> Expect.true "the matching dimension function should return true"
, fuzz losingGamepiecesFuzzer "testing four cells that do not share matching dimensions" <|
\gamepieceList ->
Q.matchingDimensions gamepieceList
|> Expect.false "the matching dimensions function should return false"
]