metrolopy 0.6.3__py3-none-any.whl → 0.6.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- metrolopy/budget.py +1 -1
- metrolopy/dfunc.py +4 -1
- metrolopy/distributions.py +1 -1
- metrolopy/fit.py +3 -3
- metrolopy/gummy.py +10 -9
- metrolopy/tests/__init__.py +0 -2
- metrolopy/tests/test_complex.py +137 -132
- metrolopy/tests/test_create.py +347 -343
- metrolopy/tests/test_gummy.py +639 -637
- metrolopy/tests/test_misc.py +94 -80
- metrolopy/tests/test_operations.py +337 -330
- metrolopy/tests/test_ubreakdown.py +335 -310
- metrolopy/unitparser.py +2 -2
- metrolopy/version.py +2 -2
- {metrolopy-0.6.3.dist-info → metrolopy-0.6.5.dist-info}/METADATA +102 -95
- {metrolopy-0.6.3.dist-info → metrolopy-0.6.5.dist-info}/RECORD +20 -20
- {metrolopy-0.6.3.dist-info → metrolopy-0.6.5.dist-info}/WHEEL +1 -1
- {metrolopy-0.6.3.dist-info → metrolopy-0.6.5.dist-info/licenses}/LICENSE +0 -0
- {metrolopy-0.6.3.dist-info → metrolopy-0.6.5.dist-info}/top_level.txt +0 -0
- {metrolopy-0.6.3.dist-info → metrolopy-0.6.5.dist-info}/zip-safe +0 -0
metrolopy/tests/test_misc.py
CHANGED
|
@@ -25,89 +25,103 @@ Check that known bugs are fixed.
|
|
|
25
25
|
|
|
26
26
|
import metrolopy as uc
|
|
27
27
|
import numpy as np
|
|
28
|
+
import unittest
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
a = uc.gummy(0,u)
|
|
39
|
-
b = a**2
|
|
40
|
-
|
|
41
|
-
assert b.u == 0
|
|
42
|
-
b.sim()
|
|
43
|
-
assert abs((np.sqrt(2)*u**2-b.usim)/b.usim) < 0.1
|
|
44
|
-
b.style = 'pmsim'
|
|
45
|
-
assert '?' not in b.tostring()
|
|
46
|
-
|
|
47
|
-
def test_triangular(plot=False):
|
|
48
|
-
a = uc.gummy(uc.TriangularDist(1,1))
|
|
49
|
-
a.sim()
|
|
50
|
-
assert abs((a.usim - 1/np.sqrt(6))/a.usim) < 0.1
|
|
51
|
-
if plot:
|
|
52
|
-
print('This should be a triangle with mode 1, lower limit 0 and upper limit 1:')
|
|
53
|
-
a.hist()
|
|
30
|
+
|
|
31
|
+
class TestMisc(unittest.TestCase):
|
|
32
|
+
|
|
33
|
+
def test_reduce(self):
|
|
34
|
+
a = uc.gummy(12.367,0.22,unit='mm/m')
|
|
35
|
+
a.reduce_unit()
|
|
36
|
+
self.assertTrue(abs(a.x - 0.012367) < 1e-15)
|
|
37
|
+
self.assertTrue(abs(a.u - 0.00022) < 1e-15)
|
|
38
|
+
self.assertTrue(a.unit is uc.one)
|
|
54
39
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
a.hist()
|
|
40
|
+
def test_zero_derivative(self):
|
|
41
|
+
u = 0.00223
|
|
42
|
+
a = uc.gummy(0,u)
|
|
43
|
+
b = a**2
|
|
60
44
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
45
|
+
self.assertTrue(b.u == 0)
|
|
46
|
+
b.sim()
|
|
47
|
+
self.assertTrue(abs((np.sqrt(2)*u**2-b.usim)/b.usim) < 0.1)
|
|
48
|
+
b.style = 'pmsim'
|
|
49
|
+
self.assertTrue('?' not in b.tostring())
|
|
66
50
|
|
|
67
|
-
def
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
51
|
+
def test_triangular(self,plot=False):
|
|
52
|
+
a = uc.gummy(uc.TriangularDist(1,1))
|
|
53
|
+
a.sim()
|
|
54
|
+
self.assertTrue(abs((a.usim - 1/np.sqrt(6))/a.usim) < 0.1)
|
|
55
|
+
if plot:
|
|
56
|
+
print('This should be a triangle with mode 1, lower limit 0 and upper limit 1:')
|
|
57
|
+
a.hist()
|
|
58
|
+
|
|
59
|
+
a = uc.gummy(uc.TriangularDist(-2.5,left_width=0.5,right_width=1.5))
|
|
60
|
+
a.sim()
|
|
61
|
+
if plot:
|
|
62
|
+
print('this should be a triangle with mode -2.5, lower limit -3 and upper limit -1:')
|
|
63
|
+
a.hist()
|
|
64
|
+
|
|
65
|
+
a = uc.gummy(uc.TriangularDist(1,lower_limit=0.5,upper_limit=1.5))
|
|
66
|
+
a.sim()
|
|
67
|
+
if plot:
|
|
68
|
+
print('this should be a triangle with mode 1, lower limit 0.5 and upper limit 1.5:')
|
|
69
|
+
a.hist()
|
|
70
|
+
|
|
71
|
+
def test_zero_degc(self):
|
|
72
|
+
a = uc.gummy(0, 0.15,unit='degC')
|
|
73
|
+
a.style='xf'
|
|
74
|
+
self.assertTrue(a.tostring() == '0.00')
|
|
75
|
+
|
|
76
|
+
def test_ufrom_multiletter(self):
|
|
77
|
+
a = uc.gummy(10.0, 1, utype='A')
|
|
78
|
+
b = uc.gummy(20.0, 2, utype='DUT')
|
|
79
|
+
y = a - b
|
|
80
|
+
self.assertTrue(abs(y.ufrom('A') - 1) < 1e-15)
|
|
81
|
+
self.assertTrue(abs(y.ufrom('DUT') - 2) < 1e-15)
|
|
82
|
+
|
|
83
|
+
def test_uniform_params(self):
|
|
84
|
+
# issue 33
|
|
85
|
+
g = uc.gummy(uc.UniformDist(lower_limit=6,upper_limit=9),unit='pA')
|
|
86
|
+
g.sim()
|
|
87
|
+
self.assertTrue(abs(min(g.simdata) - 6) < 0.01)
|
|
88
|
+
self.assertTrue(abs(max(g.simdata) - 9) < 0.01)
|
|
89
|
+
|
|
90
|
+
g = uc.gummy(uc.UniformDist(center=7.5,half_width=1.5),unit='pA')
|
|
91
|
+
g.sim()
|
|
92
|
+
self.assertTrue(abs(min(g.simdata) - 6) < 0.01)
|
|
93
|
+
self.assertTrue(abs(max(g.simdata) - 9) < 0.01)
|
|
94
|
+
|
|
95
|
+
def test_mean_b(self):
|
|
96
|
+
# issue 32
|
|
97
|
+
import numpy as np
|
|
98
|
+
from scipy.stats import t
|
|
99
|
+
from scipy import special
|
|
85
100
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
assert abs(max(g.simdata) - 9) < 0.01
|
|
101
|
+
con = special.erf(1/np.sqrt(2))
|
|
102
|
+
def u(x):
|
|
103
|
+
return t.ppf(1-(1-con)/2, len(x)-1)*x.std(ddof=1)/np.sqrt(len(x))
|
|
90
104
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
uc.gummy.
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
105
|
+
x = np.random.rand(5)
|
|
106
|
+
g = uc.mean(x)
|
|
107
|
+
g.p = 'ssd'
|
|
108
|
+
self.assertTrue(abs(con-g.p) < 1e-6)
|
|
109
|
+
self.assertTrue(abs(g.U - u(x)) < 1e-6)
|
|
110
|
+
try:
|
|
111
|
+
uc.gummy.bayesian = True
|
|
112
|
+
gg = uc.mean(x)
|
|
113
|
+
self.assertTrue(abs(gg.u - np.sqrt(2)*g.u) < 1e-6)
|
|
114
|
+
gg.p = 'ssd'
|
|
115
|
+
self.assertTrue(abs(gg.U - u(x)) < 1e-6)
|
|
116
|
+
finally:
|
|
117
|
+
uc.gummy.bayesian = False
|
|
118
|
+
|
|
119
|
+
def test_uniform_hw(self):
|
|
120
|
+
# issue 37
|
|
121
|
+
a = uc.gummy(uc.UniformDist(upper_limit=1,lower_limit=-1))
|
|
122
|
+
b = uc.gummy(uc.UniformDist(center=0,half_width=1))
|
|
123
|
+
self.assertTrue(abs(a.u - b.u) < 1e-15)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
if __name__ == '__main__':
|
|
127
|
+
unittest.main()
|