def test_insert_items(): tree1 = RBush(4) for i in range(len(data_array)): tree1.insert(*data_array[i]) tree2 = RBush(4) tree2.load(data_array) items1, _ = tree1.all() items2, _ = tree2.all() assert 0 <= tree1.height - tree2.height <= 1 assert sorted_equal(items1, items2)
def test_remove_nothing(): # 'remove' does nothing if nothing found tree1 = RBush() tree1.load(data_array) tree2 = RBush() tree2.load(data_array) tree2.remove(13, 13, 13, 13) items1, _ = tree1.all() items2, _ = tree2.all() assert sorted_equal(items1, items2)
def test_merge_trees(): smaller = data_array[:10] tree1 = RBush(4) tree1.load(data_array) tree1.load(smaller) tree2 = RBush(4) tree2.load(smaller) tree2.load(data_array) assert tree1.height == tree2.height items1, _ = tree1.all() items2, _ = tree2.all() assert sorted_equal(items1, items2)
def test_data_load_empty_maxEntries(): tree = RBush(4) tree.load(empty_array) assert tree.height == 2 items, _ = tree.all() assert sorted_equal(empty_array, items)
def test_chain(): tree = RBush() new_data = [7, 13, 21, 17] tree.load(data_array).insert(*new_data).remove(*new_data) items, _ = tree.all() assert sorted_equal(data_array, items)
def test_insert_item(): data = [[0, 0, 0, 0], [1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [1, 1, 2, 2]] data = np.asarray(data) tree = RBush(4) tree.load(data[0:3]) tree.insert(*data[3]) assert tree.height == 1 items, _ = tree.all() assert sorted_equal(items, data[0:4]) tree.insert(*data[4]) assert tree.height == 2 items, _ = tree.all() assert sorted_equal(items, data)
def test_data_insert_empty_maxEntries(): tree = RBush(4) for datum in empty_array: tree.insert(*datum) assert tree.height == 2 items, _ = tree.all() assert sorted_equal(empty_array, items)
def test_split_root_on_merge(): tree = RBush(4) tree.load(data_array) tree.load(data_array) data = np.concatenate([data_array, data_array]) assert tree.height == 4 items, _ = tree.all() assert sorted_equal(data, items)
def test_insert_numpy_vectors(): numitems = 100 import numpy as np xmin = np.random.randint(0, 100, numitems) ymin = np.random.randint(0, 100, numitems) xmax = xmin + np.random.randint(0, 100, numitems) ymax = ymin + np.random.randint(0, 100, numitems) tree = RBush() tree.insert(xmin=xmin, ymin=ymin, xmax=xmax, ymax=ymax) items, _ = tree.all() assert len(items) == numitems
def test_remove_items(): tree = RBush(4) tree.load(data_array) len_ = len(data_array) items_removed = [] items_removed.extend(tree.remove(*data_array[0])) items_removed.extend(tree.remove(*data_array[1])) items_removed.extend(tree.remove(*data_array[2])) items_removed = np.asarray([i[0] for i in items_removed]) items, _ = tree.all() assert sorted_equal(data_array[3:], items) assert sorted_equal(data_array[:3], items_removed)
def test_load(): tree = RBush(4) tree.load(data_array) items, _ = tree.all() assert sorted_equal(data_array, items)