public void Act_ShouldAttemptToClaimEachCellForWin()
        {
            //Arrange
            FakeCell fakeCell = new FakeCell.Builder().Build();
            FakeEnumerator <ICell> fakeEnumerator = new FakeEnumerator <ICell> .Builder()
                                                    .MoveNext(true, true, true, true, true, false)
                                                    .Current(fakeCell)
                                                    .Build();

            FakeCellCollection fakeCellCollection = new FakeCellCollection.Builder()
                                                    .GetEnumerator(fakeEnumerator)
                                                    .Build();
            FakeBoard fakeBoardClone = new FakeBoard.Builder()
                                       .ClaimEndsGame(Bool.False)
                                       .Build();
            FakeBoard fakeBoard = new FakeBoard.Builder()
                                  .AvailableSpaces(fakeCellCollection)
                                  .Clone(fakeBoardClone)
                                  .Build();
            FakeSelectMoveAction          fakeSelectMoveAction = new FakeSelectMoveAction.Builder().Act(null).Build();
            PlayerWinningSelectMoveAction subject = new AbstractWrapper(fakeSelectMoveAction);

            //Act
            subject.Act(fakeBoard, null, null);

            //Assert
            fakeSelectMoveAction.AssertActInvoked();
            fakeBoard.CloneInvokedCount(5);
            fakeBoardClone.AssertClaimEndsGameInvokedCount(5);
        }
        public void Act_ShouldSelectOtherPlayer()
        {
            //Arrange
            FakeCell fakeCell = new FakeCell.Builder().Build();
            FakeEnumerator <ICell> fakeEnumerator = new FakeEnumerator <ICell> .Builder()
                                                    .MoveNext(true)
                                                    .Current(fakeCell)
                                                    .Build();

            FakeCellCollection fakeCellCollection = new FakeCellCollection.Builder()
                                                    .GetEnumerator(fakeEnumerator)
                                                    .Build();
            FakeBoard fakeBoardClone = new FakeBoard.Builder()
                                       .ClaimEndsGame(Bool.True)
                                       .Build();
            FakeBoard fakeBoard = new FakeBoard.Builder()
                                  .AvailableSpaces(fakeCellCollection)
                                  .Clone(fakeBoardClone)
                                  .Build();
            FakePlayer           fakePlayer            = new FakePlayer.Builder().Build();
            FakeSelectMoveAction fakeSelectMoveAction  = new FakeSelectMoveAction.Builder().Act(null).Build();
            OtherPlayerWinningSelectMoveAction subject = new OtherPlayerWinningSelectMoveAction(fakeSelectMoveAction);

            //Act
            subject.Act(fakeBoard, null, fakePlayer);

            //Assert
            fakeBoardClone.AssertClaimEndsGameInvokedWith(fakeCell, fakePlayer);
        }
Ejemplo n.º 3
0
        public void Available_ShouldIdentifyCellAsNotAvailable()
        {
            //Arrange
            FakeCell       fakeCell       = new FakeCell.Builder().IsSelected(Bool.True).Value("1").Build();
            CellCollection cellCollection = new CellCollection(new ICell[] { fakeCell });
            Board          subject        = new Board(cellCollection, null, null);

            //Act
            Bool actual = subject.Available(fakeCell);

            //Assert
            ((bool)actual).Should().BeFalse();
        }
Ejemplo n.º 4
0
        public void IsWin_ShouldReturnTrueWhenIsWin()
        {
            //Arrange
            FakeCell           fakeCell           = new FakeCell.Builder().Value("1").Build();
            FakeCellCollection fakeCellCollection = new FakeCellCollection.Builder().At(fakeCell).Build();
            Win subject = new TestWin(fakeCellCollection, 1, 2, 3);

            //Act
            Bool actual = subject.IsWin();

            //Assert
            ((bool)actual).Should().BeTrue();
        }
Ejemplo n.º 5
0
        public void ShouldBeFalseGivenNonMatchAndSelected()
        {
            //Arrange
            FakeCell             fakeCell = new FakeCell.Builder().IsSelected(Bool.True).Build();
            Bool                 areEqual = Bool.False;
            MatchedCellAvailable subject  = new MatchedCellAvailable(fakeCell, areEqual);

            //Act
            bool actual = subject;

            //Assert
            actual.Should().BeFalse();
        }
Ejemplo n.º 6
0
        public void ShouldBeFalseForNonMatchingCells()
        {
            //Arrange
            FakeCell     fakeCell  = new FakeCell.Builder().Value("?").Build();
            FakeCell     fakeCell2 = new FakeCell.Builder().Value("X").Build();
            CellEquality subject   = new CellEquality(fakeCell, fakeCell2);

            //Act
            bool actual = subject;

            //Assert
            actual.Should().BeFalse();
        }
Ejemplo n.º 7
0
        public void IsSelected_ShouldCallThrough()
        {
            //Arrange
            FakeCell fakeCell = new FakeCell.Builder().IsSelected(Bool.True).Build();
            FakeSingleReservoirSample <ICell> fakeSingleReservoirSample = new FakeSingleReservoirSample <ICell> .Builder().Element(fakeCell).Build();

            RandomCell subject = new RandomCell(fakeSingleReservoirSample);

            //Act
            subject.IsSelected();

            //Assert
            fakeCell.AssertIsSelectedInvoked();
        }
Ejemplo n.º 8
0
        public void ShouldPrintExpected()
        {
            //Arrange
            FakeWriter       fakeWriter = new FakeWriter();
            FakeCell         fakeCell   = new FakeCell.Builder().Value("YEAH").Build();
            FakePlayer       fakePlayer = new FakePlayer.Builder().Cell(fakeCell).Build();
            PlayerWinPrinter subject    = new PlayerWinPrinter(fakePlayer, fakeWriter);

            //Act
            subject.Print();

            //Assert
            fakeWriter.AssertLastLine("Player 'YEAH' has won!");
        }
Ejemplo n.º 9
0
        public void Value_ShouldCallThrough()
        {
            //Arrange
            FakeCell fakeCell = new FakeCell.Builder().Value("?").Build();
            FakeSingleReservoirSample <ICell> fakeSingleReservoirSample = new FakeSingleReservoirSample <ICell> .Builder().Element(fakeCell).Build();

            RandomCell subject = new RandomCell(fakeSingleReservoirSample);

            //Act
            subject.Value();

            //Assert
            fakeCell.AssertValueInvoked();
        }
Ejemplo n.º 10
0
        public void IsWin_ShouldReturnFalseWhenNotMatch()
        {
            //Arrange
            FakeCell           fakeCell1          = new FakeCell.Builder().Value("1").Build();
            FakeCell           fakeCell2          = new FakeCell.Builder().Value("2").Build();
            FakeCellCollection fakeCellCollection = new FakeCellCollection.Builder().At(fakeCell1, fakeCell2).Build();
            Win subject = new TestWin(fakeCellCollection, 1, 2, 3);

            //Act
            Bool actual = subject.IsWin();

            //Assert
            ((bool)actual).Should().BeFalse();
        }
        public void Act_ShouldReturnExpectedCellWhenCenterAvailable()
        {
            //Arrange
            FakeCell                     expectedCell         = new FakeCell.Builder().Value("4").Build();
            FakeSelectMoveAction         fakeSelectMoveAction = new FakeSelectMoveAction.Builder().Build();
            FakeBoard                    fakeBoard            = new FakeBoard.Builder().Available(Bool.True).Build();
            CenterSquareSelectMoveAction subject = new CenterSquareSelectMoveAction(fakeSelectMoveAction);

            //Act
            ICell cell = subject.Act(fakeBoard, null, null);

            //Assert
            cell.Value().Should().Be(expectedCell.Value());
        }
        public void ShouldInvokeIndexes()
        {
            //Arrange
            FakeCell           fakeCell           = new FakeCell.Builder().Value("").Build();
            FakeCellCollection fakeCellCollection = new FakeCellCollection.Builder().At(fakeCell).Build();
            Int indexOne = new IntOf(1);
            Int indexTwo = new IntOf(2);
            IndexedCellEquality subject = new IndexedCellEquality(fakeCellCollection, indexOne, indexTwo);

            //Act
            bool actual = subject;

            //Assert
            fakeCellCollection.AssertAtInvokedWith(indexOne, indexTwo);
        }
Ejemplo n.º 13
0
        public void Input_ShouldWritePrompt()
        {
            //Arrange
            FakeCell fakeCell = new FakeCell.Builder().Value("?").Build();
            FakeValidResponse <IGlyph> fakeValidResponse = new FakeValidResponse <IGlyph> .Builder().Response(null).Build();

            FakeWriter     fakeWriter = new FakeWriter();
            HumanMoveInput subject    = new HumanMoveInput(fakeValidResponse, fakeWriter);

            //Act
            subject.Input(fakeCell);

            //Assert
            fakeWriter.AssertLinesWritten("Player ?'s Turn");
        }
Ejemplo n.º 14
0
        public void ShouldBeFakseWhenAnyCell()
        {
            //Arrange
            FakeCell     fakeCell = new FakeCell.Builder().Build();
            List <ICell> cells    = new List <ICell> {
                fakeCell
            };
            WhereAnyCell subject = new WhereAnyCell(cells, cell => false);

            //Act
            bool actual = subject;

            //Assert
            actual.Should().BeFalse();
        }
        public void Act_ShouldCallActWhenCenterNotAvailable()
        {
            //Arrange
            FakeCell                     expectedCell         = new FakeCell.Builder().Build();
            FakeSelectMoveAction         fakeSelectMoveAction = new FakeSelectMoveAction.Builder().Act(expectedCell).Build();
            FakeBoard                    fakeBoard            = new FakeBoard.Builder().Available(Bool.False).Build();
            FakePlayer                   fakePlayerA          = new FakePlayer.Builder().Build();
            FakePlayer                   fakePlayerB          = new FakePlayer.Builder().Build();
            CenterSquareSelectMoveAction subject = new CenterSquareSelectMoveAction(fakeSelectMoveAction);

            //Act
            subject.Act(fakeBoard, fakePlayerA, fakePlayerB);

            //Assert
            fakeSelectMoveAction.AssertActInvokedWith(new Tuple <IBoard, IPlayer, IPlayer>(fakeBoard, fakePlayerA, fakePlayerB));
        }
Ejemplo n.º 16
0
        public void TakeActionEnds_ShouldIndicateGameEnds()
        {
            //Arrange
            FakeBoard fakeBoard = new FakeBoard.Builder()
                                  .ClaimEndsGame(Bool.True)
                                  .Build();
            FakeCell             fakeCell             = new FakeCell.Builder().Build();
            FakeSelectMoveAction fakeSelectMoveAction = new FakeSelectMoveAction.Builder().Act(fakeCell).Build();
            TestPlayer           subject = new TestPlayer(fakeSelectMoveAction);

            //Act
            subject.TakeAction(fakeBoard, null);

            //Assert
            fakeBoard.AssertClaimEndsGameInvoked();
        }
Ejemplo n.º 17
0
        public void AvailableSpaces_ShouldHaveOnlyAvailableCells()
        {
            //Arrange
            FakePrinter   fakePrinter      = new FakePrinter.Builder().Build();
            FakeGameState fakeGameState    = new FakeGameState.Builder().Build();
            FakeCell      fakeCell         = new FakeCell.Builder().IsSelected(Bool.False).Build();
            FakeCell      fakeCellSelected = new FakeCell.Builder().IsSelected(Bool.True).Build();
            Board         subject          = new Board(new CellCollection(new ICell[] { fakeCell, fakeCellSelected }),
                                                       fakeGameState, fakePrinter);

            //Act
            ICellCollection actual = subject.AvailableSpaces();

            //Assert
            ((int)actual.Count()).Should().Be(1);
        }
Ejemplo n.º 18
0
        public void ShouldReturnFalseWhenNotAllSelected()
        {
            //Arrange
            FakeCell     fakeCell = new FakeCell.Builder().IsSelected(Bool.False).Build();
            List <ICell> cells    = new List <ICell>()
            {
                fakeCell
            };
            FakeCellCollection fakeCellCollection = new FakeCellCollection.Builder().GetEnumerator(cells.GetEnumerator()).Build();
            AllCellsSelected   subject            = new AllCellsSelected(fakeCellCollection);

            //Act
            bool actual = subject;

            //Assert
            actual.Should().BeFalse();
        }
Ejemplo n.º 19
0
        public void ClaimEndsGame_ReturnTrueWhenOver()
        {
            //Arrange
            FakePrinter        fakePrinter        = new FakePrinter.Builder().Build();
            FakeCell           fakeCell           = new FakeCell.Builder().Build();
            FakeCellCollection fakeCellCollection = new FakeCellCollection.Builder()
                                                    .UpdateTo()
                                                    .Build();
            FakeGameState fakeGameState = new FakeGameState.Builder().IsGameOver(Bool.True).Build();
            FakePlayer    fakePlayer    = new FakePlayer.Builder().Cell(fakeCell).Build();
            Board         subject       = new Board(fakeCellCollection, fakeGameState, fakePrinter);

            //Act
            Bool actual = subject.ClaimEndsGame(null, fakePlayer);

            //Assert
            ((bool)actual).Should().BeTrue();
        }
        public void Act_ShouldReturnAvailableCell()
        {
            //Arrange
            FakeCell  expected  = new FakeCell.Builder().Value("1").Build();
            FakeBoard fakeBoard = new FakeBoard.Builder()
                                  .Available(Bool.False, Bool.False, Bool.False, Bool.True).Build();
            FakeCell              fakeCell        = new FakeCell.Builder().Build();
            FakePlayer            fakePlayer      = new FakePlayer.Builder().Cell(fakeCell).Build();
            FakePlayer            fakePlayerOther = new FakePlayer.Builder().Build();
            FakeMoveInput         fakeMoveInput   = new FakeMoveInput.Builder().Input(new Glyph('1')).Build();
            HumanSelectMoveAction subject         = new HumanSelectMoveAction(fakeMoveInput);

            //Act
            ICell actual = subject.Act(fakeBoard, fakePlayer, fakePlayerOther);

            //Assert
            actual.Value().Should().Be(expected.Value());
        }
Ejemplo n.º 21
0
        public void ClaimEndsGame_ShouldClaimCellForPlayer()
        {
            //Arrange
            FakePrinter     fakePrinter      = new FakePrinter.Builder().Build();
            FakeCell        fakeCellBoard    = new FakeCell.Builder().IsSelected(Bool.False).Value("1").Build();
            FakeCell        fakeCellSelected = new FakeCell.Builder().IsSelected(Bool.False).Value("1").Build();
            FakeCell        fakeCellPlayer   = new FakeCell.Builder().AsSelected(fakeCellSelected).Value("1").Build();
            ICellCollection cellCollection   = new CellCollection(new ICell[] { fakeCellBoard });
            FakeGameState   fakeGameState    = new FakeGameState.Builder().IsGameOver(Bool.False).Build();
            FakePlayer      fakePlayer       = new FakePlayer.Builder().Cell(fakeCellPlayer).Build();
            Board           subject          = new Board(cellCollection, fakeGameState, fakePrinter);

            //Act
            subject.ClaimEndsGame(fakeCellBoard, fakePlayer);

            //Assert
            cellCollection.At(new IntOf(0)).Should().NotBe(fakeCellBoard);
        }
Ejemplo n.º 22
0
        public void ShouldReturnPlayersTurns()
        {
            //Arrange
            FakeCell             fakeCell           = new FakeCell.Builder().Value("?").Build();
            FakePlayer           fakePlayer         = new FakePlayer.Builder().Cell(fakeCell).Build();
            FakePlayer           fakePlayer2        = new FakePlayer.Builder().Build();
            FakePlayerCreation   fakePlayerCreation = new FakePlayerCreation.Builder().Player(fakePlayer, fakePlayer2).Build();
            FakeBoard            fakeBoard          = new FakeBoard.Builder().Build();
            HumanVsHumanGameMode subject            = new HumanVsHumanGameMode(fakePlayerCreation, fakePlayerCreation);

            //Act
            IPlayersTurns actual = subject.ConfigurePlayers(fakeBoard);

            //Assert
            actual.Should().BeOfType <PlayersTurns>();
            fakePlayerCreation.PlayerInvokedWith("");
            fakePlayerCreation.PlayerInvokedWith("?");
        }
Ejemplo n.º 23
0
        public void ShouldReturnPlayersTurnsComputerAsX()
        {
            //Arrange
            FakeCell   fakeCell           = new FakeCell.Builder().Value("O").Build();
            FakePlayer fakePlayer         = new FakePlayer.Builder().Cell(fakeCell).Build();
            FakePlayer fakePlayerComputer = new FakePlayer.Builder().Build();
            FakeValidResponse <IPlayerOrder> fakeValidResponse = new FakeValidResponse <IPlayerOrder> .Builder().Response(new HumanFirstOrder()).Build();

            FakePlayerCreation      fakePlayerCreation = new FakePlayerCreation.Builder().Player(fakePlayer, fakePlayerComputer).Build();
            FakeBoard               fakeBoard          = new FakeBoard.Builder().Build();
            HumanVsComputerGameMode subject            = new HumanVsComputerGameMode(fakeValidResponse, fakePlayerCreation, fakePlayerCreation);

            //Act
            IPlayersTurns actual = subject.ConfigurePlayers(fakeBoard);

            //Assert
            actual.Should().BeOfType <PlayersTurns>();
            fakePlayerCreation.PlayerInvokedWith("");
            fakePlayerCreation.PlayerInvokedWith("X");
        }
Ejemplo n.º 24
0
        public void Act_ShouldSelectRandomSpace()
        {
            //Arrange
            Int                expectedMax        = new IntOf(57);
            FakeCell           fakeCell           = new FakeCell.Builder().Build();
            FakeCellCollection fakeCellCollection = new FakeCellCollection.Builder()
                                                    .Count(expectedMax)
                                                    .At(fakeCell)
                                                    .Build();
            FakeBoard fakeBoard = new FakeBoard.Builder()
                                  .AvailableSpaces(fakeCellCollection)
                                  .Build();
            RandomSpaceSelectMoveAction subject = new RandomSpaceSelectMoveAction();

            //Act
            ICell actual = subject.Act(fakeBoard, null, null);

            //Assert
            actual.Should().BeOfType <RandomCell>();
        }