-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patharray_peak_test.rb
43 lines (36 loc) · 1.08 KB
/
array_peak_test.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
33
34
35
36
37
38
39
40
41
42
43
require_relative "../../test_helper"
require_relative "array_peak"
describe ArrayPeak do
describe "corner cases" do
it "should return nil for empty array as input" do
actual = ArrayPeak.run([])
expect(actual).must_be_nil
end
it "should work for array with single item" do
actual = ArrayPeak.run([1])
expect(actual).must_equal 1
end
it "should work for array with 2 asc elements" do
actual = ArrayPeak.run([0, 1])
expect(actual).must_equal 1
end
it "should work for array with 2 desc elements" do
actual = ArrayPeak.run([1, 0])
expect(actual).must_equal 1
end
it "should work when first element is peak" do
actual = ArrayPeak.run([5, 3, 1])
expect(actual).must_equal 5
end
it "should work when last element is peak" do
actual = ArrayPeak.run([1, 2, 3])
expect(actual).must_equal 3
end
end
describe "regular cases" do
it "should find the peak in the middle" do
actual = ArrayPeak.run([5, 10, 20, 15, 16, 17, 18, 15])
expect(actual).must_equal 20
end
end
end