Ejemplo n.º 1
0
 def test_guards_after_insert(self):
     ll = dllist()
     node1 = ll.insert(dllistnode(1))
     self.assertIs(ll.first, node1)
     self.assertIs(ll.last, node1)
     node2 = ll.insert(dllistnode(2))
     self.assertIs(ll.first, node1)
     self.assertIs(ll.last, node2)
Ejemplo n.º 2
0
 def test_appendright(self):
     ll = dllist(xrange(4))
     ref = dllist([0, 1, 2, 3, 10])
     prev = ll.nodeat(-1)
     arg_node = dllistnode(10)
     new_node = ll.appendright(arg_node)
     self.assertNotEqual(new_node, arg_node)
     self.assertEqual(new_node.value, 10)
     self.assertEqual(new_node.prev, prev)
     self.assertEqual(new_node.next, None)
     self.assertEqual(prev.next, new_node)
     self.assertEqual(ll.last, new_node)
     self.assertEqual(ll, ref)
Ejemplo n.º 3
0
 def test_appendleft(self):
     ll = dllist(xrange(4))
     ref = dllist([10, 0, 1, 2, 3])
     next = ll.nodeat(0)
     arg_node = dllistnode(10)
     new_node = ll.appendleft(arg_node)
     self.assertNotEqual(new_node, arg_node)
     self.assertEqual(new_node.value, 10)
     self.assertEqual(new_node.prev, None)
     self.assertEqual(new_node.next, next)
     self.assertEqual(next.prev, new_node)
     self.assertEqual(ll.first, new_node)
     self.assertEqual(ll, ref)
Ejemplo n.º 4
0
 def test_insert_value_after_last(self):
     ll = dllist(xrange(4))
     ref = dllist([0, 1, 2, 3, 10])
     prev = ll.nodeat(3)
     arg_node = dllistnode(10)
     new_node = ll.insert(arg_node, after=ll.last)
     self.assertNotEqual(new_node, arg_node)
     self.assertEqual(new_node.value, 10)
     self.assertEqual(new_node.prev, prev)
     self.assertEqual(new_node.next, None)
     self.assertEqual(prev.next, new_node)
     self.assertEqual(new_node, ll.last)
     self.assertEqual(ll, ref)
Ejemplo n.º 5
0
 def test_insert_value_after(self):
     ll = dllist(xrange(4))
     ref = dllist([0, 1, 10, 2, 3])
     prev = ll.nodeat(1)
     next = ll.nodeat(2)
     arg_node = dllistnode(10)
     new_node = ll.insert(arg_node, after=ll.nodeat(1))
     self.assertNotEqual(new_node, arg_node)
     self.assertEqual(new_node.value, 10)
     self.assertEqual(new_node.prev, prev)
     self.assertEqual(new_node.next, next)
     self.assertEqual(prev.next, new_node)
     self.assertEqual(next.prev, new_node)
     self.assertEqual(ll, ref)
Ejemplo n.º 6
0
 def test_node_readonly_attributes(self):
     ll = dllistnode()
     self.assertRaises(AttributeError, setattr, ll, 'prev', None)
     self.assertRaises(AttributeError, setattr, ll, 'next', None)
Ejemplo n.º 7
0
 def test_remove_invalid_node(self):
     ll = dllist([1, 2, 3, 4])
     self.assertRaises(ValueError, ll.remove, dllistnode())
     self.assertEqual(len(ll), 4)
Ejemplo n.º 8
0
 def test_remove_from_empty_list(self):
     ll = dllist()
     self.assertRaises(ValueError, ll.remove, dllistnode())
Ejemplo n.º 9
0
 def test_insert_invalid_ref(self):
     ll = dllist()
     self.assertRaises(TypeError, ll.insert, 10, 1)
     self.assertRaises(TypeError, ll.insert, 10, 'abc')
     self.assertRaises(TypeError, ll.insert, 10, [])
     self.assertRaises(ValueError, ll.insert, 10, dllistnode())