コード例 #1
0
ファイル: BoardTest.cs プロジェクト: MACSkeptic/minesweeper
        public void ShouldKeepTheStateOfTheBoardAsTheCellsAreOpened()
        {
            var board = new Board(4);
            board.AddBombAt(0, 1);
            board.AddBombAt(1, 0);
            board.AddBombAt(1, 1);

            board.State.Each(
                row => row.Each(
                    cellState => Assert.IsFalse(cellState.IsOpen)));

            board.Open(0, 0);
            Assert.IsFalse(board.State[0][1].IsOpen);
            Assert.IsFalse(board.State[1][0].IsOpen);
            Assert.IsFalse(board.State[1][1].IsOpen);
            Assert.IsFalse(board.State[2][2].IsOpen);
            Assert.IsTrue(board.State[0][0].IsOpen);
            Assert.AreEqual(3, board.State[0][0].HowManyBombsAround);

            board.Open(3, 3);
            Assert.IsFalse(board.State[0][1].IsOpen);
            Assert.IsFalse(board.State[1][0].IsOpen);
            Assert.IsFalse(board.State[1][1].IsOpen);
            Assert.IsTrue(board.State[2][2].IsOpen);
            Assert.IsTrue(board.State[2][3].IsOpen);
            Assert.IsTrue(board.State[3][2].IsOpen);
            Assert.IsTrue(board.State[3][3].IsOpen);
            Assert.AreEqual(2, board.State[1][2].HowManyBombsAround);
            Assert.AreEqual(2, board.State[2][1].HowManyBombsAround);
            Assert.AreEqual(1, board.State[2][2].HowManyBombsAround);
        }
コード例 #2
0
        public void ShouldProvideABoardToPlayTheGame()
        {
            board = new Board(9);
            var moqBoardGenerator = createMock();
            var controller = new GameController(moqBoardGenerator.Object);
            var result = controller.Index() as ViewResult;

            Assert.IsNotNull(result.Model);
            moqBoardGenerator.Verify();
        }
コード例 #3
0
ファイル: BoardTest.cs プロジェクト: MACSkeptic/minesweeper
 public void ShouldCountTheBombsAround()
 {
     var board = new Board(2);
     board.AddBombAt(1, 1);
     var result = board.Open(1, 0);
     var cell = new Cell(new CellContents(false), new Position(1, 0));
     cell.Open();
     var expectedResult = new CellState(cell, 1);
     Assert.AreEqual(expectedResult, result);
 }
コード例 #4
0
        public void ShouldReturnFalseWhenDoesntHaveBomb()
        {
            var moqBoardGenerator = createMock();
            var controller = new GameController(moqBoardGenerator.Object);
            int row = 1;
            int col = 2;
            board = new Board(9);
            var session = new SessionStateItemCollection();
            session["board"] = board;
            controller.ControllerContext = new FakeControllerContext(controller, session);

            var result = controller.HasBomb(row, col);
            Assert.IsFalse((bool)result.Data);
        }
コード例 #5
0
        public Mock<RandomBoardGenerator> createMock()
        {
            var moqBoardGenerator = new Mock<RandomBoardGenerator>();
            board = new Board(9);
            board.AddBombAt(1, 2);

            var session = new SessionStateItemCollection();
            session["board"] = board;
            moqBoardGenerator
                .Setup(x => x.Generate(It.IsAny<Func<ISizeOfBoard, Board>>()))
                .Returns(board);

            return moqBoardGenerator;
        }
コード例 #6
0
ファイル: BoardTest.cs プロジェクト: MACSkeptic/minesweeper
        public void ShouldConsiderTheGameToBeWonIfAllTheClosedCellsRemainingAreBombs()
        {
            var board = new Board(2);
            board.AddBombAt(0, 0);

            Assert.IsFalse(board.IsWin);

            board.Open(1, 1);
            Assert.IsFalse(board.IsWin);
            board.Open(0, 1);
            Assert.IsFalse(board.IsWin);

            board.Open(1, 0);
            Assert.IsTrue(board.IsWin);
        }
コード例 #7
0
        public void ShouldReturnTrueWhenCellHasBomb()
        {
            var session = new SessionStateItemCollection();
            board = new Board(9);
            board.AddBombAt(1, 2);
            session["board"] = board;

            var moqBoardGenerator = createMock();
            var controller = new GameController(moqBoardGenerator.Object);
            controller.ControllerContext = new FakeControllerContext(controller, session);
            int row = 1;
            int col = 2;

            JsonResult result = controller.HasBomb(row, col);
            Assert.IsTrue((bool)result.Data);
        }
コード例 #8
0
ファイル: BoardTest.cs プロジェクト: MACSkeptic/minesweeper
        public void ShouldConsiderTheGameAsOverIfABombCellIsOpened()
        {
            var board = new Board(2);
            board.AddBombAt(0, 0);

            Assert.IsFalse(board.IsGameOver);

            board.Open(1, 1);
            Assert.IsFalse(board.IsGameOver);
            board.Open(0, 1);
            Assert.IsFalse(board.IsGameOver);
            board.Open(1, 0);
            Assert.IsFalse(board.IsGameOver);

            board.Open(0, 0);
            Assert.IsTrue(board.IsGameOver);
        }
コード例 #9
0
ファイル: BoardTest.cs プロジェクト: MACSkeptic/minesweeper
 public void ShouldProvideAMechanismToOpenACell()
 {
     var board = new Board(2);
     var result = board.Open(1, 1);
     var cell = new Cell(new CellContents(false), new Position(1, 1));
     cell.Open();
     var expectedResult = new CellState(cell, 0);
     Assert.AreEqual(expectedResult, result);
 }
コード例 #10
0
ファイル: BoardTest.cs プロジェクト: MACSkeptic/minesweeper
        public void ShouldProvideAMechanismToCheckIfACellIsOpen()
        {
            var board = new Board(2);

            Assert.IsFalse(board.IsOpen(1, 1));

            board.Open(1, 1);

            Assert.IsTrue(board.IsOpen(1, 1));
        }
コード例 #11
0
ファイル: BoardTest.cs プロジェクト: MACSkeptic/minesweeper
        public void ShouldOpenAdjacentCellsIfTheOneBeingOpenedHasNoBombsAroundAndNoBomb()
        {
            var board = new Board(10);
            board.AddBombAt(0, 0);

            board.Open(0, 0);
            Assert.IsTrue(board.IsOpen(0, 0));
            Assert.IsFalse(board.IsOpen(0, 1));
            Assert.IsFalse(board.IsOpen(1, 0));
            Assert.IsFalse(board.IsOpen(1, 1));

            board.AddBombAt(5, 5);
            board.Open(5, 6);
            Assert.IsFalse(board.IsOpen(5, 5));
            Assert.IsFalse(board.IsOpen(5, 7));
            Assert.IsFalse(board.IsOpen(4, 6));
            Assert.IsFalse(board.IsOpen(6, 5));

            board.Open(9, 9);
            Assert.IsTrue(board.IsOpen(9, 9));
            Assert.IsTrue(board.IsOpen(9, 8));
            Assert.IsTrue(board.IsOpen(9, 7));
            Assert.IsTrue(board.IsOpen(9, 6));
            Assert.IsTrue(board.IsOpen(9, 5));
            Assert.IsTrue(board.IsOpen(9, 4));
            Assert.IsTrue(board.IsOpen(9, 3));
            Assert.IsTrue(board.IsOpen(8, 2));
            Assert.IsTrue(board.IsOpen(8, 4));
            Assert.IsTrue(board.IsOpen(8, 3));
            Assert.IsTrue(board.IsOpen(7, 2));
        }
コード例 #12
0
 public INumberOfBombsOfBoard WithSize(int size)
 {
     _board = new Board(_size = size);
     return this;
 }