Пример #1
0
def test(base, exp):
	size =  base ** exp
	## print out header
	s = [
		"Size / Divisor",
		"Number Bits Set",
		"Count Result",
		"Percent Bits Set"
	]
	print "".join(map(lambda x: x.rjust(25), s))
	print "="*100

	for i in range(exp):
		v = BitVector()
		divisor = base ** (exp-i)
		set = size/divisor
		for i in range(set):
			v[i*divisor] = 1
		count = v.count()
		pct = (100 * float(set) / size)

		### print out status...
		s = [
			"%d / %d" % (size, divisor),
			"%d" % (set,),
			"%d" % (count,),
			"%.08f" % (pct,)
		]
		print "".join(map(lambda x: x.rjust(25), s))
		assert count == set
Пример #2
0
	def test_size(self):
		v = BitVector()
		v.resize(10)
		for i in range(5):
			v[i*2] = True
		assert len(v) == 10
		assert v.count() == 5
Пример #3
0
	def test_setclear(self):
		v = BitVector()
		v.resize(100)

		assert v.any() == False
		assert v.none() == True

		v.set()

		assert v.any() == True
		assert v.none() == False
		assert v.count() == len(v)

		v.clear()

		assert v.any() == False
		assert v.none() == True
		assert v.count() == 0
Пример #4
0
	def test_count(self):
		base = 2
		exp = 18
		size = base ** exp

		for e in range(exp+1):
			v = BitVector()
			div = base ** (exp-e)
			nbits = size / div

			stdout.write("%d/%d... " % (nbits, size))
			stdout.flush()

			for i in range(nbits):
				v[i*div] = True

			assert v.count() == nbits