예제 #1
0
    def test_query_withPointInSomeIntervalsAndDynamicDeletionInterface_shouldReturnSetWithIntervalsThatContainQueryPoint(self):
        intervals = set()
        expected  = set()
        point     = random.uniform(0, 1000)

        for i in range(500):
            a = Interval(i, 1000)
            b = Interval(random.uniform(0, 1000), random.uniform(0, 1000))
            if point in a:
                expected.add(a)
            if point in b:
                expected.add(b)
            intervals.add(a)
            intervals.add(b)

        tree = DynamicDeletion(SegmentTree, intervals)

        self.assertEqual(expected, tree.query(point))

        while len(expected) > 0:
            x = expected.pop()
            tree.delete(x)
            self.assertEqual(expected, tree.query(point))
 def test_query_withEmptyTreeAndDynamicDeletionInterface_shouldReturnEmptySet(
         self):
     tree = DynamicDeletion(IntervalTree, [])
     for _ in range(1000):
         a = random.uniform(0, 1000)
         self.assertEqual(set(), tree.query(a))
 def test_query_withNoneTypeArgumentAndDynamicDeletionInterface_shouldRaiseValueError(
         self):
     tree = DynamicDeletion(IntervalTree, [])
     with self.assertRaises(ValueError):
         tree.query(None)