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_create.py
CHANGED
|
@@ -3,384 +3,388 @@
|
|
|
3
3
|
import metrolopy as uc
|
|
4
4
|
import numpy as np
|
|
5
5
|
import warnings
|
|
6
|
+
import unittest
|
|
6
7
|
|
|
7
8
|
from metrolopy.tests.common import rand,display
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
def test_gummy_init(n=None,exception_on_warning=True,prnt=False,plot=False):
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
else:
|
|
20
|
-
n = 10000
|
|
21
|
-
|
|
22
|
-
units=['m','lb','m**2 s**3/kg**4','degF','cm','%','kg']
|
|
23
|
-
uunits = {'%':100, 'ppm':1e6, 'ppb':1e9, 'ms/s':1000}
|
|
24
|
-
|
|
25
|
-
with warnings.catch_warnings():
|
|
26
|
-
if exception_on_warning:
|
|
27
|
-
warnings.simplefilter('error')
|
|
28
|
-
else:
|
|
29
|
-
warnings.simplefilter('ignore')
|
|
30
|
-
|
|
31
|
-
for i in range(n):
|
|
32
|
-
|
|
33
|
-
if rand.randint(2):
|
|
34
|
-
unit = units[rand.randint(len(units))]
|
|
35
|
-
else:
|
|
36
|
-
unit = uc.one
|
|
37
|
-
|
|
38
|
-
if rand.randint(2):
|
|
39
|
-
if unit == 'm':
|
|
40
|
-
if rand.randint(2):
|
|
41
|
-
uunit = 'mm'
|
|
42
|
-
elif rand.randint(2):
|
|
43
|
-
uunit = 'm'
|
|
44
|
-
else:
|
|
45
|
-
uunit = 'in'
|
|
46
|
-
else:
|
|
47
|
-
if unit in ['degF','dB(SPL)','Np']:
|
|
48
|
-
uunit = None
|
|
49
|
-
else:
|
|
50
|
-
uunit = list(uunits.keys())[rand.randint(len(uunits))]
|
|
10
|
+
class TestCreate(unittest.TestCase):
|
|
11
|
+
def test_gummy_init(self,n=None,exception_on_warning=True,prnt=False,plot=False):
|
|
12
|
+
try:
|
|
13
|
+
from scipy.stats import norm, t
|
|
14
|
+
|
|
15
|
+
uc.gummy.p_method = None
|
|
16
|
+
|
|
17
|
+
if n is None:
|
|
18
|
+
if prnt or plot:
|
|
19
|
+
n = 100
|
|
51
20
|
else:
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
21
|
+
n = 10000
|
|
22
|
+
|
|
23
|
+
units=['m','lb','m**2 s**3/kg**4','degF','cm','%','kg']
|
|
24
|
+
uunits = {'%':100, 'ppm':1e6, 'ppb':1e9, 'ms/s':1000}
|
|
25
|
+
|
|
26
|
+
with warnings.catch_warnings():
|
|
27
|
+
if exception_on_warning:
|
|
28
|
+
warnings.simplefilter('error')
|
|
58
29
|
else:
|
|
59
|
-
|
|
30
|
+
warnings.simplefilter('ignore')
|
|
31
|
+
|
|
32
|
+
for i in range(n):
|
|
60
33
|
|
|
61
|
-
if rand.randint(2):
|
|
62
34
|
if rand.randint(2):
|
|
63
|
-
|
|
64
|
-
p = None
|
|
65
|
-
else:
|
|
66
|
-
p = rand.rand()/2 + 0.49
|
|
67
|
-
k = 1
|
|
68
|
-
else:
|
|
69
|
-
k = 1
|
|
70
|
-
p = None
|
|
71
|
-
|
|
72
|
-
if rand.randint(2):
|
|
73
|
-
pmethods = ['loc','level of confidence','cp','coverage probability','gauss','ccp','ccp','conservative coverage probability','chebyshev']
|
|
74
|
-
uc.gummy.p_method = pmethods[rand.randint(len(pmethods))]
|
|
75
|
-
else:
|
|
76
|
-
uc.gummy.p_method = None
|
|
77
|
-
|
|
78
|
-
if unit == 'dB(SPL)':
|
|
79
|
-
if rand.randint(10) == 0:
|
|
80
|
-
x = rand.randint(-10,10)
|
|
35
|
+
unit = units[rand.randint(len(units))]
|
|
81
36
|
else:
|
|
82
|
-
|
|
83
|
-
elif unit == 'Np':
|
|
84
|
-
if rand.randint(10) == 0:
|
|
85
|
-
x = rand.randint(-10,10)
|
|
86
|
-
else:
|
|
87
|
-
x = 20.0*(2*rand.rand() - 1)
|
|
88
|
-
else:
|
|
89
|
-
if rand.randint(10) == 0:
|
|
90
|
-
x = rand.randint(-60000,60000)
|
|
91
|
-
else:
|
|
92
|
-
x = (2*rand.rand() - 1)*10.0**rand.randint(-10,10)
|
|
93
|
-
if rand.randint(20) == 0:
|
|
94
|
-
x = 0
|
|
37
|
+
unit = uc.one
|
|
95
38
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
u = U/1000
|
|
105
|
-
elif unit == 'm' and uunit == 'in':
|
|
106
|
-
if x == 0:
|
|
107
|
-
U = 100*rand.rand()
|
|
108
|
-
else:
|
|
109
|
-
U = abs(x)*100*rand.rand()
|
|
110
|
-
u = U*0.0254
|
|
111
|
-
else:
|
|
112
|
-
if x == 0:
|
|
113
|
-
U = 1.0e12*rand.rand()
|
|
114
|
-
else:
|
|
115
|
-
if rand.randint(20) == 0:
|
|
116
|
-
U = 1e6*abs(x)*rand.rand()
|
|
117
|
-
elif rand.randint(20) == 0:
|
|
118
|
-
U = rand.randint(20)+1
|
|
39
|
+
if rand.randint(2):
|
|
40
|
+
if unit == 'm':
|
|
41
|
+
if rand.randint(2):
|
|
42
|
+
uunit = 'mm'
|
|
43
|
+
elif rand.randint(2):
|
|
44
|
+
uunit = 'm'
|
|
45
|
+
else:
|
|
46
|
+
uunit = 'in'
|
|
119
47
|
else:
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
name = chr(rand.randint(20) + 65) + chr(rand.randint(20) + 65) + chr(rand.randint(20) + 65)
|
|
125
|
-
else:
|
|
126
|
-
name = None
|
|
127
|
-
|
|
128
|
-
if rand.randint(2):
|
|
129
|
-
utype = chr(rand.randint(20) + 65) + chr(rand.randint(20) + 65) + chr(rand.randint(20) + 65)
|
|
130
|
-
else:
|
|
131
|
-
utype = None
|
|
132
|
-
|
|
133
|
-
if rand.randint(20) == 0:
|
|
134
|
-
assert uc.gummy(x) == x
|
|
135
|
-
continue
|
|
136
|
-
|
|
137
|
-
if rand.randint(20) == 0:
|
|
138
|
-
const = True
|
|
139
|
-
U = 0
|
|
140
|
-
u = 0
|
|
141
|
-
else:
|
|
142
|
-
if u == 0:
|
|
143
|
-
const = True
|
|
48
|
+
if unit in ['degF','dB(SPL)','Np']:
|
|
49
|
+
uunit = None
|
|
50
|
+
else:
|
|
51
|
+
uunit = list(uunits.keys())[rand.randint(len(uunits))]
|
|
144
52
|
else:
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
uc.gummy.bayesian = bayesian
|
|
148
|
-
if uunit is not None and rand.randint(2):
|
|
149
|
-
uu = uc.gummy(U,unit=uunit)
|
|
150
|
-
g = uc.gummy(x,u=uu,unit=unit,dof=dof,k=k,p=p,name=name,
|
|
151
|
-
utype=utype)
|
|
152
|
-
else:
|
|
153
|
-
g = uc.gummy(x,u=U,unit=unit,dof=dof,k=k,p=p,uunit=uunit,
|
|
154
|
-
name=name,utype=utype)
|
|
53
|
+
uunit = None
|
|
155
54
|
|
|
156
|
-
|
|
157
|
-
u = u/g.k
|
|
55
|
+
bayesian = bool(rand.randint(2))
|
|
158
56
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
n = rand.randint(12)
|
|
163
|
-
if bayesian and n > 0:
|
|
57
|
+
if rand.randint(2):
|
|
58
|
+
dof = rand.randint(3,20)
|
|
59
|
+
else:
|
|
164
60
|
dof = float('inf')
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
elif n == 1:
|
|
171
|
-
if unit == 'degF':
|
|
172
|
-
g = g + uc.gummy(0,unit='degF-i')
|
|
173
|
-
else:
|
|
174
|
-
g = 1*g
|
|
175
|
-
elif n == 2:
|
|
176
|
-
if unit == 'degF':
|
|
177
|
-
g = g + uc.gummy(0,unit='degF-i')
|
|
178
|
-
else:
|
|
179
|
-
g = g*1
|
|
180
|
-
elif n == 3:
|
|
181
|
-
if unit == 'degF':
|
|
182
|
-
g = g + uc.gummy(0,unit='degF-i')
|
|
61
|
+
|
|
62
|
+
if rand.randint(2):
|
|
63
|
+
if rand.randint(2):
|
|
64
|
+
k = 4*rand.rand() + 0.1
|
|
65
|
+
p = None
|
|
183
66
|
else:
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
67
|
+
p = rand.rand()/2 + 0.49
|
|
68
|
+
k = 1
|
|
69
|
+
else:
|
|
70
|
+
k = 1
|
|
71
|
+
p = None
|
|
72
|
+
|
|
73
|
+
if rand.randint(2):
|
|
74
|
+
pmethods = ['loc','level of confidence','cp','coverage probability','gauss','ccp','ccp','conservative coverage probability','chebyshev']
|
|
75
|
+
uc.gummy.p_method = pmethods[rand.randint(len(pmethods))]
|
|
76
|
+
else:
|
|
77
|
+
uc.gummy.p_method = None
|
|
78
|
+
|
|
79
|
+
if unit == 'dB(SPL)':
|
|
80
|
+
if rand.randint(10) == 0:
|
|
81
|
+
x = rand.randint(-10,10)
|
|
190
82
|
else:
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
v = uc.gummy(0,unit='degF-i')
|
|
196
|
-
elif unit is not uc.one or rand.randint(2):
|
|
197
|
-
v = uc.gummy(0,unit=unit)
|
|
83
|
+
x = 100.0*(2*rand.rand() - 1)
|
|
84
|
+
elif unit == 'Np':
|
|
85
|
+
if rand.randint(10) == 0:
|
|
86
|
+
x = rand.randint(-10,10)
|
|
198
87
|
else:
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
v = uc.gummy(0,unit='degF-i')
|
|
204
|
-
elif unit is not uc.one or rand.randint(2):
|
|
205
|
-
v = uc.gummy(0,unit=unit)
|
|
88
|
+
x = 20.0*(2*rand.rand() - 1)
|
|
89
|
+
else:
|
|
90
|
+
if rand.randint(10) == 0:
|
|
91
|
+
x = rand.randint(-60000,60000)
|
|
206
92
|
else:
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
93
|
+
x = (2*rand.rand() - 1)*10.0**rand.randint(-10,10)
|
|
94
|
+
if rand.randint(20) == 0:
|
|
95
|
+
x = 0
|
|
96
|
+
|
|
97
|
+
if uunit in ['%','ppm','ppb','ms/s'] and not (unit == '%' and uunit == '%'):
|
|
98
|
+
U = 1.0e3*rand.rand()
|
|
99
|
+
u = abs(x)*U/uunits[uunit]
|
|
100
|
+
elif unit == 'm' and uunit == 'mm':
|
|
101
|
+
if x == 0:
|
|
102
|
+
U = 1.0e3*rand.rand()
|
|
214
103
|
else:
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
104
|
+
U = abs(x)*1.0e3*rand.rand()
|
|
105
|
+
u = U/1000
|
|
106
|
+
elif unit == 'm' and uunit == 'in':
|
|
107
|
+
if x == 0:
|
|
108
|
+
U = 100*rand.rand()
|
|
219
109
|
else:
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
110
|
+
U = abs(x)*100*rand.rand()
|
|
111
|
+
u = U*0.0254
|
|
112
|
+
else:
|
|
113
|
+
if x == 0:
|
|
114
|
+
U = 1.0e12*rand.rand()
|
|
224
115
|
else:
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
116
|
+
if rand.randint(20) == 0:
|
|
117
|
+
U = 1e6*abs(x)*rand.rand()
|
|
118
|
+
elif rand.randint(20) == 0:
|
|
119
|
+
U = rand.randint(20)+1
|
|
120
|
+
else:
|
|
121
|
+
U = 1.1*abs(x)*rand.rand()
|
|
122
|
+
u = U
|
|
123
|
+
|
|
124
|
+
if rand.randint(2):
|
|
125
|
+
name = chr(rand.randint(20) + 65) + chr(rand.randint(20) + 65) + chr(rand.randint(20) + 65)
|
|
126
|
+
else:
|
|
127
|
+
name = None
|
|
128
|
+
|
|
129
|
+
if rand.randint(2):
|
|
130
|
+
utype = chr(rand.randint(20) + 65) + chr(rand.randint(20) + 65) + chr(rand.randint(20) + 65)
|
|
131
|
+
else:
|
|
132
|
+
utype = None
|
|
133
|
+
|
|
134
|
+
if rand.randint(20) == 0:
|
|
135
|
+
self.assertTrue(uc.gummy(x) == x)
|
|
136
|
+
continue
|
|
137
|
+
|
|
138
|
+
if rand.randint(20) == 0:
|
|
139
|
+
const = True
|
|
140
|
+
U = 0
|
|
141
|
+
u = 0
|
|
142
|
+
else:
|
|
143
|
+
if u == 0:
|
|
144
|
+
const = True
|
|
230
145
|
else:
|
|
231
|
-
|
|
232
|
-
|
|
146
|
+
const = False
|
|
147
|
+
|
|
148
|
+
uc.gummy.bayesian = bayesian
|
|
149
|
+
if uunit is not None and rand.randint(2):
|
|
150
|
+
uu = uc.gummy(U,unit=uunit)
|
|
151
|
+
g = uc.gummy(x,u=uu,unit=unit,dof=dof,k=k,p=p,name=name,
|
|
152
|
+
utype=utype)
|
|
153
|
+
else:
|
|
154
|
+
g = uc.gummy(x,u=U,unit=unit,dof=dof,k=k,p=p,uunit=uunit,
|
|
155
|
+
name=name,utype=utype)
|
|
156
|
+
|
|
157
|
+
if not const:
|
|
158
|
+
u = u/g.k
|
|
159
|
+
|
|
160
|
+
orig_g = g
|
|
161
|
+
|
|
162
|
+
if rand.randint(10) == 0:
|
|
163
|
+
n = rand.randint(12)
|
|
164
|
+
if bayesian and n > 0:
|
|
165
|
+
dof = float('inf')
|
|
166
|
+
if n == 0:
|
|
167
|
+
nm = g.name
|
|
168
|
+
g = uc.gummy(g)
|
|
169
|
+
self.assertTrue(g.name is nm)
|
|
170
|
+
g.name = None
|
|
171
|
+
elif n == 1:
|
|
172
|
+
if unit == 'degF':
|
|
173
|
+
g = g + uc.gummy(0,unit='degF-i')
|
|
174
|
+
else:
|
|
175
|
+
g = 1*g
|
|
176
|
+
elif n == 2:
|
|
177
|
+
if unit == 'degF':
|
|
178
|
+
g = g + uc.gummy(0,unit='degF-i')
|
|
179
|
+
else:
|
|
180
|
+
g = g*1
|
|
181
|
+
elif n == 3:
|
|
182
|
+
if unit == 'degF':
|
|
183
|
+
g = g + uc.gummy(0,unit='degF-i')
|
|
233
184
|
else:
|
|
234
|
-
|
|
235
|
-
|
|
185
|
+
g = g/1
|
|
186
|
+
elif n == 4:
|
|
187
|
+
if unit == 'degF':
|
|
188
|
+
v = uc.gummy(0,unit='degF-i')
|
|
189
|
+
elif unit is not uc.one or rand.randint(2):
|
|
190
|
+
v = uc.gummy(0,unit=unit)
|
|
191
|
+
else:
|
|
192
|
+
v = 0
|
|
193
|
+
g = g + v
|
|
194
|
+
elif n == 5:
|
|
195
|
+
if unit == 'degF':
|
|
196
|
+
v = uc.gummy(0,unit='degF-i')
|
|
197
|
+
elif unit is not uc.one or rand.randint(2):
|
|
198
|
+
v = uc.gummy(0,unit=unit)
|
|
199
|
+
else:
|
|
200
|
+
v = 0
|
|
201
|
+
g = v + g
|
|
202
|
+
elif n == 6:
|
|
203
|
+
if unit == 'degF':
|
|
204
|
+
v = uc.gummy(0,unit='degF-i')
|
|
205
|
+
elif unit is not uc.one or rand.randint(2):
|
|
206
|
+
v = uc.gummy(0,unit=unit)
|
|
207
|
+
else:
|
|
208
|
+
v = 0
|
|
236
209
|
g = g - v
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
210
|
+
elif n == 7:
|
|
211
|
+
if unit == 'degF':
|
|
212
|
+
g = g + uc.gummy(0,unit='degF-i')
|
|
213
|
+
elif unit in ['dB(SPL)','Np']:
|
|
214
|
+
g = g + uc.gummy(0,unit=unit)
|
|
215
|
+
else:
|
|
216
|
+
g = g**1
|
|
217
|
+
elif n == 8:
|
|
218
|
+
if unit == 'degF':
|
|
219
|
+
g = g + uc.gummy(0,unit='degF-i')
|
|
220
|
+
else:
|
|
221
|
+
g = +g
|
|
222
|
+
elif n == 9:
|
|
223
|
+
if unit == 'degF':
|
|
224
|
+
g = g + uc.gummy(0,unit='degF-i')
|
|
225
|
+
else:
|
|
226
|
+
g = 2.1*g
|
|
227
|
+
g = g/2.1
|
|
228
|
+
elif n == 10:
|
|
229
|
+
if unit == 'degF':
|
|
230
|
+
g = g + uc.gummy(0,unit='degF-i')
|
|
231
|
+
else:
|
|
232
|
+
if unit is not uc.one or rand.randint(2):
|
|
233
|
+
v = uc.gummy(3.5*x,u=0.45*u,unit=unit)
|
|
234
|
+
else:
|
|
235
|
+
v = 3.3*x
|
|
236
|
+
g = v - g
|
|
237
|
+
g = g - v
|
|
238
|
+
g = -g
|
|
241
239
|
else:
|
|
242
|
-
if
|
|
243
|
-
g =
|
|
240
|
+
if unit == 'degF':
|
|
241
|
+
g = g + uc.gummy(0,unit='degF-i')
|
|
244
242
|
else:
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
243
|
+
if x >= 0:
|
|
244
|
+
g = abs(g)
|
|
245
|
+
else:
|
|
246
|
+
g = -abs(g)
|
|
247
|
+
|
|
248
|
+
k = 1
|
|
249
|
+
p = None
|
|
250
|
+
reinit = True
|
|
251
|
+
uunit = None
|
|
252
|
+
name = None
|
|
253
|
+
else:
|
|
254
|
+
reinit = False
|
|
255
|
+
|
|
256
|
+
if x != 0 and g.x != 0:
|
|
257
|
+
self.assertTrue(abs(g.x - x)/abs(x) < 1e-10)
|
|
258
|
+
else:
|
|
259
|
+
self.assertTrue(abs(g.x - x) < 1e-10)
|
|
260
|
+
|
|
261
|
+
if x != 0 and g.x != 0:
|
|
262
|
+
self.assertTrue(abs(g.x - x)/abs(x) < 1e-10)
|
|
263
|
+
else:
|
|
264
|
+
self.assertTrue(abs(g.x - x) < 1e-10)
|
|
265
|
+
|
|
266
|
+
if unit == 'degF':
|
|
267
|
+
self.assertTrue(g.unit in [uc.Unit.unit('degF'),uc.Unit.unit('degF-i')])
|
|
268
|
+
else:
|
|
269
|
+
self.assertTrue(g.unit is uc.Unit.unit(unit))
|
|
270
|
+
self.assertTrue(g.name == name)
|
|
259
271
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
assert abs(g - x) < 1e-10
|
|
276
|
-
else:
|
|
277
|
-
assert abs(g - x)/x < 1e-10
|
|
278
|
-
elif unit == '%':
|
|
279
|
-
if x == 0:
|
|
280
|
-
assert abs(g - x/100) < 1e-10
|
|
281
|
-
else:
|
|
282
|
-
assert abs((g - x/100)/(x/100)) < 1e-10
|
|
283
|
-
elif unit == 'Np':
|
|
284
|
-
assert abs(g.convert(1) - np.exp(x))/np.exp(x) < 1e-10
|
|
285
|
-
continue
|
|
286
|
-
|
|
287
|
-
if uunit in ['%','ppm','ppb','dB','ms/s'] and unit != uunit:
|
|
288
|
-
assert g.uunit_is_rel
|
|
289
|
-
else:
|
|
290
|
-
assert not g.uunit_is_rel
|
|
272
|
+
if const:
|
|
273
|
+
self.assertTrue(g.u == 0)
|
|
274
|
+
if unit is uc.one:
|
|
275
|
+
if x == 0:
|
|
276
|
+
self.assertTrue(abs(g - x) < 1e-10)
|
|
277
|
+
else:
|
|
278
|
+
self.assertTrue(abs(g - x)/x < 1e-10)
|
|
279
|
+
elif unit == '%':
|
|
280
|
+
if x == 0:
|
|
281
|
+
self.assertTrue(abs(g - x/100) < 1e-10)
|
|
282
|
+
else:
|
|
283
|
+
self.assertTrue(abs((g - x/100)/(x/100)) < 1e-10)
|
|
284
|
+
elif unit == 'Np':
|
|
285
|
+
self.assertTrue(abs(g.convert(1) - np.exp(x))/np.exp(x) < 1e-10)
|
|
286
|
+
continue
|
|
291
287
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
if uunit is not None and uunit != unit:
|
|
300
|
-
assert g.uunit is uc.Unit.unit(uunit)
|
|
288
|
+
if uunit in ['%','ppm','ppb','dB','ms/s'] and unit != uunit:
|
|
289
|
+
self.assertTrue(g.uunit_is_rel)
|
|
290
|
+
else:
|
|
291
|
+
self.assertTrue(not g.uunit_is_rel)
|
|
292
|
+
|
|
293
|
+
self.assertTrue((g.x - x)/u < 1e-6)
|
|
301
294
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
assert k <= 3
|
|
305
|
-
else:
|
|
306
|
-
if p is None:
|
|
307
|
-
assert g.k == k
|
|
295
|
+
if dof == float('inf'):
|
|
296
|
+
self.assertTrue(g.dof == float('inf'))
|
|
308
297
|
else:
|
|
309
|
-
|
|
298
|
+
self.assertTrue((g.dof - dof)/dof < 1e-6)
|
|
310
299
|
|
|
311
|
-
if
|
|
312
|
-
|
|
313
|
-
|
|
300
|
+
if uunit is not None and uunit != unit:
|
|
301
|
+
self.assertTrue(g.uunit is uc.Unit.unit(uunit))
|
|
302
|
+
|
|
303
|
+
if g.p == 0:
|
|
304
|
+
self.assertTrue(p is None)
|
|
305
|
+
self.assertTrue(k <= 3)
|
|
306
|
+
else:
|
|
307
|
+
if p is None:
|
|
308
|
+
self.assertTrue(g.k == k)
|
|
314
309
|
else:
|
|
315
|
-
|
|
310
|
+
self.assertTrue(g.p == p)
|
|
311
|
+
|
|
312
|
+
if uc.gummy.p_method in ['loc','level of confidence',None]:
|
|
313
|
+
if dof == float('inf'):
|
|
314
|
+
self.assertTrue(abs(g.k - norm.ppf(0.5 + g.p/2)) < 1e-6)
|
|
315
|
+
else:
|
|
316
|
+
if bayesian:
|
|
317
|
+
if g.p is not None:
|
|
318
|
+
self.assertTrue(abs(g.k - np.sqrt((dof-2)/dof)*t.ppf(0.5 + g.p/2,dof)) < 1e-6)
|
|
319
|
+
else:
|
|
320
|
+
self.assertTrue(abs(g.k - t.ppf(0.5 + g.p/2,dof)) < 1e-6)
|
|
321
|
+
|
|
322
|
+
elif uc.gummy.p_method in ['cp','coverage probability','gauss']:
|
|
323
|
+
if dof == float('inf') or bayesian:
|
|
316
324
|
if g.p is not None:
|
|
317
|
-
|
|
325
|
+
self.assertTrue(abs(g.k - 2/(3*(np.sqrt(1 - g.p)))) < 1e-6)
|
|
318
326
|
else:
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
elif uc.gummy.p_method in ['cp','coverage probability','gauss']:
|
|
322
|
-
if dof == float('inf') or bayesian:
|
|
323
|
-
if g.p is not None:
|
|
324
|
-
assert abs(g.k - 2/(3*(np.sqrt(1 - g.p)))) < 1e-6
|
|
325
|
-
else:
|
|
326
|
-
if g.p is not None:
|
|
327
|
-
assert abs(g.k - np.sqrt(dof/(dof-2))*(2/(3*(np.sqrt(1 - g.p))))) < 1e-6
|
|
328
|
-
else:
|
|
329
|
-
if dof == float('inf') or bayesian:
|
|
330
|
-
if g.p is not None:
|
|
331
|
-
assert abs(g.k - 1/np.sqrt(1 - g.p)) < 10.0**-6
|
|
327
|
+
if g.p is not None:
|
|
328
|
+
self.assertTrue(abs(g.k - np.sqrt(dof/(dof-2))*(2/(3*(np.sqrt(1 - g.p))))) < 1e-6)
|
|
332
329
|
else:
|
|
333
|
-
if
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
g.
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
330
|
+
if dof == float('inf') or bayesian:
|
|
331
|
+
if g.p is not None:
|
|
332
|
+
self.assertTrue(abs(g.k - 1/np.sqrt(1 - g.p)) < 10.0**-6)
|
|
333
|
+
else:
|
|
334
|
+
if g.p is not None:
|
|
335
|
+
self.assertTrue(abs(g.k - np.sqrt(dof/(dof-2))*(1/np.sqrt(1 - g.p))) < 1e-6)
|
|
336
|
+
|
|
337
|
+
self.assertTrue(abs((g.u - u)/u) < 1e-10)
|
|
338
|
+
|
|
339
|
+
if not reinit:
|
|
340
|
+
self.assertTrue(abs(g.U - U)/U < 1e-10)
|
|
341
|
+
|
|
342
|
+
self.assertTrue(abs((g.u - u)/u) < 1e-10)
|
|
343
|
+
|
|
344
|
+
self.assertTrue('?' not in g.tostring())
|
|
345
|
+
|
|
346
|
+
if prnt:
|
|
347
|
+
print('------')
|
|
348
|
+
print()
|
|
349
|
+
if rand.randint(2):
|
|
350
|
+
styles = ['pm','pmi','concise','ueq','x','xf','u','uf','xunit','uunit']
|
|
351
|
+
g.style = styles[rand.randint(10)]
|
|
352
|
+
|
|
353
|
+
g.show_k = bool(rand.randint(2))
|
|
354
|
+
g.show_dof = bool(rand.randint(2))
|
|
355
|
+
g.show_p = bool(rand.randint(2))
|
|
356
|
+
g.show_name = bool(rand.randint(2))
|
|
357
|
+
g.solidus = bool(rand.randint(2))
|
|
358
|
+
g.mulsep = bool(rand.randint(2))
|
|
359
|
+
if not rand.randint(5):
|
|
360
|
+
g.nsig = rand.randint(5) + 1
|
|
361
|
+
|
|
362
|
+
self.assertTrue('?' not in g.tostring())
|
|
363
|
+
print(g.style,', show_k=',g.show_k,', show_dof=',g.show_dof,', show_p=',g.show_p,', show_name=',g.show_name,', solidus=',g.solidus,', mulsep=',g.mulsep,', nsig=',g.nsig,':')
|
|
364
|
+
print()
|
|
365
|
+
display(g)
|
|
366
|
+
print()
|
|
367
|
+
|
|
368
|
+
if plot:
|
|
369
|
+
print('------')
|
|
370
|
+
print()
|
|
371
|
+
print(g)
|
|
372
|
+
g.sim()
|
|
373
|
+
if rand.randint(2):
|
|
374
|
+
styles = ['pmsim','pmsimi','mcisim','cisim','usim','ufsim']
|
|
375
|
+
g.style = styles[rand.randint(6)]
|
|
376
|
+
g.slashaxis = bool(rand.randint(2))
|
|
377
|
+
print(g.style,', slashaxis=',g.slashaxis,':')
|
|
378
|
+
print()
|
|
379
|
+
display(g)
|
|
380
|
+
print()
|
|
381
|
+
g.hist()
|
|
363
382
|
print()
|
|
364
|
-
display(g)
|
|
365
|
-
print()
|
|
366
383
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
g.sim()
|
|
372
|
-
if rand.randint(2):
|
|
373
|
-
styles = ['pmsim','pmsimi','mcisim','cisim','usim','ufsim']
|
|
374
|
-
g.style = styles[rand.randint(6)]
|
|
375
|
-
g.slashaxis = bool(rand.randint(2))
|
|
376
|
-
print(g.style,', slashaxis=',g.slashaxis,':')
|
|
377
|
-
print()
|
|
378
|
-
display(g)
|
|
379
|
-
print()
|
|
380
|
-
g.hist()
|
|
381
|
-
print()
|
|
382
|
-
|
|
383
|
-
uc.gummy.bayesian = False
|
|
384
|
-
finally:
|
|
385
|
-
uc.gummy.p_method = 'loc'
|
|
384
|
+
uc.gummy.bayesian = False
|
|
385
|
+
finally:
|
|
386
|
+
uc.gummy.p_method = 'loc'
|
|
387
|
+
|
|
386
388
|
|
|
389
|
+
if __name__ == '__main__':
|
|
390
|
+
unittest.main()
|