def test_merge_index(): x = population.Population(population_name="test", parent="test_parent") y = population.Population(population_name="test", parent="test_parent") x.index = np.array([0, 1, 2, 3, 4, 5, 11, 13]) y.index = np.array([0, 1, 3, 8, 11, 15, 19]) idx = population._merge_index(x, y) assert np.array_equal(idx, np.array([0, 1, 2, 3, 4, 5, 8, 11, 13, 15, 19]))
def test_merge_signatures(): x = population.Population(population_name="test") x.signature = dict(x=10., y=10., z=20.) y = population.Population(population_name="test") y.signature = dict(x=20., y=50., z=5.) sig = population._merge_signatures(x, y) assert sig.get("x") == 15. assert sig.get("y") == 30. assert sig.get("z") == 12.5
def test_check_overlap_error(): poly1, _, poly2 = generate_polygons() x = population.Population(population_name="test", parent="test_parent", geom=poly1) y = population.Population(population_name="test", parent="test_parent", geom=poly2) with pytest.raises(AssertionError) as exp: population._check_overlap(x, y, error=True) assert str(exp.value) == "Invalid: non-overlapping populations"
def test_check_overlap_invalid_shape(): geom = ThresholdGeom() x = population.Population(population_name="test", parent="test_parent", geom=geom) y = population.Population(population_name="test", parent="test_parent", geom=geom) with pytest.raises(AssertionError) as exp: population._check_overlap(x, y, error=True) assert str( exp.value) == "Only Polygon geometries can be checked for overlap"
def create_poly_pops(): poly1, poly2, _ = generate_polygons() left = population.Population(population_name="left", parent="test", geom=poly1, index=np.array([0, 1, 2, 3, 4, 5]), definition="++", signature=dict(x=5, y=5)) right = population.Population(population_name="right", parent="test", geom=poly2, index=np.array([0, 1, 2, 3, 8, 11]), definition="+-", signature=dict(x=15, y=15)) return left, right
def create_threshold_pops(): left = population.Population(population_name="left", parent="test", geom=ThresholdGeom(x_threshold=0.5, y_threshold=1.5), index=np.array([0, 1, 2, 3, 4, 5]), definition="++", signature=dict(x=5, y=5)) right = population.Population(population_name="right", parent="test", geom=ThresholdGeom(x_threshold=0.5, y_threshold=1.5), index=np.array([0, 1, 2, 3, 8, 11]), definition="+-", signature=dict(x=15, y=15)) return left, right
def test_check_overlap(): poly1, poly2, _ = generate_polygons() x = population.Population(population_name="test", parent="test_parent", geom=poly1) y = population.Population(population_name="test", parent="test_parent", geom=poly2) assert population._check_overlap(x, y, error=False) is True poly1, _, poly2 = generate_polygons() x = population.Population(population_name="test", parent="test_parent", geom=poly1) y = population.Population(population_name="test", parent="test_parent", geom=poly2) assert population._check_overlap(x, y, error=False) is False
def test_population_init(): x = population.Population(population_name="test", parent="test_parent") x.index = np.array([0, 1, 2, 3, 4, 5]) assert np.array_equal(np.array([0, 1, 2, 3, 4, 5]), x.index) assert x.n == 6