本文整理汇总了Python中sudoku.Sudoku.has_zero方法的典型用法代码示例。如果您正苦于以下问题:Python Sudoku.has_zero方法的具体用法?Python Sudoku.has_zero怎么用?Python Sudoku.has_zero使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sudoku.Sudoku
的用法示例。
在下文中一共展示了Sudoku.has_zero方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_solved_puzzle_is_solved
# 需要导入模块: from sudoku import Sudoku [as 别名]
# 或者: from sudoku.Sudoku import has_zero [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())
示例2: SudokuTest
# 需要导入模块: from sudoku import Sudoku [as 别名]
# 或者: from sudoku.Sudoku import has_zero [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)