From 6b05bae15c74fb973b1fcd967c4e640a1b2bce15 Mon Sep 17 00:00:00 2001 From: Andrew Byrd Date: Tue, 17 Oct 2023 01:38:15 +0200 Subject: [PATCH] Parameterize tests with zoom levels Also check stablity of single-pixel extents. --- .../r5/analyst/WebMercatorExtentsTest.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/test/java/com/conveyal/r5/analyst/WebMercatorExtentsTest.java b/src/test/java/com/conveyal/r5/analyst/WebMercatorExtentsTest.java index 2b4556154..310166529 100644 --- a/src/test/java/com/conveyal/r5/analyst/WebMercatorExtentsTest.java +++ b/src/test/java/com/conveyal/r5/analyst/WebMercatorExtentsTest.java @@ -2,6 +2,8 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.locationtech.jts.geom.Envelope; class WebMercatorExtentsTest { @@ -23,19 +25,20 @@ class WebMercatorExtentsTest { * Ideally we should also test that this is the case when the non-integer WGS84 values are truncated by a few * digits (as when they are stored in a database or serialized over the wire). */ - @Test - void wgsMercatorStability () { + @ParameterizedTest + @ValueSource(ints = {9, 10, 11}) + void wgsMercatorStability (int zoom) { Envelope wgsEnvelope = new Envelope(); wgsEnvelope.expandToInclude(10.22222222, 45.111111); wgsEnvelope.expandBy(0.1); - WebMercatorExtents webMercatorExtents = WebMercatorExtents.forWgsEnvelope(wgsEnvelope, 9); + WebMercatorExtents webMercatorExtents = WebMercatorExtents.forWgsEnvelope(wgsEnvelope, zoom); for (int i = 0; i < 10; i++) { Assertions.assertTrue(webMercatorExtents.width > 20); Assertions.assertTrue(webMercatorExtents.height > 20); wgsEnvelope = webMercatorExtents.toWgsEnvelope(); // Note the use of the trimmed envelope factory function, which should be used in the API. - WebMercatorExtents webMercatorExtents2 = WebMercatorExtents.forTrimmedWgsEnvelope(wgsEnvelope, 9); + WebMercatorExtents webMercatorExtents2 = WebMercatorExtents.forTrimmedWgsEnvelope(wgsEnvelope, zoom); Assertions.assertEquals(webMercatorExtents2, webMercatorExtents); webMercatorExtents = webMercatorExtents2; } @@ -45,19 +48,24 @@ void wgsMercatorStability () { * Check that a zero-size envelope (around a single point for example) will yield an extents object containing * one cell (rather than zero cells). Also check an envelope with a tiny nonzero envelope away from cell edges. */ - @Test - void singleCellExtents () { + @ParameterizedTest + @ValueSource(ints = {9, 10, 11}) + void singleCellExtents (int zoom) { Envelope wgsEnvelope = new Envelope(); wgsEnvelope.expandToInclude(10.22222222, 10.32222222); - WebMercatorExtents webMercatorExtents = WebMercatorExtents.forWgsEnvelope(wgsEnvelope, 9); + WebMercatorExtents webMercatorExtents = WebMercatorExtents.forWgsEnvelope(wgsEnvelope, zoom); Assertions.assertEquals(1, webMercatorExtents.width); Assertions.assertEquals(1, webMercatorExtents.height); wgsEnvelope.expandBy(0.00001); - webMercatorExtents = WebMercatorExtents.forWgsEnvelope(wgsEnvelope, 9); + webMercatorExtents = WebMercatorExtents.forWgsEnvelope(wgsEnvelope, zoom); Assertions.assertEquals(1, webMercatorExtents.width); Assertions.assertEquals(1, webMercatorExtents.height); + + // Try taking these single-pixel extents through WGS84 for good measure. + WebMercatorExtents wme2 = WebMercatorExtents.forTrimmedWgsEnvelope(webMercatorExtents.toWgsEnvelope(), zoom); + Assertions.assertEquals(webMercatorExtents, wme2); } } \ No newline at end of file