예제 #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)
예제 #2
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)
예제 #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)
예제 #4
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)
예제 #5
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)
예제 #6
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)
예제 #7
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)
예제 #8
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)
예제 #9
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)
예제 #10
0
 def test_appendright(self):
     ll = sllist(xrange(4))
     ref = sllist([0, 1, 2, 3, 10])
     prev = ll.nodeat(-1)
     arg_node = sllistnode(10)
     new_node = ll.appendright(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)
예제 #11
0
 def test_node_readonly_attributes(self):
     ll = sllistnode()
     self.assertRaises(AttributeError, setattr, ll, 'next', None)
예제 #12
0
 def test_remove_invalid_node(self):
     ll = sllist([1, 2, 3, 4])
     self.assertRaises(ValueError, ll.remove, sllistnode())
예제 #13
0
 def test_remove_from_empty_list(self):
     ll = sllist()
     self.assertRaises(ValueError, ll.remove, sllistnode())
예제 #14
0
 def test_remove_from_empty_list(self):
     ll = sllist()
     self.assertRaises(ValueError, ll.remove, sllistnode())
예제 #15
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())
예제 #16
0
 def test_remove_invalid_node(self):
     ll = sllist([1, 2, 3, 4])
     self.assertRaises(ValueError, ll.remove, sllistnode())
     self.assertEqual(len(ll), 4)
예제 #17
0
 def test_node_readonly_attributes(self):
     ll = sllistnode()
     self.assertRaises(AttributeError, setattr, ll, 'next', None)
예제 #18
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)
예제 #19
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)
예제 #20
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())