Пример #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())