Skip to content

Commit

Permalink
test: added some tests for geohashToEnvelope Esri#213
Browse files Browse the repository at this point in the history
  • Loading branch information
muchembledMartin committed Mar 2, 2024
1 parent 8461a3c commit cac7dfd
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions src/test/java/com/esri/core/geometry/TestGeohash.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.esri.core.geometry;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

public class TestGeohash {

/**
* Check if the center of the new envelope is well placed
*/
@Test
public void testGeohashToEnvelopeWellCentered(){
double delta = 0.00000001;

String geohash1 = "ghgh";

double lat1 = 72.50976563;
double lon1 = -40.60546875;
Envelope2D env1 = Geohash.geohashToEnvelope(geohash1);
double centerX1 = (env1.xmax + env1.xmin)*0.5;
double centerY1 = (env1.ymax + env1.ymin)*0.5;

assertEquals(lon1, centerX1, delta);
assertEquals(lat1, centerY1, delta);

String geohash2 = "p";

double lat2 = -67.50000000;
double lon2 = 157.50000000;
Envelope2D env2 = Geohash.geohashToEnvelope(geohash2);
double centerX2 = (env2.xmax + env2.xmin)*0.5;
double centerY2 = (env2.ymax + env2.ymin)*0.5;

assertEquals(lon2, centerX2, delta);
assertEquals(lat2, centerY2, delta);
}

/**
* Check if the dimension of the new envelope is correct for low precision
*/
@Test
public void testGeohashToEnvelopeGoodDimensions(){
double delta = 0.00000001;

double latDiff = 180/4;
double lonDiff = 360/8;

String geohash = "h";

Envelope2D env = Geohash.geohashToEnvelope(geohash);

assertEquals(lonDiff, env.xmax-env.xmin, delta);
assertEquals(latDiff, env.ymax-env.ymin, delta);
}

/**
* Check if the dimension of the new envelope is correct for higher precision
*/
@Test
public void testGeohashToEnvelopeGoodDimensions2(){
double delta = 0.00000001;

double latDiff = 180.0/32768;
double lonDiff = 360.0/32768;

String geohash = "hggggg";

Envelope2D env = Geohash.geohashToEnvelope(geohash);

assertEquals(lonDiff, env.xmax-env.xmin, delta);
assertEquals(latDiff, env.ymax-env.ymin, delta);
}

}

0 comments on commit cac7dfd

Please sign in to comment.