Ejemplo n.º 1
0
	# 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

	print("All Tests Pass Successfuly")

except AssertionError as e:
Ejemplo n.º 2
0
def test_single_linkedlist():
    list = LinkedList()
    list.insert(1)
    list.insert(2)
    list.insert(20)
    list.insert(24)
    list.insert(34)

    print(list)
    print(list.get(4))

    list.remove(1)
    print(list)
    list.insert(50)
    print(list)

    list.removeAt(3)
    print(list)
    list.insertAt(3, 10)
    print(list)

    # Test with String
    list = LinkedList()
    list.insert('A')
    list.insert('m')
    list.insert('m')
    print(list)
    list.removeAt(2)
    list.insert('i')
    list.insert('t')
    print(list)