def test_reverse_linked_list_size_1():
	a = LinkedListNode(1)

	assert a.value == 1
	assert a.next is None

	# Reverse list and get new head node
	new_head_node = reverse_linked_list(a)

	assert new_head_node.value == 1
	assert new_head_node.next is None
def test_reverse_linked_list():
	a = LinkedListNode(1)
	b = LinkedListNode(2)
	c = LinkedListNode(3)
	d = LinkedListNode(4)
	# put b after a
	a.next = b
	# put c after b
	b.next = c
	# put d after c
	c.next = d

	assert a.value == 1
	assert a.next.value == 2
	assert a.next.next.value == 3
	assert a.next.next.next.value == 4

	# Reverse list and get new head node
	new_head_node = reverse_linked_list(a)

	assert new_head_node.value == 4
	assert new_head_node.next.value == 3
	assert new_head_node.next.next.value == 2
	assert new_head_node.next.next.next.value == 1
Exemplo n.º 3
0
def test_contains_cycle_no_cycle():
	a = LinkedListNode('a')
	b = LinkedListNode('b')
	c = LinkedListNode('c')
	d = LinkedListNode('d')
	e = LinkedListNode('e')
	a.next = b
	b.next = c
	c.next = d
	d.next = e

	assert not contains_cycle(a)
Exemplo n.º 4
0
def test_contains_cycle_has_cycle_second():
	a = LinkedListNode('a')
	b = LinkedListNode('b')
	c = LinkedListNode('c')
	d = LinkedListNode('d')
	a.next = b
	b.next = c
	c.next = d
	d.next = b

	assert contains_cycle(a)
Exemplo n.º 5
0
def test_set_impl_has_cycle_first():
	a = LinkedListNode('a')
	b = LinkedListNode('b')
	c = LinkedListNode('c')
	d = LinkedListNode('d')
	a.next = b
	b.next = c
	c.next = d
	d.next = a

	assert contains_cycle_set_impl(a)