Exemple #1
0
    def test_query_withEmptyTreeAndDynamicInsertionDeletionInterface_shouldReturnEmptySet(self):
        tree = DynamicInsertionDeletion(SegmentTree)
        for _ in range(500):
            a = random.uniform(0, 1000)
            self.assertEqual(set(), tree.query(a))

        for i in range(500):
            point = random.uniform(0, 1000)
            a = Interval(i, i)
            tree.insert(a)
            tree.delete(a)
            self.assertEqual(set(), tree.query(point))
Exemple #2
0
 def test_query_withPointNotInAnyIntervalAndDynamicInsertionDeletionInterface_shouldReturnEmptySet(self):
     leftmost  = None
     rightmost = None
     tree = DynamicInsertionDeletion(SegmentTree)
     for i in range(500):
         a = Interval(random.uniform(0, i), random.uniform(i, 1000))
         if leftmost is None or a.min < leftmost:
             leftmost = a.min
         if rightmost is None or a.max > rightmost:
             rightmost = a.max
         tree.insert(a)
         self.assertEqual(set(), tree.query(leftmost - 1))
         self.assertEqual(set(), tree.query(rightmost + 1))
Exemple #3
0
    def test_query_withPointInSomeIntervalsAndDynamicInsertionDeletionInterface_shouldReturnSetWithIntervalsThatContainQueryPoint(self):
        expected  = set()
        point     = random.uniform(0, 1000)
        tree      = DynamicInsertionDeletion(SegmentTree)

        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)
            tree.insert(a)
            tree.insert(b)
            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_withNoneTypeArgumentAndDynamicInsertionDeletionInterface_shouldRaiseValueError(
         self):
     tree = DynamicInsertionDeletion(IntervalTree)
     with self.assertRaises(ValueError):
         tree.query(None)