Ejemplo n.º 1
0
def test_should_raise_an_exception_if_numbers_list_has_not_len_10():
    with pytest.raises(Exception):
        assert compute_weighted_avg([1, 2, 3], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
Ejemplo n.º 2
0
def test_should_compute_nominal_weighted_avg():
    with pytest.raises(TypeError):
        assert compute_weighted_avg(
            ['c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c'],
            [1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
Ejemplo n.º 3
0
def test_should_compute_complex_weighted_avg():
    avg = compute_weighted_avg([10, 5, 12, 7, 9, 1, 3, 5, 14, 18],
                               [1, 1, 3, 1, 6, 1, 1, 3, 1, 6])

    assert round(avg * 100) / 100 == 10.54
Ejemplo n.º 4
0
def test_should_compute_nominal_weighted_avg():
    avg = compute_weighted_avg([10, 10, 10, 10, 10, 10, 10, 10, 10, 10],
                               [1, 1, 1, 1, 1, 1, 1, 1, 1, 1])

    assert avg == 10
Ejemplo n.º 5
0
def test_should_raise_an_exception_if_coeff_list_has_not_len_10():
    with pytest.raises(Exception):
        assert compute_weighted_avg([10, 10, 10, 10, 10, 10, 10, 10, 10, 10],
                                    [1, 2, 3])
Ejemplo n.º 6
0
from ex2.core import compute_weighted_avg

if __name__ == '__main__':
    input_str = 'please enter 10 real comma-separated {} (e.g.: 1,2,3,4,5,6,7,8,9,10): '
    user_number_input = input(input_str.format('numbers')).split(',')
    user_coefficient_input = input(input_str.format('coefficients')).split(',')
    print(
        compute_weighted_avg(
            list(map(lambda nb: float(nb), user_number_input)),
            list(map(lambda nb: float(nb), user_coefficient_input))))