Exemplo n.º 1
0
    def test_constructor_withDynamicDeletionInterfaceAndDuplicatedIntervalsInData_shouldRemoveDuplicatesAndCreateTree(self):
        intervals = list()
        for i in range(500):
            for _ in range(10):
                intervals.append(Interval(i, i))

        tree = DynamicDeletion(SegmentTree, intervals)
        self.assertEqual(500, len(tree))
        self.assertEqual(set(intervals), tree.all())
Exemplo n.º 2
0
    def test_delete_withIntervalNotInTreeAndDynamicDeletionInterface_shouldNotAlterTree(self):
        intervals = set()
        for i in range(500):
            intervals.add(Interval(i, i))
        tree = DynamicDeletion(SegmentTree, intervals)

        for i in range(500, 1000):
            tree.delete(Interval(i, i))
            self.assertEqual(500, len(tree))
            self.assertEqual(intervals, tree.all())
Exemplo n.º 3
0
    def test_delete_withIntervalInTreeAndDynamicDeletionInterface_shouldDeleteIntervalFromTree(self):
        intervals = set()
        for i in range(1, 500):
            intervals.add(Interval(i, i))
        tree = DynamicDeletion(SegmentTree, intervals)

        for i in range(1, 500):
            tree.delete(Interval(i, i))
            intervals.remove(Interval(i, i))
            self.assertEqual(499 - i, len(tree))
            self.assertEqual(intervals, tree.all())
Exemplo n.º 4
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_constructor_withDynamicDeletionInterfaceAndNoneTypeArgumentData_shouldRaiseValueError(
         self):
     with self.assertRaises(ValueError):
         DynamicDeletion(IntervalTree, None)
 def test_constructor_withDynamicDeletionInterfaceAndEmptyData_shouldCreateEmptyTree(
         self):
     tree = DynamicDeletion(IntervalTree, [])
     self.assertEqual(0, len(tree))
 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)
Exemplo n.º 9
0
 def test_delete_withNoneTypeArgumentAndDynamicDeletionInterface_shouldRaiseValueError(self):
     tree = DynamicDeletion(SegmentTree, [])
     with self.assertRaises(ValueError):
         tree.delete(None)