Esempio n. 1
0
 def test_check_size(self):
     for i in range(1, 50):
         matrix = [[] for x in range(i)]
         for j in range(1, 50):
             for t in range(len(matrix)):
                 matrix[t] = [0 for y in range(j)]
             if ExtractInputData.is_square(i) and i == j:
                 self.assertTrue(
                     ExtractInputData.check_correct_size(matrix))
             else:
                 self.assertFalse(
                     ExtractInputData.check_correct_size(matrix))
Esempio n. 2
0
    def test_quick_transformation(self):
        list_of_lines1 = ['[1, 2, 3, 4]']
        result1 = [[1, 2, 3, 4], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
        quick_flag = True
        self.assertEqual(
            ExtractInputData.transformation(list_of_lines1, quick_flag),
            result1)
        list_of_lines2 = ['[0, 0, 0, 0]']

        result2 = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
        self.assertEqual(
            ExtractInputData.transformation(list_of_lines2, quick_flag),
            result2)
Esempio n. 3
0
    def test_read_incorrect_sudoku(self):
        source = tempfile.TemporaryFile('w+')
        source.write('[1, 2, 3, 4]\n' '[1,2,3,4\n' '[1 2 3 4]\n')
        source.seek(0)

        result = 2

        self.assertEqual(ExtractInputData.read_sudoku(source), result)
        source.close()
Esempio n. 4
0
 def test_transformation(self):
     list_of_lines = [
         '[1, 2, 3, 4]', '[5 6 7 8]', '[9,10,11,12]', '[12, 13, 14, 15]'
     ]
     result = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12],
               [12, 13, 14, 15]]
     quick_flag = False
     self.assertEqual(
         ExtractInputData.transformation(list_of_lines, quick_flag), result)
Esempio n. 5
0
    def test_read_fail_points(self):
        source = tempfile.TemporaryFile('w+')
        source.write('(1, 2)\n' '(1 2)\n' '(a,2)\n')
        source.seek(0)

        result = 3

        self.assertEqual(ExtractInputData.read_first_rule_points(source),
                         result)
        source.close()
Esempio n. 6
0
    def test_read_points(self):
        source = tempfile.TemporaryFile('w+')
        source.write('(1, 2)\n' '(1 2)\n' '(1,2)\n')
        source.seek(0)

        result = ExtractInputData.read_first_rule_points(source)[0]

        self.assertIsInstance(result, Point)
        self.assertEqual((result.row, result.column), (1, 2))
        source.close()
Esempio n. 7
0
def main():
    try:
        input_data_tuple_or_puzzle = ExtractInputData.input_puzzle()
    except ExtractInputDataExceptions as error:
        print_error(error)

    if isinstance(input_data_tuple_or_puzzle, list):
        puzzle = input_data_tuple_or_puzzle
        print_puzzle(puzzle)
    else:
        puzzle = input_data_tuple_or_puzzle[0]
        additional_params = input_data_tuple_or_puzzle[1]
        list_of_first_rule_point = input_data_tuple_or_puzzle[2]
        solve = input_data_tuple_or_puzzle[3]

        if solve and additional_params.gui_off:
            print_puzzle(puzzle)
            print()
            print_puzzle(solve)
        else:
            if additional_params.generate:
                print_puzzle(puzzle)
                print()

            try:
                solutions = SudokuSolver.solve(puzzle, additional_params,
                                               list_of_first_rule_point)
            except IncorrectSudokuError as error:
                print_error(error)

            if additional_params.gui_off:
                try:
                    check_empty = peek(solutions)
                    if check_empty is None:
                        print('Решений нет.')
                    else:
                        solutions = check_empty[1]
                        for solution in solutions:
                            print_puzzle(solution)
                            print()
                except IncorrectSudokuError as error:
                    print_error(error)
            else:
                try:
                    gui_create(solutions)
                except IncorrectSudokuError as error:
                    print_error(error)
Esempio n. 8
0
 def test_transformation_incorrect_input(self):
     list_of_lines = ['[1, 2, 3, 4]', '[5 6 7 8]', '[9,10,11,12]']
     quick_flag = False
     with self.assertRaises(IncorrectSudokuSizeError):
         ExtractInputData.transformation(list_of_lines, quick_flag)
Esempio n. 9
0
 def test_check_square(self):
     square_list = [i**2 for i in range(100)]
     for i in square_list:
         self.assertTrue(ExtractInputData.is_square(i))
     self.assertFalse(ExtractInputData.is_square(-100))