Esempio n. 1
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
Esempio n. 2
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)
Esempio n. 3
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)
Esempio n. 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)