-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrori_test.py
90 lines (61 loc) · 1.94 KB
/
errori_test.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import unittest
import sympy as sp
from uncertainties import ufloat
import uncertainties.umath as uu
from errori import compute_error
class TESTS(unittest.TestCase):
def test_0(self):
''' Litte test
'''
x = sp.Symbol('x')
y = sp.Symbol('y')
X = [x, y]
f = x + y
data = [1.2, 2]
error = [0.1, 0.15]
prop_err = compute_error(f, X, data, error)
x = ufloat(data[0], error[0])
y = ufloat(data[1], error[1])
f = x + y
print("prop_code:", prop_err)
print("prop_lib :", f)
self.assertAlmostEqual(prop_err[0], f.n, 10)
self.assertAlmostEqual(prop_err[1], f.s, 10)
def test_1(self):
''' Litte test
'''
x = sp.Symbol('x')
y = sp.Symbol('y')
X = [x, y]
f = ((1/x) + (1/y))**(-1)
data = [1.2, 2]
error = [0.1, 0.15]
prop_err = compute_error(f, X, data, error)
x = ufloat(data[0], error[0])
y = ufloat(data[1], error[1])
f = ((1/x) + (1/y))**(-1)
print("prop_code:", prop_err)
print("prop_lib :", f)
self.assertAlmostEqual(prop_err[0], f.n, 10)
self.assertAlmostEqual(prop_err[1], f.s, 10)
def test_2(self):
''' Litte test
'''
x = sp.Symbol('x')
y = sp.Symbol('y')
z = sp.Symbol('z')
X = [x, y, z]
f = sp.sin(x*z)*sp.log(y/z) + sp.tan(x**y)
data = [1.2, 2, 1.5]
error = [0.1, 0.15, 0.2]
prop_err = compute_error(f, X, data, error)
x = ufloat(data[0], error[0])
y = ufloat(data[1], error[1])
z = ufloat(data[2], error[2])
f = uu.sin(x*z)*uu.log(y/z) + uu.tan(x**y)
print("prop_code:", prop_err)
print("prop_lib :", f)
self.assertAlmostEqual(prop_err[0], f.n, 10)
self.assertAlmostEqual(prop_err[1], f.s, 10)
if __name__ == '__main__':
unittest.main()