示例#1
0
 def create_simple_tree(self):
     node = QuadNode(Point(0, 0), 20, 20)
     node.insert(Point(7, 5, data="dog"))
     node.insert(Point(6, 4, data="cat"))
     node.insert(Point(-1, -2, data=True))
     node.insert(Point(9, -9, data={"hello": "world"}))
     node.insert(Point(8, 8, data=("a", "b", "c")))
     node.insert(Point(-3, 2, data=False))
     return node
示例#2
0
 def test_insert_ll(self):
     # Without this, a lower-left insert fails to be seen on coverage,
     # which is weird. Ensure that happens & things look right.
     node = QuadNode(Point(0, 0), 20, 20)
     node.ul = QuadNode(Point(-5, 5), 10, 10)
     node.ur = QuadNode(Point(5, 5), 10, 10)
     node.ll = QuadNode(Point(-5, -5), 10, 10)
     node.lr = QuadNode(Point(5, -5), 10, 10)
     node.insert(Point(-7, -5))
     self.assertTrue(Point(-7, -5) in node)
     self.assertTrue(Point(-7, -5) in node.ll)
示例#3
0
    def test_insert(self):
        node = QuadNode(Point(0, 0), 20, 20)
        node.insert(Point(7, 5))
        node.insert(Point(6, 4))
        node.insert(Point(-1, -2))
        node.insert(Point(9, -9))

        # No subdivision yet.
        self.assertEqual(len(node.points), 4)
        self.assertIsNone(node.ul)
        self.assertIsNone(node.ur)
        self.assertIsNone(node.ll)
        self.assertIsNone(node.lr)

        # Over the edge, automatically subdivide before the insert happens.
        node.insert(Point(8, 8))
        self.assertEqual(len(node.points), 0)
        self.assertIsNotNone(node.ul)
        self.assertEqual(len(node.ul.points), 0)
        self.assertIsNotNone(node.ur)
        self.assertEqual(len(node.ur.points), 3)
        self.assertIsNotNone(node.ll)
        self.assertEqual(len(node.ll.points), 1)
        self.assertIsNotNone(node.lr)
        self.assertEqual(len(node.lr.points), 1)
示例#4
0
    def test_insert_fail(self):
        node = QuadNode(Point(0, 0), 20, 20)

        with self.assertRaises(ValueError):
            node.insert(Point(17, 55))