Esempio n. 1
0
 def test_guards_after_insert(self):
     ll = sllist()
     node1 = ll.insert(sllistnode(1))
     self.assertIs(ll.first, node1)
     self.assertIs(ll.last, node1)
     node2 = ll.insert(sllistnode(2))
     self.assertIs(ll.first, node1)
     self.assertIs(ll.last, node2)
Esempio n. 2
0
 def test_appendleft(self):
     ll = sllist(xrange(4))
     ref = sllist([10, 0, 1, 2, 3])
     next = ll.nodeat(0)
     arg_node = sllistnode(10)
     new_node = ll.appendleft(arg_node)
     self.assertNotEqual(new_node, arg_node)
     self.assertEqual(new_node.value, 10)
     self.assertEqual(new_node.next, next)
     self.assertEqual(ll.first, new_node)
     self.assertEqual(ll, ref)
Esempio n. 3
0
 def test_insert_value_before_first(self):
     ll = sllist(xrange(4))
     ref = sllist([10, 0, 1, 2, 3])
     next = ll.nodeat(0)
     arg_node = sllistnode(10)
     new_node = ll.insert(arg_node, ll.nodeat(0))
     self.assertNotEqual(new_node, arg_node)
     self.assertEqual(new_node.value, 10)
     self.assertEqual(new_node.next, next)
     self.assertEqual(new_node, ll.first)
     self.assertEqual(ll, ref)
Esempio n. 4
0
 def test_append(self):
     ll = sllist(xrange(4))
     ref = sllist([0, 1, 2, 3, 10])
     prev = ll.nodeat(-1)
     arg_node = sllistnode(10)
     new_node = ll.append(arg_node)
     self.assertNotEqual(new_node, arg_node)
     self.assertEqual(new_node.value, 10)
     self.assertEqual(new_node.next, None)
     self.assertEqual(prev.next, new_node)
     self.assertEqual(ll.last, new_node)
     self.assertEqual(ll, ref)
Esempio n. 5
0
 def test_insert_value_before(self):
     ll = sllist(xrange(4))
     ref = sllist([0, 1, 10, 2, 3])
     prev = ll.nodeat(1)
     next = ll.nodeat(2)
     arg_node = sllistnode(10)
     new_node = ll.insert(arg_node, ll.nodeat(2))
     self.assertNotEqual(new_node, arg_node)
     self.assertEqual(new_node.value, 10)
     self.assertEqual(new_node.next, next)
     self.assertEqual(prev.next, new_node)
     self.assertEqual(ll, ref)
Esempio n. 6
0
 def test_guards_after_insertbefore(self):
     ll = sllist([1])
     orig_last = ll.last
     node = ll.insertbefore(ll.first, sllistnode(2))
     self.assertIs(ll.first, node)
     self.assertIs(ll.last, orig_last)
Esempio n. 7
0
 def test_insert_invalid_ref(self):
     ll = sllist()
     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, sllistnode())
Esempio n. 8
0
 def test_node_readonly_attributes(self):
     ll = sllistnode()
     self.assertRaises(AttributeError, setattr, ll, 'next', None)
Esempio n. 9
0
 def test_remove_invalid_node(self):
     ll = sllist([1, 2, 3, 4])
     self.assertRaises(ValueError, ll.remove, sllistnode())
     self.assertEqual(len(ll), 4)
Esempio n. 10
0
 def test_remove_from_empty_list(self):
     ll = sllist()
     self.assertRaises(ValueError, ll.remove, sllistnode())