Ejemplo n.º 1
0
  public void testToString() {
    Geodetic3DPoint p = TestGeoPoint.randomGeodetic3DPoint(r);
    int prevLen = 0;

    String base = p.toString();
    String prefix = base.substring(0, base.indexOf(' ')); // e.g. "75 deg"
    char letter = base.charAt(base.indexOf(')') - 1); // e.g. "S"

    // System.out.println("base=" + base + " pre=" + prefix + " letter=" + letter);

    for (int i = 0; i < 6; i++) {
      /*
      length of string should increase two digits for each fractional # of digits in lat & lon
      0 (133 deg 47' 15" W, 73 deg 17' 33" S) @ 733484m
      1 (133 deg 47' 14.8" W, 73 deg 17' 32.7" S) @ 733484.0m
      2 (133 deg 47' 14.81" W, 73 deg 17' 32.67" S) @ 733484.00m
      3 (133 deg 47' 14.806" W, 73 deg 17' 32.675" S) @ 733484.000m
      4 (133 deg 47' 14.8060" W, 73 deg 17' 32.6749" S) @ 733484.0000m
      5 (133 deg 47' 14.80597" W, 73 deg 17' 32.67487" S) @ 733484.00000m
       ...
       */
      String s = p.toString(i);
      System.out.println(i + " " + s);
      int len = s.length();
      assertTrue(len >= prevLen + 2);
      // simple tests: 1) each should start with same degrees and 2) end with same hemisphere
      assertTrue(s.startsWith(prefix));
      assertEquals(letter, s.charAt(s.indexOf(')') - 1));
      prevLen = len;
    }
  }
Ejemplo n.º 2
0
 public void testHashCode() {
   assertEquals(a.hashCode(), b.hashCode());
   assertTrue(
       a.hashCode()
           != c
               .hashCode()); // this test isn't required by equals-hashCode contract but by how the
                             // hashCode is computed
 }
Ejemplo n.º 3
0
  public void testEquals() {
    // test equality with known geo-points
    assertEquals(a, b);
    assertFalse(a.equals(c));
    assertFalse(a.equals(d));
    assertFalse(c.equals(d));

    // test equality with any possible round off errors
    Geodetic3DPoint a2 =
        new Geodetic3DPoint(
            new Longitude(Math.toRadians(a.getLongitude().inDegrees())),
            new Latitude(Math.toRadians(a.getLatitude().inDegrees())),
            a.getElevation());
    assertEquals(a, a2);
    assertEquals(a.hashCode(), a2.hashCode());

    // approximate equals test for elevations up to 3 decimal places
    Geodetic3DPoint a3 =
        new Geodetic3DPoint(a.getLongitude(), a.getLatitude(), a.getElevation() + 10e-6);
    assertEquals(a, a3);
    assertEquals(a.hashCode(), a3.hashCode());
  }
Ejemplo n.º 4
0
  /** This method performs format conversions with string constructors in degrees and dms */
  public void testRandomEquals() {
    for (int i = 0; i < 1000; i++) {
      Geodetic3DPoint a1 = randomGeoPoint(r);
      Geodetic3DPoint a2 =
          new Geodetic3DPoint(a1.getLongitude(), a1.getLatitude(), a1.getElevation());
      // note by making equals() work in round off errors (such as in this case) using
      // Angle.equals() vs phi1=phi2 && lamb1==lamb2
      // but break contract in hashCode such that a.equals(b) -> true but hashCode(a) may not equal
      // hashCode(b)
      assertEquals(a1, a2);
      assertEquals(a1.hashCode(), a2.hashCode());

      // for symmetric tests to work elevation must be non-zero
      final double elevation = a1.getElevation();
      if (elevation == 0.0 || Math.abs(elevation) < 1e-8) a1.setElevation(1234.5);

      // test symmetric equals tests a.equals(b) -> b.equals(a)
      Geodetic2DPoint pt2 = new Geodetic2DPoint(a1.getLongitude(), a1.getLatitude());
      assertFalse(pt2.equals(a1));
      assertFalse(a1.equals(pt2));
      a1.setElevation(0);
      assertEquals(pt2, a1); // pt2.equals(al) -> a1.equals(pt2)
      assertEquals(a1, pt2);
    }
  }
Ejemplo n.º 5
0
 public void testNullCompare() {
   Geodetic3DPoint other = null;
   assertFalse(a.equals(other));
   Geodetic2DPoint p2 = null;
   assertFalse(a.equals(p2));
 }