Пример #1
0
 def test_known_boxes(self):
     self.known_boxes(CLRTree(max_entries=2))
     self.known_boxes(CLRTree())
     self.known_boxes(CQRTree(max_entries=2))
     self.known_boxes(CQRTree())
     self.known_points(CERTree(max_entries=2))
     self.known_points(CERTree())
Пример #2
0
 def new_tree():
     tree = CQRTree(max_entries=size)
     for i in range(4):
         for j in range(4):
             tree.add([(i, j)], i + j)
     assert len(tree) == 16
     return tree
Пример #3
0
    def test_docs(self):
        tree = CQRTree()
        square = ((0, 0), (0, 1), (1, 1), (1, 0))
        tree[square] = 'square'
        self.assertEqual(list(tree[square]), ['square'])
        self.assertTrue(square in tree)
        diagonal = ((0, 0), (1, 1))
        self.assertEqual(list(tree[diagonal]), [])
        self.assertFalse(diagonal in tree)
        self.assertEqual(list(tree.keys()), [((0, 0), (0, 1), (1, 1), (1, 0))])
        self.assertEqual(list(tree.values()), ['square'])
        self.assertEqual(list(tree.items()),
                         [(((0, 0), (0, 1), (1, 1), (1, 0)), 'square')])
        self.assertEqual(len(tree), 1)
        del tree[square]
        self.assertEqual(len(tree), 0)

        tree = CQRTree(default_match=MatchType.OVERLAP)
        tree[square] = 'square'
        self.assertEqual(list(tree[diagonal]), ['square'])

        tree = CQRTree(default_match=MatchType.OVERLAP)
        tree[square] = 'square'
        self.assertEqual(list(tree.get_items(diagonal)),
                         [(((0, 0), (0, 1), (1, 1), (1, 0)), 'square')])
Пример #4
0
 def test_canary(self):
     tree = CQRTree()
     for i in range(5):
         tree.add([(i, i)], i)
     keys = tree.keys()
     next(keys)
     del tree[[(1, 1)]]
     with self.assertRaisesRegex(RuntimeError, 'mutated'):
         next(keys)
Пример #5
0
    def test_python(self):

        # for other-projects.md
        from ch2.arty import CQRTree, MatchType

        tree = self.run_python(CQRTree())
        self.assertEqual(list(tree[[(0, 0)]]), ['alice'])

        self.run_python(CQRTree(default_match=MatchType.OVERLAP, default_border=3))
Пример #6
0
 def test_equals(self, ):
     for size in 2, 3, 4, 8:
         tree1 = CQRTree(max_entries=size)
         for i, box in self.gen_random(10):
             tree1.add(box, i)
         tree2 = CQRTree(max_entries=size)
         for k, v in tree1.items():
             tree2.add(k, v)
         self.assertEqual(tree1, tree2)
Пример #7
0
 def test_best_bug(self):
     seed(4)  # 1:46 2:17 3:56 4:8 5:10 6:16 7:58 8:8
     self.best_bug(CLRTree(max_entries=2))
     self.best_bug(CQRTree(max_entries=2))
     self.best_bug(CERTree(max_entries=2))
Пример #8
0
    def test_underscores(self):

        for size in 2, 3, 4, 8:
            seed(size)
            tree1 = CQRTree(max_entries=size)
            for i, box in self.gen_random(10):
                tree1[box] = i
            tree2 = CQRTree(max_entries=size)
            for k, v in tree1.items():
                tree2.add(k, v)
            self.assertEqual(tree1, tree2)
            if size == 2:
                self.assertEqual(
                    str(tree1),
                    'Quadratic RTree (10 leaves, 4 height, 1-2 entries)')
            tree3 = CQRTree(tree1.items(), max_entries=size)
            self.assertEqual(tree1, tree3)

        tree = CQRTree()
        tree.add([(1, 1)], '1')
        tree.add([(2, 2)], '2')
        self.assertEqual(len(tree), 2)
        self.assertTrue([(1, 1)] in tree)
        self.assertFalse([(3, 3)] in tree)
        self.assertTrue('1' in list(tree.values()))
        self.assertTrue(((1, 1), ) in list(tree.keys()), list(tree.keys()))
        self.assertTrue((((1, 1), ), '1') in list(tree.items()))
        del tree[[(1, 1)]]
        self.assertEqual(len(tree), 1)
        self.assertTrue(list(tree[[(2, 2)]]))
        self.assertTrue(list(tree.get([(2, 2)])))
        self.assertTrue(list(tree.get([(2, 2)], value='2')))
        self.assertFalse(list(tree.get([(2, 2)], value='1')))
        self.assertTrue(tree)
        del tree[[(2, 2)]]
        self.assertFalse(tree)