-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameStateTest.hs
26 lines (21 loc) · 931 Bytes
/
GameStateTest.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
module GameStateTest where
import Test.QuickCheck
import GameState
-- Define an Arbitrary instance for Player
instance Arbitrary Player where
arbitrary = elements [PlayerRed, PlayerBlack]
-- Property: Initial board has 12 pieces for each player
prop_initBoardHasCorrectPieceCount :: Bool
prop_initBoardHasCorrectPieceCount =
let board = initBoard
blackPieces = length [p | row <- board, p <- row, p == Black]
redPieces = length [p | row <- board, p <- row, p == Red]
in blackPieces == 12 && redPieces == 12
-- Property: Switching player twice results in the original player
prop_switchPlayerIsReversible :: Player -> Bool
prop_switchPlayerIsReversible player = switchPlayer (switchPlayer player) == player
-- Run all QuickCheck properties
runQuickCheckTests :: IO ()
runQuickCheckTests = do
quickCheck prop_initBoardHasCorrectPieceCount
quickCheck prop_switchPlayerIsReversible