def __init__(self, base_ofs): FrameManager.__init__(self) self.base_ofs = base_ofs
def test_linkedlist(self): class Loc(object): def __init__(self, pos, size, tp): self.pos = pos self.size = size self.tp = tp class FrameManager(object): @staticmethod def get_loc_index(item): return item.pos @staticmethod def frame_pos(pos, tp): if tp == 13: size = 2 else: size = 1 return Loc(pos, size, tp) fm = FrameManager() l = LinkedList(fm) l.append(1, Loc(1, 1, 0)) l.append(1, Loc(4, 1, 0)) l.append(1, Loc(2, 1, 0)) l.append(1, Loc(0, 1, 0)) assert l.master_node.val == 0 assert l.master_node.next.val == 1 assert l.master_node.next.next.val == 2 assert l.master_node.next.next.next.val == 4 assert l.master_node.next.next.next.next is None item = l.pop(1, 0) assert item.pos == 0 item = l.pop(1, 0) assert item.pos == 1 item = l.pop(1, 0) assert item.pos == 2 item = l.pop(1, 0) assert item.pos == 4 assert l.pop(1, 0) is None l.append(1, Loc(1, 1, 0)) l.append(1, Loc(5, 1, 0)) l.append(1, Loc(2, 1, 0)) l.append(1, Loc(0, 1, 0)) item = l.pop(2, 13) assert item.tp == 13 assert item.pos == 0 assert item.size == 2 assert l.pop(2, 0) is None # 2 and 4 l.append(1, Loc(4, 1, 0)) item = l.pop(2, 13) assert item.pos == 4 assert item.size == 2 assert l.pop(1, 0).pos == 2 assert l.pop(1, 0) is None l.append(2, Loc(1, 2, 0)) # this will not work because the result will be odd assert l.pop(2, 13) is None l.append(1, Loc(3, 1, 0)) item = l.pop(2, 13) assert item.pos == 2 assert item.tp == 13 assert item.size == 2