From cac7dfdc4ebeb639fa34e572a4bc55e6b4228add Mon Sep 17 00:00:00 2001 From: --replace-all Date: Sat, 2 Mar 2024 17:30:08 +0100 Subject: [PATCH] test: added some tests for geohashToEnvelope #213 --- .../com/esri/core/geometry/TestGeohash.java | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/src/test/java/com/esri/core/geometry/TestGeohash.java b/src/test/java/com/esri/core/geometry/TestGeohash.java index e69de29b..a853405b 100644 --- a/src/test/java/com/esri/core/geometry/TestGeohash.java +++ b/src/test/java/com/esri/core/geometry/TestGeohash.java @@ -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); + } + +}