From 4420765466991ff31b9ffd31fa321740db3b8502 Mon Sep 17 00:00:00 2001 From: Linus Wallin Date: Sun, 3 Mar 2024 18:37:30 +0100 Subject: [PATCH] test: added test cases for coveringGeohash function --- .../java/com/esri/core/geometry/Geohash.java | 2 +- .../com/esri/core/geometry/TestGeohash.java | 62 ++++++++++++++++++- 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/esri/core/geometry/Geohash.java b/src/main/java/com/esri/core/geometry/Geohash.java index 394be6aa..69322305 100644 --- a/src/main/java/com/esri/core/geometry/Geohash.java +++ b/src/main/java/com/esri/core/geometry/Geohash.java @@ -206,7 +206,7 @@ public static String[] coveringGeohash(Envelope2D envelope) { for (int i = 0; i < deltaLon; i++){ for (int j = 0; j < deltaLat; j++){ Point2D p = new Point2D(gridMinLon + i * grid, gridMinLat + j * grid); - geoHashes[i*deltaLat] = toGeohash(p, 1); + geoHashes[i*deltaLat + j] = toGeohash(p, 1); } } } diff --git a/src/test/java/com/esri/core/geometry/TestGeohash.java b/src/test/java/com/esri/core/geometry/TestGeohash.java index 04f8847e..6321f761 100644 --- a/src/test/java/com/esri/core/geometry/TestGeohash.java +++ b/src/test/java/com/esri/core/geometry/TestGeohash.java @@ -112,4 +112,64 @@ public void testToGeoHash() { assertEquals("gk6ru", p2Hash); assertEquals("sqdnk", p3Hash); } -} + + @Test + public void testCoveringGeohashEmptyEnvelope() { + Envelope2D emptyEnv = new Envelope2D(); + String [] coverage = Geohash.coveringGeohash(emptyEnv); + for (int i = 0; i < 4; i++){ + assertEquals(null, coverage[i]); + } + } + + @Test + public void testCoveringGeohashOneGeohash() { + Envelope2D env = new Envelope2D(-180, -90, -149, -49); + String [] coverage = Geohash.coveringGeohash(env); + assertEquals("0", coverage[0]); + for (int i = 1; i < 4; i++){ + assertEquals(null, coverage[i]); + } + } + + @Test + public void testCoveringGeohashPoint() { + Envelope2D env = new Envelope2D(180,90,180,90); + String [] coverage = Geohash.coveringGeohash(env); + assertEquals("zzzzzzzzzzzz", coverage[0]); + for (int i = 1; i < 4; i++){ + assertEquals(null, coverage[i]); + } + } + + @Test + public void testCoveringGeohashTwoGeohashes() { + Envelope2D env = new Envelope2D(-180, -90, -180, -35); + String [] coverage = Geohash.coveringGeohash(env); + assertEquals("0", coverage[0]); + assertEquals("2", coverage[1]); + assertEquals(null, coverage[2]); + assertEquals(null, coverage[3]); + } + + @Test + public void testCoveringGeohashThreeGeohashes() { + Envelope2D env = new Envelope2D(-180, -90, -180, 5); + String [] coverage = Geohash.coveringGeohash(env); + assertEquals("0", coverage[0]); + assertEquals("2", coverage[1]); + assertEquals("8", coverage[2]); + assertEquals(null, coverage[3]); + } + + @Test + public void testCoveringGeohashFourGeohashes() { + Envelope2D env = new Envelope2D(-180, -90, -140, -40); + String [] coverage = Geohash.coveringGeohash(env); + assertEquals("0", coverage[0]); + assertEquals("2", coverage[1]); + assertEquals("1", coverage[2]); + assertEquals("3", coverage[3]); + } + +} \ No newline at end of file