Ejemplo n.º 1
0
	e3 = Element(3)
	e4 = Element(4)

	# Start setting up a LinkedList
	ll = LinkedList(e1)
	ll.append(e2)
	ll.append(e3)

	# Test cases
	
	# Should print 3
	assert ll.head.next.next.value == 3

	# Test get_position
	# Should print 3
	assert ll.get_position(3).value == 3

	# Test insert
	ll.insert(e4,3)
	# Should print 4 now
	assert ll.get_position(3).value == 4

	# Test delete
	ll.delete(1)
	# Should print 2 now
	assert ll.get_position(1).value == 2
	# Should print 4 now
	assert ll.get_position(2).value == 4
	# Should print 3 now
	assert ll.get_position(3).value == 3
Ejemplo n.º 2
0
# Set up some Elements
e1 = Element(1)
e2 = Element(2)
e3 = Element(3)
e4 = Element(4)

# Start setting up a LinkedList
ll = LinkedList(e1)
ll.append(e2)

ll.append(e3)

# Test get_position
# Should print 3
print(ll.head.next.next.value)
# Should also print 3
print(ll.get_position(3).value)

# Test insert
ll.insert(e4, 3)
# Should print 4 now
print(ll.get_position(3).value)

# Test delete
ll.delete(1)
# Should print 2 now
print(ll.get_position(1).value)
# Should print 4 now
print(ll.get_position(2).value)
# Should print 3 now
print(ll.get_position(3).value)