testcomparisonops.py

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

PY
49
字号
import BitVectorimport unittestimport StringIObv1 = BitVector.BitVector( bitstring = '00110011' )bv2 = BitVector.BitVector( bitlist = [0,0,1,1,0,0,1,1] )bv3 = BitVector.BitVector( intVal = 5678 )comparisonTests = [    ((bv1,bv2, '=='), True),    ((bv1,bv2, '!='), False),    ((bv1,bv2, '<'), False),    ((bv1,bv2, '<='), True),    ((bv1,bv3, '=='), False),    ((bv3,bv1, '>'), True),    ((bv3,bv1, '>='), True),    ]class ComparisonTestCases(unittest.TestCase):    def checkComparisons(self):        print "\nTesting comparison operators"        for args, expected in comparisonTests:            try:                op = args[2]                if (op == '=='):                    actual = args[0] == args[1]                elif (op == '!='):                    actual = args[0] != args[1]                elif (op == '<'):                    actual = args[0] < args[1]                elif (op == '<='):                    actual = args[0] <= args[1]                elif (op == '=='):                    actual = args[0] == args[1]                elif (op == '>'):                    actual = args[0] > args[1]                elif (op == '>='):                    actual = args[0] >= args[1]                assert expected == actual            except Exception, e:                print e                print "        COMPARISON TEST FAILED"def getTestSuites(type):    return unittest.TestSuite([            unittest.makeSuite(ComparisonTestCases, type)                             ])                    

⌨️ 快捷键说明

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