metrolopy 0.6.2__py3-none-any.whl → 0.6.4__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.
@@ -1,59 +1,127 @@
1
1
  # -*- coding: utf-8 -*-
2
- """
3
- Created on Thu Jul 8 14:55:05 2021
4
2
 
5
- @author: Parksh
3
+ # module test_misc
4
+
5
+ # Copyright (C) 2019 National Research Council Canada
6
+ # Author: Harold Parks
7
+
8
+ # This file is part of MetroloPy.
9
+
10
+ # MetroloPy is free software: you can redistribute it and/or modify it under
11
+ # the terms of the GNU General Public License as published by the Free Software
12
+ # Foundation, either version 3 of the License, or (at your option) any later
13
+ # version.
14
+
15
+ # MetroloPy is distributed in the hope that it will be useful, but WITHOUT ANY
16
+ # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17
+ # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18
+ # details.
19
+
20
+ # You should have received a copy of the GNU General Public License along with
21
+ # MetroloPy. If not, see <http://www.gnu.org/licenses/>.
22
+ """
23
+ Check that known bugs are fixed.
6
24
  """
7
25
 
8
26
  import metrolopy as uc
9
27
  import numpy as np
28
+ import unittest
10
29
 
11
- def test_reduce():
12
- a = uc.gummy(12.367,0.22,unit='mm/m')
13
- a.reduce_unit()
14
- assert abs(a.x - 0.012367) < 1e-15
15
- assert abs(a.u - 0.00022) < 1e-15
16
- assert a.unit is uc.one
17
-
18
- def test_zero_derivative():
19
- u = 0.00223
20
- a = uc.gummy(0,u)
21
- b = a**2
22
-
23
- assert b.u == 0
24
- b.sim()
25
- assert abs((np.sqrt(2)*u**2-b.usim)/b.usim) < 0.1
26
- b.style = 'pmsim'
27
- assert '?' not in b.tostring()
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)
39
+
40
+ def test_zero_derivative(self):
41
+ u = 0.00223
42
+ a = uc.gummy(0,u)
43
+ b = a**2
44
+
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())
50
+
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
28
100
 
29
- def test_triangular(plot=False):
30
- a = uc.gummy(uc.TriangularDist(1,1))
31
- a.sim()
32
- assert abs((a.usim - 1/np.sqrt(6))/a.usim) < 0.1
33
- if plot:
34
- print('This should be a triangle with mode 1, lower limit 0 and upper limit 1:')
35
- a.hist()
36
-
37
- a = uc.gummy(uc.TriangularDist(-2.5,left_width=0.5,right_width=1.5))
38
- a.sim()
39
- if plot:
40
- print('this should be a triangle with mode -2.5, lower limit -3 and upper limit -1:')
41
- a.hist()
42
-
43
- a = uc.gummy(uc.TriangularDist(1,lower_limit=0.5,upper_limit=1.5))
44
- a.sim()
45
- if plot:
46
- print('this should be a triangle with mode 1, lower limit 0.5 and upper limit 1.5:')
47
- a.hist()
48
-
49
- def test_zero_degc():
50
- a = uc.gummy(0, 0.15,unit='degC')
51
- a.style='xf'
52
- assert a.tostring() == '0.00'
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))
53
104
 
54
- def test_ufrom_multiletter():
55
- a = uc.gummy(10.0, 1, utype='A')
56
- b = uc.gummy(20.0, 2, utype='DUT')
57
- y = a - b
58
- assert abs(y.ufrom('A') - 1) < 1e-15
59
- assert abs(y.ufrom('DUT') - 2) < 1e-15
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()