-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
98623ce
commit 0ce0f46
Showing
3 changed files
with
73 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ | |
|
||
# Act-Assert | ||
expect { | ||
answer = newman_conway(input) | ||
newman_conway(input) | ||
}.must_raise ArgumentError | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters