sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rlaid...@apache.org
Subject svn commit: r1359754 - in /incubator/sis/trunk: CHANGES.txt sis-core/src/test/java/org/apache/sis/util/ sis-core/src/test/java/org/apache/sis/util/TestGeoHashUtils.java
Date Tue, 10 Jul 2012 16:18:12 GMT
Author: rlaidlaw
Date: Tue Jul 10 16:18:11 2012
New Revision: 1359754

URL: http://svn.apache.org/viewvc?rev=1359754&view=rev
Log:
SIS-50: added simple unit tests for GeoHashUtils class in sis-core

Added:
    incubator/sis/trunk/sis-core/src/test/java/org/apache/sis/util/
    incubator/sis/trunk/sis-core/src/test/java/org/apache/sis/util/TestGeoHashUtils.java 
 (with props)
Modified:
    incubator/sis/trunk/CHANGES.txt

Modified: incubator/sis/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/sis/trunk/CHANGES.txt?rev=1359754&r1=1359753&r2=1359754&view=diff
==============================================================================
--- incubator/sis/trunk/CHANGES.txt (original)
+++ incubator/sis/trunk/CHANGES.txt Tue Jul 10 16:18:11 2012
@@ -3,7 +3,9 @@ Apache SIS Change Log
 
 Release 0.3-incubating - Current Development
 
-* SIS-48: added some basic junit tests for the core geometry classes in 
+* SIS-49: added some simple junit tests for the GeoHashUtils class in sis-core
+
+* SIS-48: added some simple junit tests for the core geometry classes in 
   sis-core - LatLon, LatLonRect and LatLonPointRadius (rlaidlaw)
 
 * SIS-49: updated for loop in getCircularRegionApproximation of LatLonPointRadius 

Added: incubator/sis/trunk/sis-core/src/test/java/org/apache/sis/util/TestGeoHashUtils.java
URL: http://svn.apache.org/viewvc/incubator/sis/trunk/sis-core/src/test/java/org/apache/sis/util/TestGeoHashUtils.java?rev=1359754&view=auto
==============================================================================
--- incubator/sis/trunk/sis-core/src/test/java/org/apache/sis/util/TestGeoHashUtils.java (added)
+++ incubator/sis/trunk/sis-core/src/test/java/org/apache/sis/util/TestGeoHashUtils.java Tue
Jul 10 16:18:11 2012
@@ -0,0 +1,119 @@
+package org.apache.sis.util;
+
+import junit.framework.TestCase;
+
+//JDK imports
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * Tests methods from the {@link GeoHashUtils} class.
+ * 
+ * @author rlaidlaw
+ */
+public class TestGeoHashUtils extends TestCase
+{
+  private static final double EPSILON = 0.000001;
+  private HashMap<String, HashMap<String, double[]>> places;
+
+  /**
+   * Sets up objects before running tests.
+   */
+  public void setUp()
+  {
+    // Test data - locations and geohashes of some notable places
+    places = new HashMap<String, HashMap<String, double[]>>();
+    places.put("Empire State Building", new HashMap<String, double[]>());
+    places.put("Statue Of Liberty", new HashMap<String, double[]>());
+    places.put("The White House", new HashMap<String, double[]>());
+    places.put("Hoover Dam", new HashMap<String, double[]>());
+    places.put("Golden Gate Bridge", new HashMap<String, double[]>());
+    places.put("Mount Rushmore", new HashMap<String, double[]>());
+    places.put("Space Needle", new HashMap<String, double[]>());
+
+    places.get("Empire State Building").put("dr5ru6j2c62q", new double[]{40.748433, -73.985656});
+    places.get("Statue Of Liberty").put("dr5r7p4rx6kz", new double[]{40.689167, -74.044444});
+    places.get("The White House").put("dqcjqcpeq70c", new double[]{38.897669, -77.03655});
+    places.get("Hoover Dam").put("9qqkvh6mzfpz", new double[]{36.015556, -114.737778});
+    places.get("Golden Gate Bridge").put("9q8zhuvgce0m", new double[]{37.819722, -122.478611});
+    places.get("Mount Rushmore").put("9xy3teyv7ke4", new double[]{43.878947, -103.459825});
+    places.get("Space Needle").put("c22yzvh0gmfy", new double[]{47.620400, -122.349100});
+  }
+  
+  /**
+   * Clears up objects after running tests.
+   */
+  public void tearDown()
+  {
+    places = null;
+  }
+  
+  /**
+   * Tests the encode() method.
+   */
+  public void testEncode()
+  {
+    for (Map.Entry<String, HashMap<String, double[]>> place : places.entrySet())
+    {
+      HashMap<String, double[]> geoData = place.getValue();
+      
+      if (geoData == null) 
+      { 
+        fail("incorrect test data"); 
+      }
+      else
+      {
+        for (Map.Entry<String, double[]> geoInfo : geoData.entrySet())
+        {
+          String geoHash = geoInfo.getKey();
+          double[] point = geoInfo.getValue();
+          
+          if (geoHash == null || point == null) 
+          { 
+            fail("incorrect test data"); 
+          }
+          else
+          {
+            String encoded = GeoHashUtils.encode(point[0], point[1]);
+            assertEquals(geoHash, encoded);
+          }
+        }        
+      }
+    }
+  }
+  
+  /**
+   * Tests the decode() method.
+   */
+  public void testDecode()
+  {
+    for (Map.Entry<String, HashMap<String, double[]>> place : places.entrySet())
+    {
+      HashMap<String, double[]> geoData = place.getValue();
+      
+      if (geoData == null) 
+      { 
+        fail("incorrect test data"); 
+      }
+      else
+      {
+        for (Map.Entry<String, double[]> geoInfo : geoData.entrySet())
+        {
+          String geoHash = geoInfo.getKey();
+          double[] point = geoInfo.getValue();
+          
+          if (geoHash == null || point == null) 
+          { 
+            fail("incorrect test data"); 
+          }
+          else
+          {
+            double[] decoded = GeoHashUtils.decode(geoHash);
+            assertEquals(point[0], decoded[0], EPSILON);
+            assertEquals(point[1], decoded[1], EPSILON);
+          }
+        }
+      }
+    }
+  }
+}

Propchange: incubator/sis/trunk/sis-core/src/test/java/org/apache/sis/util/TestGeoHashUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message