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


Python Sudoku.toString方法代码示例

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


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

示例1: main

# 需要导入模块: from sudoku import Sudoku [as 别名]
# 或者: from sudoku.Sudoku import toString [as 别名]

#.........这里部分代码省略.........
    #-----------------------------------------------------------------------------------------
    if debug: print 'test countMissing'
    try: 
        assert(0 == sudoku.countMissing())
    except: 
        if debug: print 'ERROR----->m:', 0, '\tmethod:', sudoku.countMissing(); exit()

    try: 
        assert(9 == unsolvedSudoku.countMissing())
    except: 
        if debug: print 'ERROR----->m:', 9, '\tmethod:', unsolvedSudoku.countMissing(); exit()
    if debug: print 'passed countMissing\n'

    #-----------------------------------------------------------------------------------------

    if debug: print 'test countMissing row'
    try: 
        assert(0 == sudoku.countMissing(row = 0))
    except: 
        if debug: print 'ERROR----->m:', 0, '\tmethod:', sudoku.countMissing(row = 0); exit()

    try: 
        assert(9 == unsolvedSudoku.countMissing(row = 0))
    except: 
        if debug: print 'ERROR----->m:', 9, '\tmethod:', unsolvedSudoku.countMissing(row = 0); exit()
    if debug: print 'passed countMissing row\n'

    #-----------------------------------------------------------------------------------------

    if debug: print 'test countMissing column'
    try: 
        assert(0 == sudoku.countMissing(column = 0))
    except: 
        if debug: print 'ERROR----->m:', 0, '\tmethod:', sudoku.countMissing(column = 0); exit()

    try: 
        assert(1 == unsolvedSudoku.countMissing(column = 0))
    except: 
        if debug: print 'ERROR----->m:', 1, '\tmethod:', unsolvedSudoku.countMissing(column = 0); exit()
    if debug: print 'passed countMissing column\n'

    #-----------------------------------------------------------------------------------------

    if debug: print 'test willConflict'
    for row in range(9):
        for column in range(9):
            try: 
                assert(True == sudoku.willConflict(solved[row][column], row, column))
            except: 
                if debug: print 'ERROR----->C:', True, '\tmethod:', sudoku.willConflict(solved[row][column], (row, column)); exit()
    if debug: print 'passed willConflict\n'

    if debug: print sudoku.toString(), '\n'
    if debug: print unsolvedSudoku.toString()

    #test each square
    if debug: print 'test getSquare'
    assert([2,4,8,5,7,1,9,3,6] == sudoku.getSquare(1,0))
    assert([3,9,5,6,2,8,7,4,1] == sudoku.getSquare(1,4))
    assert([7,1,6,3,4,9,5,8,2] == sudoku.getSquare(1,8))
    assert([6,8,2,3,5,9,7,1,4] == sudoku.getSquare(5,0))
    assert([5,3,9,1,7,4,8,6,2] == sudoku.getSquare(5,4))
    assert([1,7,4,6,2,8,9,5,3] == sudoku.getSquare(5,8))
    assert([8,6,3,1,9,5,4,2,7] == sudoku.getSquare(7,0))
    assert([4,1,7,2,8,6,9,5,3] == sudoku.getSquare(7,4))
    assert([9,2,5,4,3,7,8,6,1] == sudoku.getSquare(7,8))
    if debug: print 'passed getSquare\n'
    
    #-----------------------------------------------------------------------------------------
    
    if debug: print 'test resolveAllPossibilities'
    
    #check to make sure all possibilities are default value
    for row in range(9):
        for column in range(9):
            assert(sudoku.matrix[row][column].possibleNumbers == [1,2,3,4,5,6,7,8,9])
            
    if debug: print '\tall possibleNumbers initialized correctly'
    
    #resolve solved board
    sudoku.resolveAllPossibilities()
    for row in range(9):
        for column in range(9):
            assert(sudoku.matrix[row][column].possibleNumbers == [])
            
    if debug: print '\tall possible numbers resolved correctly in solved sudoku'
            
    #resolve unsolved board
    unsolvedSudoku.resolveAllPossibilities()
    for column in range(9):
        #first row is emptyCharacters
        assert(unsolvedSudoku.matrix[0][column].possibleNumbers == [9])
    for row in range(1,9):
        for column in range(9):
            #all other slots have a value, so no possible numbers
            assert(unsolvedSudoku.matrix[row][column].possibleNumbers == [])
    
    if debug: print '\tall possible numbers resolved correctly in unsolved sudoku'
    
    if debug: print 'passed resolveAllPossibilities\n'
开发者ID:andy-shaw,项目名称:sudoku_solver,代码行数:104,代码来源:_sudokuTest.py


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