kopia lustrzana https://github.com/onthegomap/planetiler
tests for hasSameContents
rodzic
dd505aeb33
commit
10db8f1fe1
|
@ -247,9 +247,11 @@ public record FeatureGroup(FeatureSort sorter, Profile profile, CommonStringEnco
|
|||
return false;
|
||||
}
|
||||
for (int i = 0; i < entries.size(); i++) {
|
||||
byte[] a = entries.get(i).value();
|
||||
byte[] b = other.entries.get(i).value();
|
||||
if (!Arrays.equals(a, b)) {
|
||||
FeatureSort.Entry a = entries.get(i);
|
||||
FeatureSort.Entry b = other.entries.get(i);
|
||||
long layerA = extractLayerIdFromSortKey(a.sortKey());
|
||||
long layerB = extractLayerIdFromSortKey(b.sortKey());
|
||||
if (layerA != layerB || !Arrays.equals(a.value(), b.value())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,9 +76,14 @@ public class FeatureGroupTest {
|
|||
|
||||
private void putWithGroupAndZorder(int tile, String layer, Map<String, Object> attrs, Geometry geom, int zOrder,
|
||||
boolean hasGroup, long group, int limit) {
|
||||
putWithIdGroupAndZorder(id++, tile, layer, attrs, geom, zOrder, hasGroup, group, limit);
|
||||
}
|
||||
|
||||
private void putWithIdGroupAndZorder(long id, int tile, String layer, Map<String, Object> attrs, Geometry geom,
|
||||
int zOrder, boolean hasGroup, long group, int limit) {
|
||||
RenderedFeature feature = new RenderedFeature(
|
||||
TileCoord.decode(tile),
|
||||
new VectorTileEncoder.Feature(layer, id++, VectorTileEncoder.encodeGeometry(geom), attrs),
|
||||
new VectorTileEncoder.Feature(layer, id, VectorTileEncoder.encodeGeometry(geom), attrs),
|
||||
zOrder,
|
||||
hasGroup ? Optional.of(new RenderedFeature.Group(group, limit)) : Optional.empty()
|
||||
);
|
||||
|
@ -305,4 +310,70 @@ public class FeatureGroupTest {
|
|||
FeatureGroup.encodeSortKey(tileB, layerB, zOrderB, hasGroupB)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasSameFeatures() {
|
||||
// should be the "same" even though z-order is different
|
||||
putWithIdGroupAndZorder(
|
||||
1, 1, "layer", Map.of("id", 1), newPoint(1, 2), 1, true, 2, 3
|
||||
);
|
||||
putWithIdGroupAndZorder(
|
||||
1, 2, "layer", Map.of("id", 1), newPoint(1, 2), 2, true, 2, 3
|
||||
);
|
||||
sorter.sort();
|
||||
var iter = features.iterator();
|
||||
assertTrue(iter.next().hasSameContents(iter.next()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoesNotHaveSameFeaturesWhenGeometryChanges() {
|
||||
putWithIdGroupAndZorder(
|
||||
1, 1, "layer", Map.of("id", 1), newPoint(1, 2), 1, true, 2, 3
|
||||
);
|
||||
putWithIdGroupAndZorder(
|
||||
1, 2, "layer", Map.of("id", 1), newPoint(1, 3), 1, true, 2, 3
|
||||
);
|
||||
sorter.sort();
|
||||
var iter = features.iterator();
|
||||
assertFalse(iter.next().hasSameContents(iter.next()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoesNotHaveSameFeaturesWhenAttrsChange() {
|
||||
putWithIdGroupAndZorder(
|
||||
1, 1, "layer", Map.of("id", 1), newPoint(1, 2), 1, true, 2, 3
|
||||
);
|
||||
putWithIdGroupAndZorder(
|
||||
1, 2, "layer", Map.of("id", 2), newPoint(1, 2), 1, true, 2, 3
|
||||
);
|
||||
sorter.sort();
|
||||
var iter = features.iterator();
|
||||
assertFalse(iter.next().hasSameContents(iter.next()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoesNotHaveSameFeaturesWhenLayerChanges() {
|
||||
putWithIdGroupAndZorder(
|
||||
1, 1, "layer", Map.of("id", 1), newPoint(1, 2), 1, true, 2, 3
|
||||
);
|
||||
putWithIdGroupAndZorder(
|
||||
1, 2, "layer2", Map.of("id", 1), newPoint(1, 2), 1, true, 2, 3
|
||||
);
|
||||
sorter.sort();
|
||||
var iter = features.iterator();
|
||||
assertFalse(iter.next().hasSameContents(iter.next()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoesNotHaveSameFeaturesWhenIdChanges() {
|
||||
putWithIdGroupAndZorder(
|
||||
1, 1, "layer", Map.of("id", 1), newPoint(1, 2), 1, true, 2, 3
|
||||
);
|
||||
putWithIdGroupAndZorder(
|
||||
2, 2, "layer", Map.of("id", 1), newPoint(1, 2), 1, true, 2, 3
|
||||
);
|
||||
sorter.sort();
|
||||
var iter = features.iterator();
|
||||
assertFalse(iter.next().hasSameContents(iter.next()));
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue