Exemplo n.º 1
0
    def test_random_inputs(self):
        def naive_implementation(numbers):
            return max(a * b * c for (a, b, c) in combinations(numbers, 3))

        for _ in range(100):
            nums = random.sample(range(-100, 100), 20)
            assert naive_implementation(nums) == highest_product(nums)
Exemplo n.º 2
0
def _highest_product():
    raw_nums = request.form['numbers']
    nums = []
    for num in raw_nums.split():
        try:
            nums.append(int(num))
        except ValueError:
            return jsonify(error="%s is not a valid integer" % num)
    try:
        prod = highest_product(nums)
    except ValueError:
        return jsonify(error="Needs at least three integers")
    return jsonify(result=prod)
Exemplo n.º 3
0
 def test_too_short_input(self):
     with pytest.raises(ValueError):
         highest_product([0, 6])
Exemplo n.º 4
0
 def test_very_long_input(self):
     numbers = [6, 5, 10] + [1, 2] * 350 + [-10, -5] * 1000
     assert highest_product(numbers) == -10 * -10 * 10
Exemplo n.º 5
0
 def test_long_input(self):
     numbers = [6, 5, 10] + [1, 2] * 350
     assert highest_product(numbers) == 300
Exemplo n.º 6
0
 def test_zero_result(self):
     numbers = [-10, -5, -2, 0]
     assert highest_product(numbers) == 0
Exemplo n.º 7
0
 def test_mixed_sign_negative_result(self):
     numbers = [1, -10, 5]
     assert highest_product(numbers) == 1 * -10 * 5
Exemplo n.º 8
0
 def test_mixed_sign_positive_result(self):
     numbers = [1, -6, -5, 10, 5]
     assert highest_product(numbers) == 10 * -6 * -5
Exemplo n.º 9
0
 def test_all_negative(self):
     numbers = [-1, -6, -5, -10, -5]
     assert highest_product(numbers) == -1 * -5 * -5
Exemplo n.º 10
0
 def test_all_positive(self):
     numbers = [1, 6, 5, 10, 5]
     assert highest_product(numbers) == 10 * 6 * 5