-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
One of my favorite problems refactored.
Must add my notes here too.
- Loading branch information
1 parent
bb5343d
commit cbf3b05
Showing
2 changed files
with
21 additions
and
21 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
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,21 @@ | ||
from ..max_subseq import max_subarray, find_biased_max | ||
|
||
import unittest | ||
|
||
class FunctionsTest(unittest.TestCase): | ||
|
||
def test_find_biased_max(self): | ||
self.assertEqual((6, 45), find_biased_max((5, 15, -30, 10, -5, 40, 10), 4, 6)) | ||
|
||
def test_max_subarray(self): | ||
self.assertEqual((0, 1, 20), max_subarray((5, 15, -30, 10))) | ||
# The example from the book | ||
stocks = [13, -3, -25, 20, -3, -16, -23, 18, 20, -7, 12, -5, -22, 15, -4, 7] | ||
self.assertEqual((7, 10, 43), max_subarray(stocks)) | ||
self.assertEqual((0, 1, 10), max_subarray((7, 3))) | ||
self.assertEqual((1, 1, 10), max_subarray((-10, 10))) | ||
self.assertEqual((0, 0, 10), max_subarray((10, -10))) | ||
self.assertEqual((0, 0, 10), max_subarray([10])) | ||
self.assertEqual((1, 2, 50), max_subarray((-5, 40, 10))) | ||
self.assertEqual((0, 0, -10), max_subarray([-10])) | ||
self.assertEqual((3, 6, 55), max_subarray((5, 15, -30, 10, -5, 40, 10))) |