Skip to content

Commit

Permalink
Parameterize tests with zoom levels
Browse files Browse the repository at this point in the history
Also check stablity of single-pixel extents.
  • Loading branch information
abyrd committed Oct 16, 2023
1 parent 1d70428 commit 6b05bae
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/test/java/com/conveyal/r5/analyst/WebMercatorExtentsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
}
Expand All @@ -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);
}

}

0 comments on commit 6b05bae

Please sign in to comment.