Beispiel #1
0
 def test_iter(self):
     dll = dllist()
     for i in range(10):
         dll.insert(Node(10+i))
         check_dllist(dll)
     value = 10
     for node in dll:
         self.assertIsInstance(node, Node)
         self.assertEqual(node.callback, value)
         value += 1
     check_dllist(dll)
Beispiel #2
0
 def test_iter(self):
     dll = dllist()
     for i in range(10):
         dll.insert(Node(10 + i))
         check_dllist(dll)
     value = 10
     for node in dll:
         self.assertIsInstance(node, Node)
         self.assertEqual(node.callback, value)
         value += 1
     check_dllist(dll)
Beispiel #3
0
 def test_many_nodes(self):
     nodes = []
     dll = dllist()
     count = 10000
     for i in range(count):
         before = random.choice(nodes) if nodes else None
         node = Node(i)
         dll.insert(node, before)
         nodes.append(node)
         self.assertEqual(len(dll), i+1)
         if i % 100 == 0:
             check_dllist(dll)
     check_dllist(dll)
     for i in range(count):
         r = random.randint(0, len(nodes)-1)
         node = nodes[r]; del nodes[r]
         dll.remove(node)
         self.assertEqual(len(dll), count-i-1)
         if i % 100 == 0:
             check_dllist(dll)
     check_dllist(dll)
Beispiel #4
0
 def test_many_nodes(self):
     nodes = []
     dll = dllist()
     count = 10000
     for i in range(count):
         before = random.choice(nodes) if nodes else None
         node = Node(i)
         dll.insert(node, before)
         nodes.append(node)
         self.assertEqual(len(dll), i + 1)
         if i % 100 == 0:
             check_dllist(dll)
     check_dllist(dll)
     for i in range(count):
         r = random.randint(0, len(nodes) - 1)
         node = nodes[r]
         del nodes[r]
         dll.remove(node)
         self.assertEqual(len(dll), count - i - 1)
         if i % 100 == 0:
             check_dllist(dll)
     check_dllist(dll)
Beispiel #5
0
 def test_basic(self):
     dll = dllist()
     check_dllist(dll)
     self.assertIsNone(dll.first)
     self.assertIsNone(dll.last)
     self.assertEqual(len(dll), 0)
     # insert first element
     n1 = Node('foo')
     dll.insert(n1)
     self.assertIs(dll.first, n1)
     self.assertIs(dll.last, n1)
     self.assertEqual(len(dll), 1)
     check_dllist(dll)
     # insert second at end
     n2 = Node('bar')
     dll.insert(n2)
     self.assertIs(dll.first, n1)
     self.assertIs(dll.last, n2)
     self.assertEqual(len(dll), 2)
     check_dllist(dll)
     # insert in middle
     n3 = Node('baz')
     dll.insert(n3, before=n2)
     self.assertIs(dll.first, n1)
     self.assertIs(dll.last, n2)
     self.assertEqual(len(dll), 3)
     check_dllist(dll)
     # remove middle
     dll.remove(n3)
     self.assertIs(dll.first, n1)
     self.assertIs(dll.last, n2)
     self.assertEqual(len(dll), 2)
     check_dllist(dll)
     # remove first
     dll.remove(n1)
     self.assertIs(dll.first, n2)
     self.assertIs(dll.last, n2)
     self.assertEqual(len(dll), 1)
     check_dllist(dll)
     # remove remaining element
     dll.remove(n2)
     self.assertIsNone(dll.first)
     self.assertIsNone(dll.last)
     self.assertEqual(len(dll), 0)
     check_dllist(dll)
Beispiel #6
0
 def test_basic(self):
     dll = dllist()
     check_dllist(dll)
     self.assertIsNone(dll.first)
     self.assertIsNone(dll.last)
     self.assertEqual(len(dll), 0)
     # insert first element
     n1 = Node('foo')
     dll.insert(n1)
     self.assertIs(dll.first, n1)
     self.assertIs(dll.last, n1)
     self.assertEqual(len(dll), 1)
     check_dllist(dll)
     # insert second at end
     n2 = Node('bar')
     dll.insert(n2)
     self.assertIs(dll.first, n1)
     self.assertIs(dll.last, n2)
     self.assertEqual(len(dll), 2)
     check_dllist(dll)
     # insert in middle
     n3 = Node('baz')
     dll.insert(n3, before=n2)
     self.assertIs(dll.first, n1)
     self.assertIs(dll.last, n2)
     self.assertEqual(len(dll), 3)
     check_dllist(dll)
     # remove middle
     dll.remove(n3)
     self.assertIs(dll.first, n1)
     self.assertIs(dll.last, n2)
     self.assertEqual(len(dll), 2)
     check_dllist(dll)
     # remove first
     dll.remove(n1)
     self.assertIs(dll.first, n2)
     self.assertIs(dll.last, n2)
     self.assertEqual(len(dll), 1)
     check_dllist(dll)
     # remove remaining element
     dll.remove(n2)
     self.assertIsNone(dll.first)
     self.assertIsNone(dll.last)
     self.assertEqual(len(dll), 0)
     check_dllist(dll)