forked from openhistogram/libcircllhist
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
34 lines (29 loc) · 1.01 KB
/
test.py
File metadata and controls
34 lines (29 loc) · 1.01 KB
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
"Test for circllhist"
import unittest
from circllhist import Circllhist, Circllbin
class TestHistogram(unittest.TestCase):
def test_hist(self):
h = Circllhist()
h.insert(123,3)
h.insert_intscale(1,1)
self.assertEqual(h.count(), 4)
self.assertEqual(h.bin_count(), 2)
self.assertAlmostEqual(h.sum(), 384.87619047)
self.assertAlmostEqual(h.mean(), 96.2190476)
self.assertAlmostEqual(h.quantile(0.5), 122.5, 1)
self.assertTrue(str(h))
g = Circllhist.from_dict(h.to_dict())
self.assertEqual(h.sum(), g.sum())
h.merge(g)
print(h.to_b64())
f = Circllhist.from_b64(h.to_b64())
self.assertEqual(h.sum(), f.sum())
h.clear()
self.assertEqual(h.count(), 0)
def test_bin(self):
b = Circllbin.from_number(123.3)
self.assertEqual(b.width,10)
self.assertEqual(b.midpoint,124.8)
self.assertEqual(b.edge,120)
if __name__ == '__main__':
unittest.main(verbosity=2)