def test_works_well(self): ''' Make sure the index scheduler works well ''' bitfield = make_bitfield(4096) peer_bitfield = make_bitfield(4096) # Find each free slot and consider each bit inside it expect = [] for index in range(len(bitfield.bits)): if not bitfield.bits[index] and peer_bitfield.bits[index]: for shift in range(8): expect.append(index * 8 + shift) # The real code should behave in the same way, but randomly seen = [] for index in sched_idx(bitfield, peer_bitfield): seen.append(index) seen = sorted(seen) # Let's see self.assertEqual(expect, seen)
def test_check_lengths(self): ''' Make sure the index scheduler checks lengths ''' bitfield = make_bitfield(17) peer_bitfield = make_bitfield(71) schedidx = sched_idx(bitfield, peer_bitfield) self.assertRaises(AssertionError, schedidx.next)