Esempio n. 1
0
    def test_three_nodes(self):
        """Search through a tree with three nodes.

        The nodes are organized as such::

              a
            ┌─┘
            b
            └┐
             c
        """
        tree = IntervalTree()
        node_a = Node(Interval(3, 3))
        node_b = Node(Interval(1, 1))
        node_c = Node(Interval(2, 2))
        tree.insert(node_a)
        tree.insert(node_b)
        node_b.right = node_c  # force tree to take desired shape
        node_c.parent = node_b
        with self.subTest(comment='pass nothing'):
            self.assertEqual(tree.min(), node_b)
        with self.subTest(comment='pass node_a'):
            self.assertEqual(tree.min(node_a), node_b)
        with self.subTest(comment='pass node_b'):
            self.assertEqual(tree.min(node_b), node_b)
        with self.subTest(comment='pass node_c'):
            self.assertEqual(tree.min(node_c), node_c)
Esempio n. 2
0
    def test_three_nodes(self):
        """Search through a tree with three nodes.

        The nodes are organized as such::

              a
            ┌─┘
            b
            └┐
             c
        """
        tree = IntervalTree()
        node_a = Node(Interval(3, 3))
        node_b = Node(Interval(1, 1))
        node_c = Node(Interval(2, 2))
        tree.insert(node_a)
        tree.insert(node_b)
        node_b.right = node_c  # force tree to take desired shape
        node_c.parent = node_b
        with self.subTest(comment='pass nothing'):
            self.assertEqual(tree.min(), node_b)
        with self.subTest(comment='pass node_a'):
            self.assertEqual(tree.min(node_a), node_b)
        with self.subTest(comment='pass node_b'):
            self.assertEqual(tree.min(node_b), node_b)
        with self.subTest(comment='pass node_c'):
            self.assertEqual(tree.min(node_c), node_c)
Esempio n. 3
0
 def test_one_node(self):
     """Search through a tree with one node."""
     node = Node(Interval(1, 1))
     tree = IntervalTree()
     tree.insert(node)
     with self.subTest(comment='pass nothing'):
         self.assertEqual(tree.min(), node)
     with self.subTest(comment='pass node'):
         self.assertEqual(tree.min(node), node)
Esempio n. 4
0
 def test_one_node(self):
     """Search through a tree with one node."""
     node = Node(Interval(1, 1))
     tree = IntervalTree()
     tree.insert(node)
     with self.subTest(comment='pass nothing'):
         self.assertEqual(tree.min(), node)
     with self.subTest(comment='pass node'):
         self.assertEqual(tree.min(node), node)
Esempio n. 5
0
 def test_no_nodes(self):
     """Search through an empty tree."""
     tree = IntervalTree()
     with self.assertRaises(NoSuchIntervalError):
         tree.min()
Esempio n. 6
0
 def test_no_nodes(self):
     """Search through an empty tree."""
     tree = IntervalTree()
     with self.assertRaises(NoSuchIntervalError):
         tree.min()