Example #1
0
def test_all_negative_case():
    """Testing that function returns correct answer with negative only"""
    assert find_maximal_subarray_sum([-1, -2, -3, -4, -10], 4) == -1
Example #2
0
def test_pos_neg_case():
    """Testing that returns correct with positive and negative integers"""
    assert find_maximal_subarray_sum([1, 3, -1, -3, 5, 3, 6, 7], 3) == 16
Example #3
0
def test_empty_list_case():
    """Testing that function returns 0 if list is empty"""
    assert find_maximal_subarray_sum([], 3) == 0
Example #4
0
def test_negative_case3():
    """Testing with k=0"""
    assert not find_maximal_subarray_sum([1, 2, 3], k=0) != 0
Example #5
0
def test_positive_case1():
    """Testing that function finds subarray with max sum correctly"""
    assert find_maximal_subarray_sum([1, 3, -1, -3, 5, 3, 6, 7], k=3) == 16
Example #6
0
def test_negative_case1():
    """Testing with k > len(num)"""
    assert not find_maximal_subarray_sum([1, 2, 3], k=4)
Example #7
0
def test_negative_case2():
    """Check for output data type"""
    assert not type(find_maximal_subarray_sum([1, 2, 3], k=1)) != int
Example #8
0
def test_find_maximal_subarray_sum_empty_list():
    assert find_maximal_subarray_sum([], 2) is None
Example #9
0
def test_find_maximal_subarray_sum_negative_nums_only():
    assert find_maximal_subarray_sum([-1, -2, -5, -50], 3) == -1
Example #10
0
def test_find_maximal_subarray_sum_positive_nums_only_3_val():
    assert find_maximal_subarray_sum([1, 2, 5, 50], 3) == 57
Example #11
0
def test_find_maximal_subarray_sum_positive_nums_only_2_val():
    assert find_maximal_subarray_sum([1, 2, 1, 2, 1], 2) == 3
Example #12
0
def test_find_maximal_subarray_sum_positive_and_negatives_nums():
    assert find_maximal_subarray_sum([2, -1, 2, -5, -50], 3) == 3
Example #13
0
def test_subarray_sum(nums: List[int], k: int, expected_result: int):
    actual_result = find_maximal_subarray_sum(nums, k)

    assert actual_result == expected_result
Example #14
0
def test_sum_of_subarray_longer_than_array():
    """Testing that subarray longer than array gives sum of array."""
    arr = [1, -12, 5, 78, 0]
    assert find_maximal_subarray_sum(arr, 7) == sum(arr)
Example #15
0
def test_sum_of_long_array():
    """Testing that sum of subarray is counted correctly."""
    assert find_maximal_subarray_sum([1, 3, -1, -3, 5, 3, 6, 7], 3) == 16
Example #16
0
def test_sum_of_empty_array():
    """Testing that sum of subarray of empty array gives zero."""
    assert find_maximal_subarray_sum([], 3) == 0