-
Notifications
You must be signed in to change notification settings - Fork 54
/
test_hyper.py
74 lines (55 loc) 路 2.24 KB
/
test_hyper.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# --------------------------------------------------------------------------- #
# test_hyper.py #
# #
# Copyright 漏 2015-2020, Rajiv Bakulesh Shah, original author. #
# All rights reserved. #
# --------------------------------------------------------------------------- #
from pottery import HyperLogLog
from tests.base import TestCase
class HyperLogLogTests(TestCase):
_KEY = '{}hll'.format(TestCase._TEST_KEY_PREFIX)
def test_init_without_iterable(self):
hll = HyperLogLog()
assert len(hll) == 0
def test_init_with_iterable(self):
hll = HyperLogLog({'foo', 'bar', 'zap', 'a'})
assert len(hll) == 4
def test_add(self):
hll = HyperLogLog()
hll.add('foo')
assert len(hll) == 1
hll.add('bar')
assert len(hll) == 2
hll.add('zap')
assert len(hll) == 3
hll.add('a')
assert len(hll) == 4
hll.add('a')
assert len(hll) == 4
hll.add('b')
assert len(hll) == 5
hll.add('c')
assert len(hll) == 6
hll.add('foo')
assert len(hll) == 6
def test_update(self):
hll1 = HyperLogLog({'foo', 'bar', 'zap', 'a'})
hll2 = HyperLogLog({'a', 'b', 'c', 'foo'})
hll1.update(hll2)
assert len(hll1) == 6
hll1 = HyperLogLog({'foo', 'bar', 'zap', 'a'})
hll1.update({'b', 'c', 'd', 'foo'})
assert len(hll1) == 7
hll1 = HyperLogLog({'foo', 'bar', 'zap', 'a'})
hll1.update(hll2, {'b', 'c', 'd', 'baz'})
assert len(hll1) == 8
def test_union(self):
hll1 = HyperLogLog({'foo', 'bar', 'zap', 'a'})
hll2 = HyperLogLog({'a', 'b', 'c', 'foo'})
assert len(hll1.union(hll2)) == 6
assert len(hll1.union({'b', 'c', 'd', 'foo'})) == 7
assert len(hll1.union(hll2, {'b', 'c', 'd', 'baz'})) == 8
def test_repr(self):
'Test HyperLogLog.__repr__()'
hll = HyperLogLog({'foo', 'bar', 'zap', 'a'}, key=self._KEY)
assert repr(hll) == '<HyperLogLog key={} len=4>'.format(self._KEY)