예제 #1
0
 def test_union(self):
     s0, s1 = sample(sets, k=2)
     u = s0.union(s1)
     self.assertTrue(s0.is_subset(u))
     self.assertTrue(s1.is_subset(u))
     intervals = list(s0.intervals.union(s1.intervals))
     self.assertEqual(u, TimeSet(intervals))
예제 #2
0
 def test_is_empty(self):
     self.assertTrue(TimeSet([]).is_empty(), "No intervals")
     self.assertTrue(TimeSet([ti.empty]).is_empty(), "Empty interval")
예제 #3
0
 def test_is_subset(self):
     s = choice(sets)
     i = sample(s.intervals, randrange(1, len(s.intervals) + 1))
     self.assertTrue(TimeSet(i).is_subset(s))
예제 #4
0
 def test_empty_union(self):
     e = TimeSet.empty()
     s = choice(sets)
     self.assertEqual(e.union(s), s)
예제 #5
0
 def test_not_empty(self):
     self.assertFalse(TimeSet.from_interval(t[2], t[5]).is_empty())
예제 #6
0
 def test_empty(self):
     self.assertTrue(TimeSet([]).is_empty(), "Set without intervals")
     self.assertTrue(TimeSet.empty().is_empty(), "Empty set")
     self.assertTrue(
         TimeSet([ti.empty, ti.empty]).is_empty(), "Set of empty intervals")
예제 #7
0
 def test_from_interval(self):
     s = make_sets(1, t[0], t[19], 1)[0]
     i, = s.intervals  # Unpacking single element
     s1 = TimeSet.from_interval(i.start, i.end)
     self.assertEqual(s1, s)
예제 #8
0
def make_sets(number: int, start: datetime, end: datetime, max_components=5) -> List[TimeSet]:
    return [
        TimeSet(make_intervals(randrange(1, max_components+1), start, end))
        for _ in range(number)
    ]