def testAll(): b = Bag() assert (b.size() == 0) assert (b.isEmpty()) b.add(4) b.add(11) b.add(4) b.add(77) b.add(8) assert (b.size() == 5) assert (b.isEmpty() == False) assert (b.remove(44) == False) assert (b.remove(11)) assert (b.size() == 4) assert (b.nrOccurrences(4) == 2) assert (b.search(77)) assert (b.search(13) == False) itb = b.iterator() assert (itb.valid()) cont = 0 while (itb.valid()): cont += 1 e = itb.getCurrent() itb.next() assert (b.search(e)) assert (cont == b.size()) itb.first() assert (itb.valid())
def testAdd(): b = Bag() for i in range(10): b.add(i) assert(b.isEmpty() == False) assert(b.size() == 10) for i in range(-10, 20): b.add(i) assert(b.isEmpty() == False) assert(b.size() == 40) for i in range(-100, 100): b.add(i) assert(b.isEmpty() == False) assert(b.size() == 240) for i in range(-200,200): count = b.nrOccurrences(i) if i < -100: assert(count == 0) assert(b.search(i) == False) elif i < -10: assert(count == 1) assert(b.search(i) == True) elif i < 0: assert(count == 2) assert(b.search(i) == True) elif i < 10: assert(count == 3) assert(b.search(i) == True) elif i < 20: assert(count == 2) assert(b.search(i) == True) elif i < 100: assert(count == 1) assert(b.search(i) == True) else: assert(count == 0) assert(b.search(i) == False) for i in range(10000, -10000, -1): b.add(i) assert(b.size() == 20240)
def testCreate(): b = Bag() assert(b.size() == 0) assert(b.isEmpty() == True) for i in range(-5,5): assert(b.search(i) == False) for i in range(-10,10): assert(b.remove(i) == False) for i in range(-10,10): assert(b.nrOccurrences(i) == 0) it = b.iterator() assert(it.valid() == False)