-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathtest_sample.py
39 lines (29 loc) · 1.43 KB
/
test_sample.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
from timehash import encode, before, after, neighbors, expand
from time import time
rightnow = time()
# (precision, window size) where window size is in seconds
precisions = [(8, 240.765380859375), (9, 30), (10, 3.76194)]
hashes = [encode(rightnow, precision) for (precision, _) in precisions]
def test_before():
hashes_pre = [encode(rightnow - window_size, precision)
for (precision, window_size) in precisions]
hashes_before = [before(hashcode) for hashcode in hashes]
assert hashes_pre == hashes_before
def test_after():
hashes_post = [encode(rightnow + window_size, precision)
for (precision, window_size) in precisions]
hashes_after = [after(hashcode) for hashcode in hashes]
assert hashes_post == hashes_after
def test_expand():
hashes_real = [[encode(rightnow - window_size, precision),
encode(rightnow, precision),
encode(rightnow + window_size, precision)]
for (precision, window_size) in precisions]
hashes_expanded = [expand(hashcode) for hashcode in hashes]
assert hashes_real == hashes_expanded
def test_neighbors():
hashes_real = [[encode(rightnow - window_size, precision),
encode(rightnow + window_size, precision)]
for (precision, window_size) in precisions]
hashes_neighbors = [neighbors(hashcode) for hashcode in hashes]
assert hashes_real == hashes_neighbors