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


Python Sudoku.solved方法代码示例

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


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

示例1: test_solved_puzzle_is_solved

# 需要导入模块: from sudoku import Sudoku [as 别名]
# 或者: from sudoku.Sudoku import solved [as 别名]
 def test_solved_puzzle_is_solved(self):
     """example taken from http://www.sudokugame.com/rules.php"""
     tmp = Sudoku()
     tmp[0] = [2,4,8,3,9,5,7,1,6]
     tmp[1] = [5,7,1,6,2,8,3,4,9]
     tmp[2] = [9,3,6,7,4,1,5,8,2]
     tmp[3] = [6,8,2,5,3,9,1,7,4]
     tmp[4] = [3,5,9,1,7,4,6,2,8]
     tmp[5] = [7,1,4,8,6,2,9,5,3]
     tmp[6] = [8,6,3,4,1,7,2,9,5]
     tmp[7] = [1,9,5,2,8,6,4,3,7]
     tmp[8] = [4,2,7,9,5,3,8,6,1]
     self.assertTrue(tmp.solved())
     self.assertFalse(tmp.has_zero())
     self.assertTrue(tmp.consistent())
开发者ID:djuber,项目名称:sudoku,代码行数:17,代码来源:sudoku_tests.py

示例2: SudokuTest

# 需要导入模块: from sudoku import Sudoku [as 别名]
# 或者: from sudoku.Sudoku import solved [as 别名]
class SudokuTest(unittest.TestCase):
    def setUp(self):
        self.puzzle = Sudoku()
        self.empty = Sudoku()
        for row in range(9):
            for col in range(9):
                self.puzzle[row][col] = 1 + (row + col) % 9
    def test_puzzle_initialized(self):
        self.assertEqual([1,2,3,4,5,6,7,8,9], self.puzzle[0])
        self.assertEqual([1,2,3,4,5,6,7,8,9], self.puzzle.col(0))
    def test_empty_initialized(self):
        self.assertEqual([0,0,0,0,0,0,0,0,0], self.empty[0])
        self.assertEqual([0,0,0,0,0,0,0,0,0], self.empty.col(0))
    def test_puzzle_rows_are_consistent(self):
        for row in range(9):
            self.assertTrue(self.puzzle.row_consistent(row))
    def test_puzzle_cols_are_consisten(self):
        for col in range(9):
            self.assertTrue(self.puzzle.col_consistent(col))
    def test_consistent_ignores_zero_entries(self):
        for index in range(9):
            self.assertTrue(self.empty.row_consistent(index))
            self.assertTrue(self.empty.col_consistent(index))
    def test_consistent_returns_false(self):
        self.puzzle[0][0] = 8
        self.assertFalse(self.puzzle.row_consistent(0))
        self.assertFalse(self.puzzle.col_consistent(0))
        self.puzzle[0][0] = 1
    def test_consistent_plays_nice_with_index(self):
        "this test doesn't check what it needs to"
        tmp = self.puzzle[8][8]
        self.puzzle[8][8] = 1
        self.assertFalse(self.puzzle.row_consistent(8))
        self.assertFalse(self.puzzle.col_consistent(8))
        self.puzzle[8][8] = tmp
    def test_squares_are_all_inconsistent(self):
        for i in range(9):
            self.assertFalse(self.puzzle.square_consistent(i))
    def test_squares_of_empty_are_consistent(self):
        for i in range(9):
            self.assertTrue(self.empty.square_consistent(i))
    def test_square_can_be_consistent(self):
        tmp = Sudoku()
        self.assertTrue(tmp.square_consistent(0))
        tmp[0][0] = 1
        tmp[0][1] = 2
        tmp[0][2] = 3
        self.assertTrue(tmp.square_consistent(0))
        tmp[1][0] = 4
        tmp[1][1] = 5
        tmp[1][2] = 3
        self.assertFalse(tmp.square_consistent(0))
        tmp[1][2] = 6
        self.assertTrue(tmp.square_consistent(0))
        tmp[2][0] = 7
        tmp[2][0] = 8
        self.assertTrue(tmp.square_consistent(0))
        tmp[2][2] = 5
        self.assertFalse(tmp.square_consistent(0))
    def test_puzzle_inconsistent(self):
        self.assertFalse(self.puzzle.consistent())
    def test_empty_consistent(self):
        self.assertTrue(self.empty.consistent())
    def test_puzzle_has_no_zero(self):
        self.assertFalse(self.puzzle.has_zero())
    def test_empty_has_zero(self):
        self.assertTrue(self.empty.has_zero())
    def test_puzzle_not_solved(self):
        self.assertFalse(self.puzzle.solved())
    def test_empty_not_solved(self):
        self.assertFalse(self.empty.solved())
    def test_solved_puzzle_is_solved(self):
        """example taken from http://www.sudokugame.com/rules.php"""
        tmp = Sudoku()
        tmp[0] = [2,4,8,3,9,5,7,1,6]
        tmp[1] = [5,7,1,6,2,8,3,4,9]
        tmp[2] = [9,3,6,7,4,1,5,8,2]
        tmp[3] = [6,8,2,5,3,9,1,7,4]
        tmp[4] = [3,5,9,1,7,4,6,2,8]
        tmp[5] = [7,1,4,8,6,2,9,5,3]
        tmp[6] = [8,6,3,4,1,7,2,9,5]
        tmp[7] = [1,9,5,2,8,6,4,3,7]
        tmp[8] = [4,2,7,9,5,3,8,6,1]
        self.assertTrue(tmp.solved())
        self.assertFalse(tmp.has_zero())
        self.assertTrue(tmp.consistent())
    def test_zeros(self):
        self.assertEqual(len(self.empty.zeros()), 81)
    def test_print(self):
        self.assertTrue(len(str(self.empty)) > 50)
开发者ID:djuber,项目名称:sudoku,代码行数:92,代码来源:sudoku_tests.py


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