Exemplo n.º 1
0
 def testIfTryToFindDataFromInvalidColumnThenShouldTrowAnException(self):
     sudoku = SudokuBoard(3)
     try:
         sudoku.get_value('C', 4)
         self.fail("Did not raise the exception InvalidColumnException")
     except InvalidColumnException:
         pass
Exemplo n.º 2
0
 def testIfTryToUpdateDataInAnInvalidColumnThenShouldTrowAnException(self):
     sudoku = SudokuBoard()
     try:
         sudoku.set_value('A', 10, '5')
         self.fail("Did not raise the exception InvalidColumnException")
     except InvalidColumnException:
         pass
Exemplo n.º 3
0
 def testWhenTryToSetAnInvalidValueThehnShouldRaiseanException(self):
     sudoku = SudokuBoard(3)
     try:
         sudoku.set_value('C', 2, '5')
         self.fail("Did not raise the exception InvalidParameterValueException")
     except InvalidParameterValueException:
         pass
Exemplo n.º 4
0
 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
Exemplo n.º 5
0
 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())
Exemplo n.º 6
0
 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
Exemplo n.º 7
0
 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
Exemplo n.º 8
0
 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)
Exemplo n.º 9
0
 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))
Exemplo n.º 10
0
 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)
Exemplo n.º 11
0
 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)
Exemplo n.º 12
0
 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())
Exemplo n.º 13
0
 def testWhenTrySetDataInCorrectAndEditableCellThenShouldSetDataProperly(self):
     sudoku = SudokuBoard(3)
     sudoku.set_value('C', 2, '2')
     self.assertEqual('2', sudoku.dic['C2'].get_value())
Exemplo n.º 14
0
 def testIfTryToFindDataInRightCellThenShouldFindTheCorrectData(self):
     sudoku = SudokuBoard(3)
     sudoku.dic['C2'].set_value('4')
     value = sudoku.get_value('C', 2)
     self.assertEqual('4', value)
Exemplo n.º 15
0
 def testIfTryToAddDataInRightCellThenShouldAddTheDataProperly(self):
     sudoku = SudokuBoard(18)
     sudoku.set_value('B', 2, '5')
     
     self.assertEqual('5', sudoku.dic['B2'].get_value())