forked from AdaGold/dynamic-programming
-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathmax_sub_array_test.rb
70 lines (51 loc) · 1.18 KB
/
max_sub_array_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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
require_relative "test_helper"
xdescribe "max subarray" do
it "will work for [-2,1,-3,4,-1,2,1,-5,4]" do
# Arrange
input = [-2,1,-3,4,-1,2,1,-5,4]
# Act
answer = max_sub_array(input)
# Assert
expect(answer).must_equal 6
end
it "will work with a totally negative array" do
# Arrange
input = [-3, -4, -5, -6, -7]
# Act
answer = max_sub_array(input)
# Assert
expect(answer).must_equal(-3)
end
it "will work with a totally negative array with the largest element at the rear" do
# Arrange
input = [ -4, -5, -6, -7, -3]
# Act
answer = max_sub_array(input)
# Assert
expect(answer).must_equal(-3)
end
it "will work with a 1-element array" do
# Arrange
input = [3]
# Act
answer = max_sub_array(input)
# Assert
expect(answer).must_equal 3
end
it "will return nil for an empty array" do
# Arrange
input = []
# Act
answer = max_sub_array(input)
# Assert
expect(answer).must_be_nil
end
it "will work for [50, -50, 50]" do
# Arrange
input = [50, -50, 50]
# Act
answer = max_sub_array(input)
# Assert
expect(answer).must_equal 50
end
end