示例#1
0
 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)
示例#2
0
 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)
示例#3
0
 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})
示例#4
0
 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',))
         ])
示例#5
0
 def test_top(self):
     dl = DepList()
     dl.stack = [1, 2, 3]
     self.assertEqual(dl.top(), dl.stack[-1])
示例#6
0
 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)})