From b3fba44562c8a8bfdf69e74a48338f81e64d8efd Mon Sep 17 00:00:00 2001 From: Leon Coto Date: Mon, 8 Apr 2019 00:26:16 +0100 Subject: [PATCH] fixup --- test/Game/BuilderSpec.hs | 58 +++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/test/Game/BuilderSpec.hs b/test/Game/BuilderSpec.hs index 04d7bd8..6889d30 100644 --- a/test/Game/BuilderSpec.hs +++ b/test/Game/BuilderSpec.hs @@ -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 @@ -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" @@ -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 @@ -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