|
| 1 | +from timehash import encode, before, after, neighbors, expand |
| 2 | +from time import time |
| 3 | + |
| 4 | + |
| 5 | +rightnow = time() |
| 6 | +# (precision, window size) where window size is in seconds |
| 7 | +precisions = [(8, 240.765380859375), (9, 30), (10, 3.76194)] |
| 8 | +hashes = [encode(rightnow, precision) for (precision, _) in precisions] |
| 9 | + |
| 10 | + |
| 11 | +def test_before(): |
| 12 | + hashes_pre = [encode(rightnow - window_size, precision) |
| 13 | + for (precision, window_size) in precisions] |
| 14 | + hashes_before = [before(hashcode) for hashcode in hashes] |
| 15 | + assert hashes_pre == hashes_before |
| 16 | + |
| 17 | + |
| 18 | +def test_after(): |
| 19 | + hashes_post = [encode(rightnow + window_size, precision) |
| 20 | + for (precision, window_size) in precisions] |
| 21 | + hashes_after = [after(hashcode) for hashcode in hashes] |
| 22 | + assert hashes_post == hashes_after |
| 23 | + |
| 24 | + |
| 25 | +def test_expand(): |
| 26 | + hashes_real = [[encode(rightnow - window_size, precision), |
| 27 | + encode(rightnow, precision), |
| 28 | + encode(rightnow + window_size, precision)] |
| 29 | + for (precision, window_size) in precisions] |
| 30 | + hashes_expanded = [expand(hashcode) for hashcode in hashes] |
| 31 | + assert hashes_real == hashes_expanded |
| 32 | + |
| 33 | + |
| 34 | +def test_neighbors(): |
| 35 | + hashes_real = [[encode(rightnow - window_size, precision), |
| 36 | + encode(rightnow + window_size, precision)] |
| 37 | + for (precision, window_size) in precisions] |
| 38 | + hashes_neighbors = [neighbors(hashcode) for hashcode in hashes] |
| 39 | + assert hashes_real == hashes_neighbors |
0 commit comments