当前位置: 首页>>代码示例>>Python>>正文


Python Sudoku.find_unsolved_location方法代码示例

本文整理汇总了Python中sudoku.Sudoku.find_unsolved_location方法的典型用法代码示例。如果您正苦于以下问题:Python Sudoku.find_unsolved_location方法的具体用法?Python Sudoku.find_unsolved_location怎么用?Python Sudoku.find_unsolved_location使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sudoku.Sudoku的用法示例。


在下文中一共展示了Sudoku.find_unsolved_location方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: SudokuTest

# 需要导入模块: from sudoku import Sudoku [as 别名]
# 或者: from sudoku.Sudoku import find_unsolved_location [as 别名]
class SudokuTest(unittest.TestCase):

    def setUp(self):
        self.sudoku = Sudoku()
        self.sudoku_puzzle = self.sudoku.parse_csv("puzzle.csv")
        self.matrix = self.sudoku.group(self.sudoku_puzzle, 9)
        self.location = (0, 0)

    def test_puzzle_has_eighty_one_items(self):
        self.assertEquals(len(self.sudoku_puzzle), 81)

    def test_solve_puzzle(self):
        answer = self.sudoku.solve(self.matrix)
        self.sudoku.write_to_csv(answer)
        dir = os.curdir
        file_sys = os.listdir(dir)
        self.assertIn("solution.csv", file_sys)

    def test_solution_has_eighty_one_items(self):
        solution = self.sudoku.parse_csv("solution.csv")
        self.assertEquals(len(solution), 81)

    def test_solution_is_correct(self):
        solution = self.sudoku.parse_csv("solution.csv")
        matrix = self.sudoku.group(solution, 9)
        for line in matrix:
            self.assertEquals(sorted(line), range(1, 10))

    def test_solution_is_csv(self):
        puzzle_file = "solution.csv"
        self.assertTrue(puzzle_file.endswith("csv"))

    def test_puzzle_elements_at_a_position(self):
        col_elements = self.sudoku.get_col(self.matrix, self.location)
        row_elements = self.sudoku.get_row(self.matrix, self.location)
        block_elements = self.sudoku.get_block(self.matrix, self.location)

        self.assertEquals(len(col_elements), 9)
        self.assertEquals(len(row_elements), 9)
        self.assertEquals(len(block_elements), 9)

    def test_puzzle_elements_at_row_position_are_valid(self):
        row_elements = self.sudoku.get_row(self.matrix, self.location)
        self.assertEquals(row_elements, [0, 3, 5, 2, 9, 0, 8, 6, 4])

    def test_puzzle_elements_at_col_position_are_valid(self):
        col_elements = self.sudoku.get_col(self.matrix, self.location)
        self.assertEquals(col_elements, [0, 0, 7, 2, 0, 0, 4, 3, 8])

    def test_puzzle_elements_at_block_position_are_valid(self):
        block_elements = self.sudoku.get_block(self.matrix, self.location)
        self.assertEquals(block_elements, [0, 3, 5, 0, 8, 2, 7, 6, 4])

    def test_puzzle_file_is_not_already_solved(self):
        pos = self.sudoku.find_unsolved_location(self.matrix)
        self.assertIsInstance(pos, tuple)

    def test_unassinged_location(self):
        pos = self.sudoku.find_unsolved_location(self.matrix)
        self.assertEquals(pos, (0, 0))

    def test_possible_value_is_correct(self):
        value = list(
            self.sudoku.find_possible_values(self.matrix, self.location)
        )
        self.assertEquals(value[0], 1)

    def test_value_is_legal(self):
        self.assertTrue(self.sudoku.is_legal(1, self.matrix, self.location))
开发者ID:cyberomin,项目名称:InsightDataEngineering,代码行数:71,代码来源:sudoku_test.py


注:本文中的sudoku.Sudoku.find_unsolved_location方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。