def test_init(self): dl = DepList() self.assertEqual(dl.unsorted, []) self.assertEqual(dl.index, {}) self.assertEqual(dl.stack, []) self.assertEqual(dl.pushed, set()) self.assertEqual(dl.sorted, None)
def test_pop(self): item = ('a', ('b',)) dl = DepList() dl.push(item) # has popped = dl.pop() self.assertEqual(popped, item) # empty popped = dl.pop() self.assertEqual(popped, None)
def test_push(self): item = ('a', ('b',)) dl = DepList() dl.push(item) self.assertEqual(len(dl.stack), 1) self.assertEqual(dl.pushed, {item}) # 2nd push skipped dl.push(item) self.assertEqual(len(dl.stack), 1) self.assertEqual(dl.pushed, {item})
def test_sort(self): a = ('a', ('x',)) b = ('b', ('a',)) c = ('c', ('a', 'b')) d = ('d', ('c',)) e = ('e', ('d', 'a')) f = ('f', ('e', 'c', 'd', 'a')) x = ('x', ()) g = ('g', ('G',)) dl = DepList() dl.add(c, e, d, b, f, a, x, g) self.assertEqual( dl.sort(), [ ('x', ()), ('a', ('x',)), ('b', ('a',)), ('c', ('a', 'b')), ('d', ('c',)), ('e', ('d', 'a')), ('f', ('e', 'c', 'd', 'a')), ('g', ('G',)) ])
def test_top(self): dl = DepList() dl.stack = [1, 2, 3] self.assertEqual(dl.top(), dl.stack[-1])
def test_add(self): items = [(1, 2), (3, 4)] dl = DepList() dl.add(*items) self.assertEqual(dl.unsorted, items) self.assertEqual(dl.index, {1: (1, 2), 3: (3, 4)})