def test_load_data_from_input(self): """ Test if data are loaded correctly. Attributes: self: self """ inputs_in_order = ['5', '5', '5'] minesweeper = minesweeper_generator.Minesweeper(5, 5, 5) with patch('builtins.input', side_effect=inputs_in_order): result = minesweeper_generator.load_data_from_input() self.assertEqual(result.rows, minesweeper.rows) self.assertEqual(result.cols, minesweeper.cols) self.assertEqual(result.count_of_mines, minesweeper.count_of_mines)
def setUp(self) -> None: """ Set up minesweeper. Attributes: self: self Returns: None """ self.minesweeper = minesweeper_generator.Minesweeper(3, 3, 6) self.minesweeper.playground = [['#', '#', '#', '#', '#'], ['#', '*', ' ', '*', '#'], ['#', ' ', '*', '*', '#'], ['#', '*', '*', ' ', '#'], ['#', '#', '#', '#', '#']]
def test_put_mines_to_playground(self): """ Test if zero mines were put to playground. Attributes: self: self """ minesweeper = minesweeper_generator.Minesweeper(5, 5, 0) minesweeper_generator.put_mines_to_playground(minesweeper) expected_array = [['#', '#', '#', '#', '#', '#', '#'], ['#', ' ', ' ', ' ', ' ', ' ', '#'], ['#', ' ', ' ', ' ', ' ', ' ', '#'], ['#', ' ', ' ', ' ', ' ', ' ', '#'], ['#', ' ', ' ', ' ', ' ', ' ', '#'], ['#', ' ', ' ', ' ', ' ', ' ', '#'], ['#', '#', '#', '#', '#', '#', '#']] self.assertListEqual(minesweeper.playground, expected_array)
def test_put_numbers_to_playground(self): """ Test if the numbers of near mines are correct. Attributes: self: self """ minesweeper = minesweeper_generator.Minesweeper(5, 5, 6) expected_minesweeper = [['#', '#', '#', '#', '#', '#', '#'], ['#', '*', 2, 1, 1, 1, '#'], ['#', '*', 2, 1, '*', 1, '#'], ['#', 1, 1, 2, 3, 3, '#'], ['#', 1, 1, 1, '*', '*', '#'], ['#', '*', 1, 1, 2, 2, '#'], ['#', '#', '#', '#', '#', '#', '#']] minesweeper.playground = [['#', '#', '#', '#', '#', '#', '#'], ['#', '*', ' ', ' ', ' ', ' ', '#'], ['#', '*', ' ', ' ', '*', ' ', '#'], ['#', ' ', ' ', ' ', ' ', ' ', '#'], ['#', ' ', ' ', ' ', '*', '*', '#'], ['#', '*', ' ', ' ', ' ', ' ', '#'], ['#', '#', '#', '#', '#', '#', '#']] minesweeper_generator.put_numbers_to_playground(minesweeper) self.assertEqual(minesweeper.playground, expected_minesweeper)
def test_print_playground(self): """ Test if playground was printed correctly. Attributes: self: self """ minesweeper = minesweeper_generator.Minesweeper(5, 5, 6) minesweeper.playground = [['#', '#', '#', '#', '#', '#', '#'], ['#', '*', 2, 1, 1, 1, '#'], ['#', '*', 2, 1, '*', 1, '#'], ['#', 1, 1, 2, 3, 3, '#'], ['#', 1, 1, 1, '*', '*', '#'], ['#', '*', 1, 1, 2, 2, '#'], ['#', '#', '#', '#', '#', '#', '#']] with patch('builtins.print') as fake_stdout: minesweeper_generator.print_playground(minesweeper) fake_stdout.assert_has_calls([ call('#', end=' '), call('#', end=' '), call('#', end=' '), call('#', end=' '), call('#', end=' '), call('#', end=' '), call('#', end=' '), call(), call('#', end=' '), call('*', end=' '), call(2, end=' '), call(1, end=' '), call(1, end=' '), call(1, end=' '), call('#', end=' '), call(), call('#', end=' '), call('*', end=' '), call(2, end=' '), call(1, end=' '), call('*', end=' '), call(1, end=' '), call('#', end=' '), call(), call('#', end=' '), call(1, end=' '), call(1, end=' '), call(2, end=' '), call(3, end=' '), call(3, end=' '), call('#', end=' '), call(), call('#', end=' '), call(1, end=' '), call(1, end=' '), call(1, end=' '), call('*', end=' '), call('*', end=' '), call('#', end=' '), call(), call('#', end=' '), call('*', end=' '), call(1, end=' '), call(1, end=' '), call(2, end=' '), call(2, end=' '), call('#', end=' '), call(), call('#', end=' '), call('#', end=' '), call('#', end=' '), call('#', end=' '), call('#', end=' '), call('#', end=' '), call('#', end=' '), call() ])