public SetStoneGameState(PlayingBoard playingBoard, Stone nextStone, Player newPlayer) : base(playingBoard, nextStone, newPlayer) { if (nextStone == null) { throw new ArgumentNullException("nextStone"); } }
public void Ctor_WithNextStoneAlreadyPresentOnPlayingField_ThrowsArgumentException() { var playfield = new PlayingBoard(); playfield = playfield.SetStone(0, 0, this._sampleStone); Action call = () => Substitute.For<GameStateBase>(playfield, this._sampleStone, Player.One); call.ShouldThrow<TargetInvocationException>().WithInnerException<ArgumentException>(); }
public void GetAllFields_WithOneStonesSet_ReturnsTheSetStone() { var objectUnderTest = new PlayingBoard().SetStone(0, 0, this._sampleStoneOne); var result = objectUnderTest.GetAllFields(); result.Should().Contain(this._sampleStoneOne); }
public void Ctor_WithANonNullPlayfieldAndANotSetNextStone_DoesNotThrowAnException() { var notSetStone = new Stone(Size.High, Surface.Flat, Color.Black, Shape.Square); var playfield = new PlayingBoard(); playfield = playfield.SetStone(0, 0, this._sampleStone); Action call = () => Substitute.For<GameStateBase>(playfield, notSetStone, Player.One); call.ShouldNotThrow(); }
public void GetDiagonals_WithStonesSet_ReturnsExpectedDiagonals() { this._objectUnderTest = this._objectUnderTest.SetStone(1, 1, this._sampleStoneOne); this._objectUnderTest = this._objectUnderTest.SetStone(2, 3, this._sampleStoneTwo); var result = this._objectUnderTest.GetDiagonals().ToArray(); result[0].Should().BeEquivalentTo(new Stone[] {null, this._sampleStoneOne, null, null}, "diagonal 0 must match"); result[1].Should().BeEquivalentTo(new Stone[] {null, null, null, null}, "diagonal 1 must match"); }
public void GetAllLines_ReturnsTenLines() { var pb = new PlayingBoard(); var result = pb.GetAllLines(); result.Should().NotBeNull(); result.Should().HaveCount(10); }
public static IEnumerable <IEnumerable <Stone> > GetAllLines(this PlayingBoard playingBoard) { if (playingBoard == null) { throw new ArgumentNullException("playingBoard"); } return(playingBoard.GetColumns().Concat(playingBoard.GetRows()).Concat(playingBoard.GetDiagonals())); }
public static IEnumerable <Stone> GetAllFields(this PlayingBoard playingBoard) { if (playingBoard == null) { throw new ArgumentNullException("playingBoard"); } return(playingBoard.GetRows().SelectMany(r => r)); }
public void GetRows_WithStonesSet_ReturnsExpectedRows() { this._objectUnderTest = this._objectUnderTest.SetStone(0, 1, this._sampleStoneOne); this._objectUnderTest = this._objectUnderTest.SetStone(2, 3, this._sampleStoneTwo); var result = this._objectUnderTest.GetRows().ToArray(); result.Should().HaveCount(4); result[0].Should().BeEquivalentTo(new Stone[] {null, this._sampleStoneOne, null, null}, "row 0 must match"); result[1].Should().BeEquivalentTo(new Stone[] {null, null, null, null}, "row 1 must match"); result[2].Should().BeEquivalentTo(new Stone[] {null, null, null, this._sampleStoneTwo}, "row 2 must match"); result[3].Should().BeEquivalentTo(new Stone[] {null, null, null, null}, "row 3 must match"); }
protected GameStateBase(PlayingBoard playingBoard, Stone nextStone, Player currentPlayer) { if (playingBoard == null) { throw new ArgumentNullException("playingBoard"); } if (nextStone != null) { if (playingBoard.GetAllFields().Contains(nextStone)) { throw new ArgumentException("nextStone is already set on the playing board.", "nextStone"); } } this._playingBoard = playingBoard; this._nextStone = nextStone; this._currentPlayer = currentPlayer; this._isWinState = new Lazy <bool>(() => DetectIsWinState(this)); }
protected GameStateBase(PlayingBoard playingBoard, Stone nextStone, Player currentPlayer) { if (playingBoard == null) { throw new ArgumentNullException("playingBoard"); } if (nextStone != null) { if (playingBoard.GetAllFields().Contains(nextStone)) { throw new ArgumentException("nextStone is already set on the playing board.", "nextStone"); } } this._playingBoard = playingBoard; this._nextStone = nextStone; this._currentPlayer = currentPlayer; this._isWinState = new Lazy<bool>(() => DetectIsWinState(this)); }
public ChooseStoneGameState(PlayingBoard playingBoard, Player currentPlayer) : base(playingBoard, null, currentPlayer) { }
public void SetUp() { this._objectUnderTest = new PlayingBoard(); }