Skip to content

Commit

Permalink
test: added test cases for coveringGeohash function
Browse files Browse the repository at this point in the history
  • Loading branch information
LinusWallin committed Mar 3, 2024
1 parent 2c31979 commit 4420765
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/esri/core/geometry/Geohash.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
62 changes: 61 additions & 1 deletion src/test/java/com/esri/core/geometry/TestGeohash.java
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}

}

0 comments on commit 4420765

Please sign in to comment.