Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
grancalavera committed Apr 7, 2019
1 parent 3b07b5b commit b3fba44
Showing 1 changed file with 31 additions and 27 deletions.
58 changes: 31 additions & 27 deletions test/Game/BuilderSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,19 @@ players2 = Map.fromList [(Second, Player "P2" Red Second)] <> players1
players3 = Map.fromList [(Third, Player "P3" Green First)] <> players2
players4 = Map.fromList [(Fourth, Player "P4" Blue Second)] <> players3

invalidPlan0Players, invalidPlan1Players, validPlan2Players, validPlan3Players, validPlan4Players
:: BuildPlan
invalidPlan0Players :: BuildPlan
invalidPlan0Players = Builder.defaultPlan mempty

invalidPlan1Players :: BuildPlan
invalidPlan1Players = Builder.defaultPlan players1

validPlan2Players :: BuildPlan
validPlan2Players = Builder.defaultPlan players2

validPlan3Players :: BuildPlan
validPlan3Players = Builder.defaultPlan players3

validPlan4Players :: BuildPlan
validPlan4Players = Builder.defaultPlan players4

duplicatedBoardPositions :: BuildPlan
Expand All @@ -52,28 +59,11 @@ duplicatedGates :: BuildPlan
duplicatedGates = validPlan2Players & _buildGates .~ addDuplicate
(validPlan2Players ^. _buildGates)

unknownTilePositions :: BuildPlan
unknownTilePositions = validPlan2Players
addDuplicate :: Ord a => NonEmpty a -> NonEmpty a
addDuplicate l = NonEmpty.insert (NonEmpty.head l) l

spec :: Spec
spec = describe "Building new games declaratively" $ do
let tooManyTreasuresPlan = BuildPlan
{ buildBoard = NonEmpty.fromList
[ BuildFixedTreasureFork (V2 0 0) North
, BuildTreasureCorner
, BuildTreasureFork
, BuildTreasureFork
]
, buildGates = NonEmpty.fromList
[ (V2 0 0, Cell Gate South Open)
, (V2 0 1, Cell Gate South Open)
]
, buildPositions = NonEmpty.fromList [V2 0 0, V2 0 1, V2 0 2, V2 0 3]
, buildPlayers = players2
, minPlayers = 2
, buildTreasures = 6
}

context "Players" $ do

it "fails with empty players"
Expand Down Expand Up @@ -159,9 +149,26 @@ spec = describe "Building new games declaratively" $ do
Builder.mkTreasures tooFewTreasuresPlan
`shouldBe` Failure [TooFewTreasures]

it "fails when there are too many treasures"
$ Builder.mkTreasures tooManyTreasuresPlan
`shouldBe` Failure [TooManyTreasures]
it "fails when there are too many treasures" $ do
let tooManyTreasuresPlan = BuildPlan
{ buildBoard = NonEmpty.fromList
[ BuildFixedTreasureFork (V2 0 0) North
, BuildTreasureCorner
, BuildTreasureFork
, BuildTreasureFork
]
, buildGates = NonEmpty.fromList
[ (V2 0 0, Cell Gate South Open)
, (V2 0 1, Cell Gate South Open)
]
, buildPositions = NonEmpty.fromList
[V2 0 0, V2 0 1, V2 0 2, V2 0 3]
, buildPlayers = players2
, minPlayers = 2
, buildTreasures = 6
}
Builder.mkTreasures tooManyTreasuresPlan
`shouldBe` Failure [TooManyTreasures]

it "succeeds with valid 2 players plan"
$ Builder.mkTreasures validPlan2Players
Expand Down Expand Up @@ -218,6 +225,3 @@ spec = describe "Building new games declaratively" $ do
it "succeeds with valid 4 players plan"
$ Builder.validatePositionsCount validPlan4Players
`shouldBe` Success (Builder.buildPositions validPlan4Players)

addDuplicate :: Ord a => NonEmpty a -> NonEmpty a
addDuplicate l = NonEmpty.insert (NonEmpty.head l) l

0 comments on commit b3fba44

Please sign in to comment.