testpermutations.py

来自「java bitvector implementation.」· Python 代码 · 共 32 行

PY
32
字号
import BitVectorimport unittestbv1 = BitVector.BitVector( bitlist = [1,0,0,1,1,0,1] )bv2 = BitVector.BitVector( bitlist = [1,0,1,0,0,1,1] )permutationTests = [    ((bv1, 'permute', '6201543'), '1010011'),    ((bv2, 'unpermute', '6201543'), '1001101'),    ]class PermutationTestCase(unittest.TestCase):    def checkPermutations(self):        print "\nTesting permutations"         for args, expected in permutationTests:            try:                if (args[1] == 'permute'):                    actual = args[0].permute( map( lambda x: int(x),                                                   list( args[2] ) ) )                elif (args[1] == 'unpermute'):                    actual = args[0].unpermute( map( lambda x: int(x),                                                     list( args[2] ) ) )                assert actual == BitVector.BitVector( bitstring = expected )            except Exception, e:                print e                print "Permutation test failed"def getTestSuites(type):    return unittest.TestSuite([            unittest.makeSuite(PermutationTestCase, type)                ])                    

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?