forked from fossasia/pslab-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_analytics.py
50 lines (42 loc) · 1.53 KB
/
test_analytics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import unittest
from PSL import analyticsClass
class TestAnalytics(unittest.TestCase):
def test_frexp10(self):
input_value = 43.0982
expected_result = (4.30982, 1)
self.assertAlmostEqual(analyticsClass.frexp10(input_value), expected_result)
def test_apply_si_prefix_rounding(self):
input_value = {
"value": 7545.230053,
"unit": "J",
}
expected_result = "7.55 kJ"
self.assertEqual(analyticsClass.apply_si_prefix(**input_value), expected_result)
def test_apply_si_prefix_high_precision(self):
input_value = {
"value": -0.000002000008,
"unit": "A",
"precision": 6,
}
expected_result = "-2.000008 µA"
self.assertEqual(analyticsClass.apply_si_prefix(**input_value), expected_result)
def test_apply_si_prefix_low_precision(self):
input_value = {
"value": -1,
"unit": "V",
"precision": 0,
}
expected_result = "-1 V"
self.assertEqual(analyticsClass.apply_si_prefix(**input_value), expected_result)
def test_apply_si_prefix_too_big(self):
input_value = {
"value": 1e27,
"unit": "V",
}
self.assertRaises(ValueError, analyticsClass.apply_si_prefix, **input_value)
def test_apply_si_prefix_too_small(self):
input_value = {
"value": 1e-25,
"unit": "V",
}
self.assertRaises(ValueError, analyticsClass.apply_si_prefix, **input_value)