-
Notifications
You must be signed in to change notification settings - Fork 0
/
brin_lib_test.py
76 lines (60 loc) · 2.68 KB
/
brin_lib_test.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
75
76
from datetime import datetime
from brin_lib import BlockRange, date_match, fully_within_dates, overlaps_dates
ts = datetime.fromtimestamp
def test_fully_within_dates() -> None:
br = BlockRange(1, ts(10), ts(20))
assert fully_within_dates(br, None, None)
assert fully_within_dates(br, ts(9), None)
assert fully_within_dates(br, None, ts(21))
assert fully_within_dates(br, ts(9), ts(21))
# excluded by single bound, only one value given
assert not fully_within_dates(br, ts(11), None)
assert not fully_within_dates(br, None, ts(19))
# excluded by single bound, both values given
assert not fully_within_dates(br, ts(1), ts(19))
assert not fully_within_dates(br, ts(11), ts(100))
# excluded by both bounds
assert not fully_within_dates(br, ts(11), ts(19))
def test_fully_within_dates_edge() -> None:
br = BlockRange(1, ts(10), ts(20))
assert fully_within_dates(br, ts(10), None)
assert fully_within_dates(br, None, ts(20))
assert fully_within_dates(br, ts(10), ts(20))
# These test cases match test_fully_within_dates.
def test_overlaps_dates() -> None:
br = BlockRange(1, ts(10), ts(20))
# fully within, so naturally also overlaps.
assert overlaps_dates(br, None, None)
assert overlaps_dates(br, ts(9), None)
assert overlaps_dates(br, None, ts(21))
assert overlaps_dates(br, ts(9), ts(21))
# not fully within, but overlapping
assert overlaps_dates(br, ts(11), None)
assert overlaps_dates(br, None, ts(19))
assert overlaps_dates(br, ts(1), ts(19))
assert overlaps_dates(br, ts(11), ts(100))
assert overlaps_dates(br, ts(11), ts(19))
# narrower range also overlaps
assert overlaps_dates(br, ts(15), ts(17))
def test_overlaps_dates_fails() -> None:
br = BlockRange(1, ts(10), ts(20))
assert not overlaps_dates(br, ts(1), ts(5))
assert not overlaps_dates(br, ts(50), ts(100))
assert not overlaps_dates(br, None, ts(5))
assert not overlaps_dates(br, ts(50), None)
def test_overlaps_dates_edge() -> None:
br = BlockRange(1, ts(10), ts(20))
# Same as test_fully_within_dates_edge cases.
assert overlaps_dates(br, ts(10), None)
assert overlaps_dates(br, None, ts(20))
# Also match overlaps.
assert overlaps_dates(br, None, ts(10))
assert overlaps_dates(br, ts(20), None)
def test_date_match() -> None:
br = BlockRange(1, ts(10), ts(20))
assert date_match(br, "overlap", ts(5), ts(15))
assert not date_match(br, "within", ts(5), ts(15))
assert date_match(br, "overlap", ts(1), ts(100))
assert date_match(br, "within", ts(1), ts(100))
assert not date_match(br, "overlap", ts(100), ts(110))
assert not date_match(br, "within", ts(100), ts(110))