def testIfTryToFindDataFromInvalidColumnThenShouldTrowAnException(self): sudoku = SudokuBoard(3) try: sudoku.get_value('C', 4) self.fail("Did not raise the exception InvalidColumnException") except InvalidColumnException: pass
def testIfTryToUpdateDataInAnInvalidColumnThenShouldTrowAnException(self): sudoku = SudokuBoard() try: sudoku.set_value('A', 10, '5') self.fail("Did not raise the exception InvalidColumnException") except InvalidColumnException: pass
def testWhenTryToSetAnInvalidValueThehnShouldRaiseanException(self): sudoku = SudokuBoard(3) try: sudoku.set_value('C', 2, '5') self.fail("Did not raise the exception InvalidParameterValueException") except InvalidParameterValueException: pass
def testWhenTrySetDateInCorrectAndNonEditableCellThenShouldThrownAnException(self): sudoku = SudokuBoard(3) sudoku.set_editable('C', 2, False) try: sudoku.set_value('C', 2, '2') self.fail("Did not raise the exception CellNotEditableException") except CellNotEditableException: pass
def test_test(self): sudoku = SudokuBoard(3) sudoku.from_dictionary(self.dic_with_data, True) self.assertFalse(sudoku.dic['A3'].is_editable()) self.assertFalse(sudoku.dic['B2'].is_editable()) self.assertTrue(sudoku.dic['B1'].is_editable()) self.assertTrue(sudoku.dic['B3'].is_editable())
def test_given_a_dictionary_with_invalid_values_then_should_raise_an_exception(self): sudoku = SudokuBoard(3) try: sudoku.from_dictionary(self.dic_with_invalid_values) self.fail("Did not raise the exception InvalidParameterValueException") except InvalidParameterValueException: pass
def test_given_an_invalid_dictionary_size_then_should_raise_an_exception(self): sudoku = SudokuBoard() try: sudoku.from_dictionary(self.dic_with_data) self.fail("Did not raise the exception InvalidDictionarySizeException") except InvalidDictionarySizeException: pass
def test_given_a_sudoku_table_then_should_convert_it_to_dictionary(self): sudoku = SudokuBoard(3) rows = ['A', 'B', 'C'] cols = range(1, 4) for row in rows: for col in cols: sudoku.set_value(row, col, self.dic_with_data[row + str(col)]) dictionary = sudoku.to_dictionary() self.assertDictEqual(self.dic_with_data, dictionary)
def test_given_a_valid_dictionary_then_should_convert_it_to_sudoku_table(self): sudoku = SudokuBoard(3) sudoku.from_dictionary(self.dic_with_data) rows = ['A', 'B', 'C'] cols = range(1, 4) self.assertEqual(len(self.dic_with_data), len(sudoku.dic)) for row in rows: for col in cols: self.assertEqual(self.dic_with_data[row + str(col)], sudoku.get_value(row, col))
def ifASukokuTableIsCreatedThenTheDictionaryStructureShouldHaveTheRightSizeOfRecordsWithDefaultInformation(self): sudoku = SudokuBoard(3) self.assertEqual(3, sudoku.size) self.assertEqual(9, len(sudoku.dic)) cols = [1, 2, 3] rows = ['A', 'B', 'C'] for row in rows: for col in cols: Cell = sudoku.getCell(row, col) value = Cell.get_value() editable = Cell.iseditable() self.assertEqual('0', value) self.assertTrue(editable)
def test_given_a_valid_parameters_then_should_set_the_hint_value_in_the_soduko_board(self): initial_sudoku = SudokuBoard(3) user_sudoku = SudokuBoard(3) solved_sudoku = SudokuBoard(3) initial_sudoku.from_dictionary(self.solved_sudoku) user_sudoku.from_dictionary(self.user_sudoku) solved_sudoku.from_dictionary(self.solved_sudoku) game = Game() game.started = True game.initial_sudoku = initial_sudoku game.user_sudoku = user_sudoku game.solved_sudoku = solved_sudoku cmd = HintCommand(self.hint_parameters) cmd.set_game(game) cmd.execute() self.assertEqual(game.solved_sudoku.dic[self.cell].value, game.user_sudoku.dic[self.cell].value)
def test_when_restart_game_is_executed_then_the_user_table_should_be_restarted_properly(self): sudoku = SudokuBoard(3) user_sudoku = SudokuBoard(3) sudoku.from_dictionary(self.solved_sudoku, True) user_sudoku.from_dictionary(self.user_sudoku, True) game = Game() game.initial_sudoku = sudoku game.user_sudoku = user_sudoku cmd = RestartGameCommand(None) cmd.set_game(game) cmd.execute() self.assertDictEqual(game.initial_sudoku.to_dictionary(), game.user_sudoku.to_dictionary())
def testWhenTrySetDataInCorrectAndEditableCellThenShouldSetDataProperly(self): sudoku = SudokuBoard(3) sudoku.set_value('C', 2, '2') self.assertEqual('2', sudoku.dic['C2'].get_value())
def testIfTryToFindDataInRightCellThenShouldFindTheCorrectData(self): sudoku = SudokuBoard(3) sudoku.dic['C2'].set_value('4') value = sudoku.get_value('C', 2) self.assertEqual('4', value)
def testIfTryToAddDataInRightCellThenShouldAddTheDataProperly(self): sudoku = SudokuBoard(18) sudoku.set_value('B', 2, '5') self.assertEqual('5', sudoku.dic['B2'].get_value())