-
Notifications
You must be signed in to change notification settings - Fork 11
/
exercise_40.rb
32 lines (26 loc) · 1.03 KB
/
exercise_40.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Exercise 40
# You will write a method, find_peaks(array), that accepts an array of integers
# The method should return an array containing all of "peaks" of the array.
# An element is considered a "peak" if it is greater than both it's left and right neighbour.
# The first or last element of the array is considered a "peak" if it is greater than it's one neighbour
# Write Your method code here
# Driver Code: Do not edit under this line
# check_solution runs a single test case and prints whether it was
# successful or not.
def check_solution(test_number, array, expected)
actual = find_peaks(array)
if actual != expected
puts "Test ##{test_number}: Incorrect value: got #{actual}, expected #{expected}"
return false
end
puts "Test ##{test_number}: Correct"
return true
end
# run_tests runs each of the test cases.
def run_tests()
check_solution(1, [1, 3, 5, 4], [5])
check_solution(2, [4, 2, 3, 6, 10], [4, 10])
check_solution(3, [4, 2, 11, 6, 10], [4, 11, 10])
end
# Execute the tests.
run_tests()