public void TestPrintAllFields() { using (StringWriter sw = new StringWriter()) { Console.SetOut(sw); using (StringReader sr = new StringReader(string.Format(" 0 " + Environment.NewLine + " ╔═══╗" + Environment.NewLine + "0 ║ 0 ║" + Environment.NewLine + " ╚═══╝" + Environment.NewLine))) { Console.SetIn(sr); Renderer ab = new Renderer(); IBoard gameMatrix = new Board(1, 1, 0); IBoardScanner scanner = new BoardScanner(gameMatrix); ab.PrintAllFields(gameMatrix, scanner); string expected = string.Format(" 0 " + Environment.NewLine + " ╔═══╗" + Environment.NewLine + "0 ║ 0 ║" + Environment.NewLine + " ╚═══╝" + Environment.NewLine); Assert.AreEqual <string>(expected, sw.ToString()); } } }
public void ScanningForMinesWhereNoMinesSetTest() { var board = new Board(4, 4, 1); var boardScanner = new BoardScanner(board); int expected = 0; int actual = boardScanner.ScanSurroundingFields(2, 0); Assert.AreEqual(expected, actual); }
public void OpenFieldSuccessfullyTest() { var board = new Board(4, 4, 1); var boardScanner = new BoardScanner(board); var boardManager = new BoardManager(board, boardScanner); var bombSetter = new MineSetter(new RandomGeneratorForTesting(2)); board.Accept(bombSetter); var openedField = boardManager.OpenField(2, 1); Assert.AreEqual(openedField, BoardStatus.SuccessfullyOpened); }
public void OpenFieldWithBombTest() { var board = new Board(4, 4, 1); var boardScanner = new BoardScanner(board); var boardManager = new BoardManager(board, boardScanner); var bombSetter = new MineSetter(new RandomGeneratorForTesting(1)); board.Accept(bombSetter); var openedField = boardManager.OpenField(1, 1); Assert.AreEqual(openedField, BoardStatus.SteppedOnAMine); }
public void OpenFieldWhichIsAlreadyOpened() { var board = new Board(4, 4, 1); var boardScanner = new BoardScanner(board); var boardManager = new BoardManager(board, boardScanner); var bombSetter = new MineSetter(new RandomGeneratorForTesting(2)); board.Accept(bombSetter); var openedField = boardManager.OpenField(2, 1); var secondOpeningField = boardManager.OpenField(2, 1); Assert.AreEqual(secondOpeningField, BoardStatus.AlreadyOpened); }
public void ScanningWhenTwoBombsAreAround() { var board = new Board(4, 4, 1); var boardScanner = new BoardScanner(board); var bombSetter = new MineSetter(new RandomGeneratorForTesting(3)); var bombSetter2 = new MineSetter(new RandomGeneratorForTesting(2)); board.Accept(bombSetter); board.Accept(bombSetter2); int expected = 2; int actual = boardScanner.ScanSurroundingFields(2, 3); Assert.AreEqual(expected, actual); }
public void ScanningForMinesTest() { var board = new Board(4, 4, 1); var boardScanner = new BoardScanner(board); var bombSetter = new MineSetter(new RandomGeneratorForTesting(3)); board.Accept(bombSetter); var fieldWithBomb = board.FieldsMatrix[3, 3]; Assert.AreEqual(fieldWithBomb, new Field(0, FieldStatus.IsAMine)); var adjacentField = board.FieldsMatrix[2, 3]; int minesAround = boardScanner.ScanSurroundingFields(2, 3); Assert.AreEqual(1, minesAround); }
public BoardScannerTests() { _boardScanner = new BoardScanner(); _gameBoard = new GameBoard(); }