Esempio n. 1
0
def test_max_product_raises_error_if_array_is_empty():

    # GIVEN
    nums = []

    # EXPECT
    with pytest.raises(ValueError):
        max_product(nums)
Esempio n. 2
0
def test_max_product_returns_zero_when_all_elements_are_zero():

    # GIVEN
    nums = [0, 0, 0, 0]

    # WHEN
    result = max_product(nums)

    # THEN
    assert result == 0
Esempio n. 3
0
def test_max_product_finds_maximum_product_subarray_when_positive_and_negative_numbers_and_zeros_are_present(
):

    # GIVEN
    nums = [-1, -2, -3, 0, 1]

    # WHEN
    result = max_product(nums)

    # THEN
    assert result == 6
Esempio n. 4
0
def test_max_product_finds_maximum_product_subarray_when_some_zeroes_are_present(
):

    # GIVEN
    nums = [9, 3, 0, 2, 3, 8, 0, 7]

    # WHEN
    result = max_product(nums)

    # THEN
    assert result == 48
Esempio n. 5
0
def test_max_product_finds_maximum_product_subarray_given_odd_number_of_negative_elements(
):

    # GIVEN
    nums = [8, 3, 5, -6, 2, 4]

    # WHEN
    result = max_product(nums)

    # THEN
    assert result == 120
Esempio n. 6
0
def test_max_product_finds_maximum_product_subarray_when_all_elements_are_positive(
):

    # GIVEN
    nums = [2, 1, 4, 3, 5]

    # WHEN
    result = max_product(nums)

    # THEN
    assert result == 120
Esempio n. 7
0
def test_max_product_finds_maximum_product_subarray_given_even_number_of_negative_elements(
):

    # GIVEN
    nums = [6, 8, -2, 5, 4, -3, 10]

    # WHEN
    result = max_product(nums)

    # THEN
    assert result == 57600
Esempio n. 8
0
def test_max_product_finds_maximum_product_subarray_when_all_elements_are_negative(
):

    # GIVEN
    nums = [-4, -2, -5, -1, -3]

    # WHEN
    result = max_product(nums)

    # THEN
    assert result == 40