Skip to content

Commit fb1f5dd

Browse files
committed
Adding unit tests for element not found in max-heap
1 parent 7fa7c5b commit fb1f5dd

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

data_structures/heaps/max_heap_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,22 @@ def test_max_returns_maximum_heap_element
2222
assert heap.max == 4
2323
end
2424

25+
def test_max_returns_nil_if_empty_heap
26+
heap = MaxHeap.new
27+
assert heap.max.nil?
28+
end
29+
2530
def test_extract_max_returns_and_removes_maximum_heap_element
2631
heap = MaxHeap.new([4, 1, 3])
2732
assert heap.extract_max == 4
2833
assert heap.to_array == [3, 1]
2934
end
3035

36+
def test_extract_max_returns_nil_if_empty_heap
37+
heap = MaxHeap.new
38+
assert heap.extract_max.nil?
39+
end
40+
3141
def test_insert_adds_element_to_appropriate_position
3242
heap = MaxHeap.new([4, 1, 3])
3343
heap.insert(2)

0 commit comments

Comments
 (0)