Exemplo n.º 1
0
def test_max_product_raises_error_if_array_is_empty():

    # GIVEN
    nums = []

    # EXPECT
    with pytest.raises(ValueError):
        max_product(nums)
Exemplo 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
Exemplo 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
Exemplo 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
Exemplo 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
Exemplo 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
Exemplo 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
Exemplo 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