CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
test_codata.py79 linesDownload Raw Back to tests
1from scipy.constants import find, value, c, speed_of_light, precision
2from numpy.testing import assert_equal, assert_, assert_almost_equal
3import scipy.constants._codata as _cd
4from scipy import constants
5
6
7def test_find():
8    keys = find('weak mixing', disp=False)
9    assert_equal(keys, ['weak mixing angle'])
10
11    keys = find('qwertyuiop', disp=False)
12    assert_equal(keys, [])
13
14    keys = find('natural unit', disp=False)
15    assert_equal(keys, sorted(['natural unit of velocity',
16                                'natural unit of action',
17                                'natural unit of action in eV s',
18                                'natural unit of mass',
19                                'natural unit of energy',
20                                'natural unit of energy in MeV',
21                                'natural unit of momentum',
22                                'natural unit of momentum in MeV/c',
23                                'natural unit of length',
24                                'natural unit of time']))
25
26
27def test_basic_table_parse():
28    c_s = 'speed of light in vacuum'
29    assert_equal(value(c_s), c)
30    assert_equal(value(c_s), speed_of_light)
31
32
33def test_basic_lookup():
34    assert_equal('%d %s' % (_cd.value('speed of light in vacuum'),
35                            _cd.unit('speed of light in vacuum')),
36                 '299792458 m s^-1')
37
38
39def test_find_all():
40    assert_(len(find(disp=False)) > 300)
41
42
43def test_find_single():
44    assert_equal(find('Wien freq', disp=False)[0],
45                 'Wien frequency displacement law constant')
46
47
48def test_2002_vs_2006():
49    assert_almost_equal(value('magn. flux quantum'),
50                        value('mag. flux quantum'))
51
52
53def test_exact_values():
54    # Check that updating stored values with exact ones worked.
55    exact = dict((k, v[0]) for k, v in _cd._physical_constants_2018.items())
56    replace = _cd.exact2018(exact)
57    for key, val in replace.items():
58        assert_equal(val, value(key))
59        assert precision(key) == 0
60
61
62def test_gh11341():
63    # gh-11341 noted that these three constants should exist (for backward
64    # compatibility) and should always have the same value:
65    a = constants.epsilon_0
66    b = constants.physical_constants['electric constant'][0]
67    c = constants.physical_constants['vacuum electric permittivity'][0]
68    assert a == b == c
69
70
71def test_gh14467():
72    # gh-14467 noted that some physical constants in CODATA are rounded
73    # to only ten significant figures even though they are supposed to be
74    # exact. Check that (at least) the case mentioned in the issue is resolved.
75    res = constants.physical_constants['Boltzmann constant in eV/K'][0]
76    ref = (constants.physical_constants['Boltzmann constant'][0]
77           / constants.physical_constants['elementary charge'][0])
78    assert res == ref
79 
Aluode/PerceptionLabPortable · CoolFace