You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines 1.4 KiB Raw Blame History

 ``````from nilmdb import Interval, IntervalSet, IntervalException from datetime import datetime from nose.tools import assert_raises import itertools def test_interval(): """Test the Interval class""" start = datetime.strptime("19801205","%Y%m%d") end = datetime.strptime("20110216","%Y%m%d") # basic construction i = Interval(start, end) assert(i.start == start) assert(i.end == end) # end before start assert_raises(Exception, Interval, end, start) def test_interval_intersect(): """Test Interval intersections""" dates = [ datetime.strptime(year, "%y") for year in [ "00", "01", "02", "03" ] ] perm = list(itertools.permutations(dates, 2)) prod = list(itertools.product(perm, perm)) should_intersect = { False: [4, 5, 8, 20, 48, 56, 60, 96, 97, 100], True: [0, 1, 2, 12, 13, 14, 16, 17, 24, 25, 26, 28, 29, 32, 49, 50, 52, 53, 61, 62, 64, 65, 68, 98, 101, 104]} for i,((a,b),(c,d)) in enumerate(prod): try: i1 = Interval(a, b) i2 = Interval(c, d) assert(i1.intersects(i2) == i2.intersects(i1)) assert(i in should_intersect[i1.intersects(i2)]) except IntervalException: assert(i not in should_intersect[True] and i not in should_intersect[False]) def test_intervalset(): """Test interval sets""" #iset = IntervalSet("hi") ``````