Example #1
0
 def test5(self):
     for numbits in xrange(1,256):
         bv = BitVector(256, 1<<(numbits-1) )
         other = BitVector(numbits, 1<<(numbits-1))
         self.assert_( bv.is_same_when_extended( other ))
         other = BitVector(numbits, 1<<(numbits))
         self.assert_( bv.is_same_when_extended( other ) == False )
         other = BitVector(1, 1)
         self.assert_(bv.is_same_when_extended( other, self_max = numbits-1, self_min = numbits-1 ))
         if numbits > 1: self.assert_( bv.is_same_when_extended( other, self_max = numbits-1, self_min = 0 ) == False)
Example #2
0
    def test6(self):
        bv = BitVector(256, val_int=0)
        for numbits in xrange(256,0,-1):
            other = BitVector(numbits, 1<<(numbits-1))
            bv.update_from(other)
            self.assert_( bv.is_same_when_extended( other ))

        other1 = BitVector(8,val_int=0xff)
        for start in xrange(0,256-8):
            bv = BitVector( 256, val_int=0 )
            bv.update_from(other1, self_max = start+7, self_min = start)
            expd = 0xff << start
            bvd = bv.get_bin_data()
            self.assert_(bvd == expd, "\nexpd=0x%x\nbv  =0x%x" % (expd, bvd))

            
        c = 0x12345678abcd112212345678abcd1122
        c2 = 0x556611ff
        other2 = BitVector(32,c2)
        for start in xrange(0,256-32):
            bv = BitVector( 256, c )
            bv.update_from(other2, self_max = start+31, self_min = start)
            expd = c & ~(0xffffffff << start) | ( c2 << start)
            bvd = bv.get_bin_data()
            self.assert_(bvd == expd, "\nstart=%d\nexpd=0x%x\nbv  =0x%x" % (start, expd, bvd))