Hong-Phuc Bui
6 days ago c97d23edee3e224f1bcba0add74b61934ad69ff7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from polynomial import Polynomial
EPSILON = 0.001
 
def test_polynomial_representation():
    c = Polynomial(5, 6, 0, -7)
    s = f'{c}'
    assert s == '5 6 0 -7'
 
def test_evaluate():
    l = Polynomial(-12.5, 3.6)
    x = 0.0
    (y, rest) = l.evaluate(x)
    assert abs(y + 12.5) < EPSILON
 
def test_evaluate_2():
    l = Polynomial(11, 7, -5, -4, 2)
    x = 2
    rest_expected = [-3, -5, 0, 2]
    y_expected = 5
    (y, rest) = l.evaluate(x)
 
    assert abs(y - y_expected) < EPSILON
    for (i, r) in enumerate( rest_expected ):
        assert abs(r - rest[i]) < EPSILON
 
 
if __name__ == "__main__":
    test_evaluate_2()