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); }
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(); }
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(); }
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(); }
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(); }
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(); }
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!"); }
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(); }
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); }
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"); }
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)); }
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(); }
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); }
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(); }
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()); }
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); }
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("?"); }
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"); }
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>(); }