|
|
@@ -115,18 +115,88 @@ def test_intervalset_construct(): |
|
|
|
# misc |
|
|
|
assert(repr(iset) == repr(eval(repr(iset).replace("datetime.","")))) |
|
|
|
|
|
|
|
def test_intervalset_intersect(): |
|
|
|
"""Test interval set intersections""" |
|
|
|
dates = [ datetime.strptime(year, "%y") for year in [ "00", "01", "02", "03", "04", "05" ] ] |
|
|
|
|
|
|
|
a = Interval(dates[0], dates[1]) # --- |
|
|
|
b = Interval(dates[0], dates[1]) # --- |
|
|
|
c = Interval(dates[0], dates[1]) # --- |
|
|
|
d = Interval(dates[0], dates[1]) # --- |
|
|
|
e = Interval(dates[0], dates[1]) # --- |
|
|
|
f = Interval(dates[0], dates[1]) # - |
|
|
|
g = Interval(dates[0], dates[1]) # ------- |
|
|
|
|
|
|
|
def iset(string): |
|
|
|
"""Build an IntervalSet from a string, for testing purposes |
|
|
|
|
|
|
|
Each character is a year |
|
|
|
[ = interval start |
|
|
|
| = interval end + adjacent start |
|
|
|
] = interval end |
|
|
|
anything else is ignored |
|
|
|
""" |
|
|
|
iset = IntervalSet() |
|
|
|
for i, c in enumerate(string): |
|
|
|
day = datetime.strptime("{0:04d}".format(i+2000), "%Y") |
|
|
|
if (c == "["): |
|
|
|
start = day |
|
|
|
elif (c == "|"): |
|
|
|
iset += Interval(start, day) |
|
|
|
start = day |
|
|
|
elif (c == "]"): |
|
|
|
iset += Interval(start, day) |
|
|
|
del start |
|
|
|
return iset |
|
|
|
|
|
|
|
def test_intervalset_iset(): |
|
|
|
"""test basic iset construction""" |
|
|
|
assert(iset(" [----] ") == |
|
|
|
iset(" [-|--] ")) |
|
|
|
|
|
|
|
assert(iset("[] [--] ") + |
|
|
|
iset(" [] [--]") == |
|
|
|
iset("[|] [-----]")) |
|
|
|
|
|
|
|
def test_intervalset_intsersect(): |
|
|
|
"""test intersection (&)""" |
|
|
|
assert(iset("[---------]") & |
|
|
|
iset(" [---] ") == |
|
|
|
iset(" [---] ")) |
|
|
|
|
|
|
|
assert(iset(" [-----]") & |
|
|
|
iset(" [-----] ") == |
|
|
|
iset(" [--] ")) |
|
|
|
|
|
|
|
assert(iset(" [---]") & |
|
|
|
iset(" [--] ") == |
|
|
|
iset(" ")) |
|
|
|
|
|
|
|
assert(iset(" [-|---]") & |
|
|
|
iset(" [-----|-] ") == |
|
|
|
iset(" [----] ")) |
|
|
|
|
|
|
|
assert(iset(" [-|-] ") & |
|
|
|
iset(" [-|--|--] ") == |
|
|
|
iset(" [---] ")) |
|
|
|
|
|
|
|
assert(iset(" [----][--]") & |
|
|
|
iset("[-] [--] []") == |
|
|
|
iset(" [] [-] []")) |
|
|
|
|
|
|
|
def test_intervalset_union(): |
|
|
|
"""test union (|)""" |
|
|
|
assert(iset("[---------]") | |
|
|
|
iset(" [---] ") == |
|
|
|
iset("[---------]")) |
|
|
|
|
|
|
|
assert(iset(" [-----]") | |
|
|
|
iset(" [-----] ") == |
|
|
|
iset(" [--------]")) |
|
|
|
|
|
|
|
assert(iset(" [---]") | |
|
|
|
iset(" [--] ") == |
|
|
|
iset(" [--] [---]")) |
|
|
|
|
|
|
|
assert(iset(" [-|---]") | |
|
|
|
iset(" [-----|-] ") == |
|
|
|
iset(" [--------]")) |
|
|
|
|
|
|
|
assert(iset(" [-|-] ") | |
|
|
|
iset(" [-|--|--] ") == |
|
|
|
iset(" [-------] ")) |
|
|
|
|
|
|
|
assert(iset(" [----][--]") | |
|
|
|
iset("[-] [--] []") == |
|
|
|
iset("[---------]")) |
|
|
|
|
|
|
|
# start-other.start start-other.end end-other.start end-other.end |
|
|
|
# --- < < < < n |
|
|
|