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.
@@ -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
- def test_reduce():
30
- a = uc.gummy(12.367,0.22,unit='mm/m')
31
- a.reduce_unit()
32
- assert abs(a.x - 0.012367) < 1e-15
33
- assert abs(a.u - 0.00022) < 1e-15
34
- assert a.unit is uc.one
35
-
36
- def test_zero_derivative():
37
- u = 0.00223
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
- a = uc.gummy(uc.TriangularDist(-2.5,left_width=0.5,right_width=1.5))
56
- a.sim()
57
- if plot:
58
- print('this should be a triangle with mode -2.5, lower limit -3 and upper limit -1:')
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
- a = uc.gummy(uc.TriangularDist(1,lower_limit=0.5,upper_limit=1.5))
62
- a.sim()
63
- if plot:
64
- print('this should be a triangle with mode 1, lower limit 0.5 and upper limit 1.5:')
65
- a.hist()
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 test_zero_degc():
68
- a = uc.gummy(0, 0.15,unit='degC')
69
- a.style='xf'
70
- assert a.tostring() == '0.00'
71
-
72
- def test_ufrom_multiletter():
73
- a = uc.gummy(10.0, 1, utype='A')
74
- b = uc.gummy(20.0, 2, utype='DUT')
75
- y = a - b
76
- assert abs(y.ufrom('A') - 1) < 1e-15
77
- assert abs(y.ufrom('DUT') - 2) < 1e-15
78
-
79
- def test_uniform_params():
80
- # issue 33
81
- g = uc.gummy(uc.UniformDist(lower_limit=6,upper_limit=9),unit='pA')
82
- g.sim()
83
- assert abs(min(g.simdata) - 6) < 0.01
84
- assert abs(max(g.simdata) - 9) < 0.01
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
- g = uc.gummy(uc.UniformDist(center=7.5,half_width=1.5),unit='pA')
87
- g.sim()
88
- assert abs(min(g.simdata) - 6) < 0.01
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
- def test_mean_b():
92
- # issue 32
93
- import numpy as np
94
- from scipy.stats import t
95
- from scipy import special
96
-
97
- con = special.erf(1/np.sqrt(2))
98
- def u(x):
99
- return t.ppf(1-(1-con)/2, len(x)-1)*x.std(ddof=1)/np.sqrt(len(x))
100
-
101
- x = np.random.rand(5)
102
- g = uc.mean(x)
103
- g.p = 'ssd'
104
- assert abs(con-g.p) < 1e-6
105
- assert abs(g.U - u(x)) < 1e-6
106
- try:
107
- uc.gummy.bayesian = True
108
- gg = uc.mean(x)
109
- assert abs(gg.u - np.sqrt(2)*g.u) < 1e-6
110
- gg.p = 'ssd'
111
- assert abs(gg.U - u(x)) < 1e-6
112
- finally:
113
- uc.gummy.bayesian = False
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()