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


Python Position.reset方法代码示例

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


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

示例1: UnitTestBacktrak

# 需要导入模块: from position import Position [as 别名]
# 或者: from position.Position import reset [as 别名]
class UnitTestBacktrak(unittest.TestCase):
    
    def setUp(self):
        self.max_col = 9
        self.max_row = 9
        self.col = 0
        self.row = 0
        self.new_position = Position(self.max_row,self.max_col)
        
        self.sudoku_str = "273481960000075030048090100059300000367510809124968700001829576685734000092156384"
        self.sudoku_resolved_to_compare = "273481965916275438548693127859347612367512849124968753431829576685734291792156384"
        list_for_matrix = [0] * self.max_col
        self.zero_matrix = [list_for_matrix] * self.max_row
        self.sudoku_matrix = [[2, 7, 3, 4, 8, 1, 9, 6, 0], [0, 0, 0, 0, 7, 5, 0, 3, 0], [0, 4, 8, 0, 9, 0, 1, 0, 0], 
                              [0, 5, 9, 3, 0, 0, 0, 0, 0], [3, 6, 7, 5, 1, 0, 8, 0, 9], [1, 2, 4, 9, 6, 8, 7, 0, 0], 
                              [0, 0, 1, 8, 2, 9, 5, 7, 6], [6, 8, 5, 7, 3, 4, 0, 0, 0], [0, 9, 2, 1, 5, 6, 3, 8, 4]]
        self.new_resolve = Resolve(self.sudoku_str)
    
    def test_verify_it_can_set_row(self):
        self.new_position.set_row(4)
        self.assertEqual(4,self.new_position.get_row())
        
    
    def test_verify_it_can_set_row_equal_to_0_if_it_is_minor_to_0(self):
        self.new_position.set_row(-1)
        self.assertEqual(0,self.new_position.get_row())
    
    def test_verify_it_cat_set_row_equal_to_minus_1_if_it_is_mayor_to_max_row(self):
        self.new_position.set_row(11)
        self.assertEqual(-1,self.new_position.get_row())
    
    def test_verify_it_can_set_col(self):
        self.new_position.set_col(5)
        self.assertEqual(5,self.new_position.get_col())
    
    def test_verify_it_can_set_col_equal_to_0_if_it_is_minor_to_0(self):
        self.new_position.set_col(-2)
        self.assertEqual(0,self.new_position.get_col())
    
    def test_verify_it_cat_set_col_equal_to_minus_1_if_it_is_mayor_to_max_col(self):
        self.new_position.set_col(20)
        self.assertEqual(-1,self.new_position.get_col())
    
    def test_verify_it_can_get_row(self):
        self.new_position.set_row(8)
        self.assertEqual(8,self.new_position.get_row())
    
    def test_verify_it_can_get_col(self):
        self.new_position.set_col(4)
        self.assertEqual(4,self.new_position.get_col())
    
    def test_verify_it_is_end_of_the_matrix_it_should_return_minus_1(self):
        self.new_position.set_row(self.max_col)
        self.new_position.set_col(self.max_row)
        self.assertTrue(self.new_position.end_matrix())
    
    def test_verify_it_can_reset_to_zero_the_row_and_col(self):
        self.new_position.reset()
        self.assertEqual(0,self.new_position.get_col())
        self.assertEqual(0,self.new_position.get_row())
    
    def test_verify_it_can_move_to_next_vale_of_a_matrix(self):
        """
        if initial position is row = 0, col = 1
        the next position should be row = 0, col = 2
        """
        self.new_position.set_row(0)
        self.new_position.set_col(1)
        self.new_position.next_position()
        self.assertEqual(0,self.new_position.get_row())
        self.assertEqual(2,self.new_position.get_col())
    
    def test_verify_it_can_not_move__next_row_if_it_is_mayor_to_max_row(self):
        self.new_position.set_row(self.max_row + 1)
        self.new_position.next_position()
        self.assertEqual(-1,self.new_position.get_row())
        
    def test_verify_it_can_move_to_next_col_if_it_is_mayor_to_max_col(self):
        self.new_position.set_col(self.max_col + 1)
        self.new_position.next_position()
        self.assertEqual(0,self.new_position.get_col())
    
    def test_verify_it_can_not_move_to_next_value_if_it_is_end_of_the_matrix(self):
        self.new_position.set_row(self.max_row)
        self.new_position.set_col(self.max_col)
        self.new_position.next_position()
        self.assertTrue(self.new_position.end_matrix())
    
    def test_verify_it_can_get_a_position_of_a_matrix(self):
        self.new_position.set_row(3)
        self.new_position.set_col(3)
        self.assertEqual([3,3],self.new_position.get_position())
    
    def test_verify_it_could_resolve_a_sudoku(self):
        self.new_resolve.resolve(self.sudoku_matrix)
        self.assertEqual(self.sudoku_resolved_to_compare,self.new_resolve.get_solve_game())
    
    def test_verify_it_could_generate_a_zero_matrix(self):
        self.assertEqual(self.zero_matrix, self.new_resolve.generate_matrix(self.max_row, self.max_col))
        
#.........这里部分代码省略.........
开发者ID:RafaelAlfaro,项目名称:sudokuC,代码行数:103,代码来源:test_backtraking.py


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