Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion linked_lists/linked_list_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def test_it_pushes_three_elements_onto_a_list
list.push("hello")
list.push("world")
list.push("today")

assert_equal 3, list.count
end

Expand All @@ -27,36 +28,45 @@ def test_it_pops_the_last_element_from_the_list
list.push("hello")
list.push("world")
list.push("today")

output = list.pop

assert_equal "today", output
assert_equal 2, list.count
end

def test_a_popped_element_is_removed
skip
list.push("hello")

output = list.pop

assert_equal "hello", output
assert_equal 0, list.count
end

def test_it_pops_nil_when_there_are_no_elements
skip

assert_nil list.pop
end

def test_it_deletes_a_solo_node
skip
list.push("hello")

list.delete("hello")

assert_equal 0, list.count
end

def test_it_does_not_delete_when_the_data_does_not_match
skip
list.push("hello")
list.push("world")

list.delete("today")

assert_equal 2, list.count
end

Expand All @@ -65,7 +75,9 @@ def test_it_deletes_a_last_node
list.push("hello")
list.push("world")
list.push("today")

list.delete("today")

assert_equal 2, list.count
end

Expand All @@ -74,7 +86,9 @@ def test_it_deletes_a_middle_node
list.push("hello")
list.push("world")
list.push("today")

list.delete("world")

assert_equal 2, list.count
assert_equal "today", list.pop
assert_equal "hello", list.pop
Expand All @@ -85,14 +99,17 @@ def test_it_deletes_the_head_when_there_are_more_nodes
list.push("hello")
list.push("world")
list.push("today")

list.delete("hello")

assert_equal 2, list.count
assert_equal "today", list.pop
assert_equal "world", list.pop
end

def test_it_converts_to_an_array_when_there_are_no_elements
skip

assert_equal [], list.to_a
end

Expand All @@ -101,35 +118,41 @@ def test_it_converts_to_an_array_with_several_elements
list.push("hello")
list.push("world")
list.push("today")

assert_equal ["hello", "world", "today"], list.to_a
end

def test_it_finds_the_last_node
skip
list.push("hello")
list.push("world")

node = list.last_node

assert_equal "world", node.data
end

def test_a_node_links_to_its_next_element
skip
list.push("hello")
list.push("world")

assert_equal "world", list.last_node.data
assert_equal "world", list.head_node.next_node.data
end

def test_next_node_for_the_last_node_is_nil
skip
list.push("world")

assert_nil list.last_node.next_node
end

def test_find_if_an_element_is_included_in_the_list
skip
list.push("hello")
list.push("world")

assert_equal true, list.include?("hello")
assert_equal false, list.include?("bogus")
end
Expand Down Expand Up @@ -181,16 +204,31 @@ def test_insert_after_adds_a_node_after_a_given_node
end

def test_distance_returns_distance_between_two_nodes
skip
list.push("hello")
list.push("pizza")
list.push("world")
list.push("today")
list.push("tomorrow")

assert_equal 3, list.distance("hello", "today")
assert_equal 2, list.distance("pizza", "today")
assert_equal 2, list.distance("hello", "world")
assert_equal 4, list.distance("hello", "tomorrow")
assert_equal 1, list.distance("world", "today")
end


def test_dequeue_treates_list_like_a_stack
skip
list.push("hello")
list.push("pizza")
list.push("world")

list.dequeue

assert_equal false, list.include?("hello")
assert_equal true, list.include?("pizza")
assert_equal 2, list.count
end

end