def test_with_two_flag_toggles_should_notify_observer_with_board(self): keyword_args_0 = self.simulate_create_board(row_count=3, column_count=5, row_index=0, column_index=1) turn_0 = keyword_args_0['first_turn'] minefield_identifier = keyword_args_0['minefield_identifier'] kewyword_args_1 = self.simulate_toggle_flag(column_index=0, row_index=0, parent_turn_identifier=turn_0.identifier, minefield_identifier=minefield_identifier) turn_1 = kewyword_args_1['turn'] kewyword_args_2 = self.simulate_toggle_flag(column_index=0, row_index=0, parent_turn_identifier=turn_1.identifier, minefield_identifier=minefield_identifier) turn_2 = kewyword_args_2['turn'] game_state_2 = kewyword_args_2['game_state'] keyword_args_3 = self.simulate_present_board(turn_identifier=turn_2.identifier) board_snapshot = keyword_args_3['board_snapshot'] expected_board_snapshot = [ [CellType.Unknown, CellType.Two, CellType.Unknown, CellType.Unknown, CellType.Unknown], [CellType.Unknown, CellType.Unknown, CellType.Unknown, CellType.Unknown, CellType.Unknown], [CellType.Unknown, CellType.Unknown, CellType.Unknown, CellType.Unknown, CellType.Unknown] ] assert_board_snapshots_equal(board_snapshot, expected_board_snapshot, self) self.assertEqual(game_state_2, GameState.Started)
def test_play_with_valid_dimensions_should_notify_observer_with_board_snapshot_after_second_turn(self): spy = Mock(GameObserver) self.subject.start_new_game(row_count=5, column_count=5, observer=spy) create_minefield = spy.game_did_create_board.call_args[1]['create_minefield'] create_minefield(row_index=0, column_index=4) call_args = spy.game_did_create_minefield.call_args[1] reveal_cell = call_args['reveal_cell'] reveal_cell(row_index=0, column_index=1) call_args = spy.game_did_take_turn.call_args[1] board_snapshot = call_args['board_snapshot'] expected_board_snapshot = [ [CellType.Unknown, CellType.Two, CellType.One, CellType.Zero, CellType.Zero], [CellType.Unknown, CellType.Unknown, CellType.Two, CellType.One, CellType.Zero], [CellType.Unknown, CellType.Unknown, CellType.Unknown, CellType.Two, CellType.One], [CellType.Unknown, CellType.Unknown, CellType.Unknown, CellType.Unknown, CellType.Unknown], [CellType.Unknown, CellType.Unknown, CellType.Unknown, CellType.Unknown, CellType.Unknown], ] assert_board_snapshots_equal(board_snapshot=board_snapshot, expected_board_snapshot=expected_board_snapshot, test_case=self)
def test_with_valid_parameters_should_notify_observer_with_board_snapshot(self): self.subject(row_count=5, column_count=5, observer=self.spy) board_snapshot = self.spy.did_create_board.call_args[1]['board_snapshot'] expected_board_snapshot = [ [CellType.Unknown, CellType.Unknown, CellType.Unknown, CellType.Unknown, CellType.Unknown], [CellType.Unknown, CellType.Unknown, CellType.Unknown, CellType.Unknown, CellType.Unknown], [CellType.Unknown, CellType.Unknown, CellType.Unknown, CellType.Unknown, CellType.Unknown], [CellType.Unknown, CellType.Unknown, CellType.Unknown, CellType.Unknown, CellType.Unknown], [CellType.Unknown, CellType.Unknown, CellType.Unknown, CellType.Unknown, CellType.Unknown] ] assert_board_snapshots_equal(board_snapshot, expected_board_snapshot, self)
def test_with_first_turn_should_notify_observer_with_board(self): kewyword_args_0 = self.simulate_create_board(row_count=3, column_count=5, row_index=0, column_index=1) first_turn = kewyword_args_0['first_turn'] keyword_args_1 = self.simulate_present_board(turn_identifier=first_turn.identifier) expected_board_snapshot = [ [CellType.Unknown, CellType.Two, CellType.Unknown, CellType.Unknown, CellType.Unknown], [CellType.Unknown, CellType.Unknown, CellType.Unknown, CellType.Unknown, CellType.Unknown], [CellType.Unknown, CellType.Unknown, CellType.Unknown, CellType.Unknown, CellType.Unknown] ] board_snapshot = keyword_args_1['board_snapshot'] assert_board_snapshots_equal(board_snapshot, expected_board_snapshot, self)
def test_play_with_valid_dimensions_should_notify_observer_with_board_snapshot_after_minefield_creation(self): first_turn = RawTurn(action=TurnAction.RevealCell, coordinate=Coordinate(row_index=0, column_index=4)) board_snapshot = self.simulate_start_game(row_count=5, column_count=5, turns=[first_turn]) expected_board_snapshot = [ [CellType.Unknown, CellType.Unknown, CellType.One, CellType.Zero, CellType.Zero], [CellType.Unknown, CellType.Unknown, CellType.Two, CellType.One, CellType.Zero], [CellType.Unknown, CellType.Unknown, CellType.Unknown, CellType.Two, CellType.One], [CellType.Unknown, CellType.Unknown, CellType.Unknown, CellType.Unknown, CellType.Unknown], [CellType.Unknown, CellType.Unknown, CellType.Unknown, CellType.Unknown, CellType.Unknown], ] assert_board_snapshots_equal(board_snapshot=board_snapshot, expected_board_snapshot=expected_board_snapshot, test_case=self)
def test_play_with_valid_dimensions_should_notify_observer_with_board_snapshot(self): spy = Mock(GameObserver) self.subject.start_new_game(row_count=5, column_count=5, observer=spy) board_snapshot = spy.game_did_create_board.call_args[1]['board_snapshot'] expected_board_snapshot = [ [CellType.Unknown, CellType.Unknown, CellType.Unknown, CellType.Unknown, CellType.Unknown], [CellType.Unknown, CellType.Unknown, CellType.Unknown, CellType.Unknown, CellType.Unknown], [CellType.Unknown, CellType.Unknown, CellType.Unknown, CellType.Unknown, CellType.Unknown], [CellType.Unknown, CellType.Unknown, CellType.Unknown, CellType.Unknown, CellType.Unknown], [CellType.Unknown, CellType.Unknown, CellType.Unknown, CellType.Unknown, CellType.Unknown], ] assert_board_snapshots_equal(board_snapshot=board_snapshot, expected_board_snapshot=expected_board_snapshot, test_case=self)
def test_present_start_menu_options_should_notify_observer_with_present_create_board_options_callable(self): present_create_board_options = get_keywords(test_action_method=self.subject, keyword_argument='present_create_board_options', spy_class=PresentStartMenuOptionsUseCaseObserver, spied_upon_method_name='did_present_start_menu_options') create_board = get_keywords(test_action_method=present_create_board_options, keyword_argument='create_board', spy_class=PresentCreateBoardOptionsUseCaseObserver, spied_upon_method_name='did_present_create_board_options') create_board = partial(create_board.__call__, row_count=7, column_count=6) board = get_keywords(test_action_method=create_board, keyword_argument='board', spy_class=CreateBoardUseCaseObserver, spied_upon_method_name='did_create_board') expected_board = Board(row_count=7, column_count=6) assert_boards_equal(board=board, expected_board=expected_board, test_case=self) board_snapshot = get_keywords(test_action_method=create_board, keyword_argument='board_snapshot', spy_class=CreateBoardUseCaseObserver, spied_upon_method_name='did_create_board') expected_board_snapshot = [[CellType.Unknown for column in range(6)] for row in range(7)] assert_board_snapshots_equal(board_snapshot=board_snapshot, expected_board_snapshot=expected_board_snapshot, test_case=self)
def test_reveal_mine_should_notify_observer_with_board(self): keyword_args_0 = self.simulate_create_board(row_count=3, column_count=5, row_index=0, column_index=4) turn_0 = keyword_args_0['first_turn'] minefield_identifier = keyword_args_0['minefield_identifier'] keyword_args_1 = self.simulate_reveal_cell(column_index=0, row_index=0, parent_turn_identifier=turn_0.identifier, minefield_identifier=minefield_identifier) turn_1 = keyword_args_1['turn'] game_state_1 = keyword_args_1['game_state'] keyword_args_2 = self.simulate_present_board(turn_identifier=turn_1.identifier) board_snapshot = keyword_args_2['board_snapshot'] expected_board_snapshot = [ [CellType.Mine, CellType.Unknown, CellType.One, CellType.Zero, CellType.Zero], [CellType.Unknown, CellType.Mine, CellType.Two, CellType.One, CellType.Zero], [CellType.Unknown, CellType.Unknown, CellType.Mine, CellType.One, CellType.Zero] ] assert_board_snapshots_equal(board_snapshot, expected_board_snapshot, self) self.assertEqual(game_state_1, GameState.Lost)