From ef301b953b1822ed6de80be6f7793a678d913c91 Mon Sep 17 00:00:00 2001 From: Michael Dao Date: Sun, 8 Feb 2015 21:31:53 -0700 Subject: [PATCH 1/2] Added test to have student implement a dequeue method for FIFO --- linked_lists/linked_list_test.rb | 39 +++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/linked_lists/linked_list_test.rb b/linked_lists/linked_list_test.rb index 7d7c72b..66784b4 100644 --- a/linked_lists/linked_list_test.rb +++ b/linked_lists/linked_list_test.rb @@ -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 @@ -27,7 +28,9 @@ 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 @@ -35,20 +38,25 @@ def test_it_pops_the_last_element_from_the_list 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 @@ -56,7 +64,9 @@ 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 @@ -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 @@ -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 @@ -85,7 +99,9 @@ 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 @@ -93,6 +109,7 @@ def test_it_deletes_the_head_when_there_are_more_nodes def test_it_converts_to_an_array_when_there_are_no_elements skip + assert_equal [], list.to_a end @@ -101,6 +118,7 @@ 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 @@ -108,7 +126,9 @@ def test_it_finds_the_last_node skip list.push("hello") list.push("world") + node = list.last_node + assert_equal "world", node.data end @@ -116,6 +136,7 @@ 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 @@ -123,6 +144,7 @@ def test_a_node_links_to_its_next_element def test_next_node_for_the_last_node_is_nil skip list.push("world") + assert_nil list.last_node.next_node end @@ -130,6 +152,7 @@ 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 @@ -181,16 +204,30 @@ 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 + 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 From 53d79a2c3733b32eb80bfbeb93a9ebc27fea719b Mon Sep 17 00:00:00 2001 From: Michael Dao Date: Sun, 8 Feb 2015 21:37:00 -0700 Subject: [PATCH 2/2] Added a skip to final test --- linked_lists/linked_list_test.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/linked_lists/linked_list_test.rb b/linked_lists/linked_list_test.rb index 66784b4..0e426dd 100644 --- a/linked_lists/linked_list_test.rb +++ b/linked_lists/linked_list_test.rb @@ -219,6 +219,7 @@ def test_distance_returns_distance_between_two_nodes end def test_dequeue_treates_list_like_a_stack + skip list.push("hello") list.push("pizza") list.push("world")