### Question:
Geo { public static double lengthOf(LineString line) { double dist = 0.0; Coordinate[] coords = line.getCoordinates(); for (int i = 1; i < coords.length; i++) { dist += distanceBetweenCoordinates( coords[i - 1].y, coords[i - 1].x, coords[i].y, coords[i].x ); } return dist; }  static double distanceBetweenCoordinatesHaversine(
      double lat1, double lng1, double lat2, double lng2
  ); static double distanceBetweenCoordinates(
      double lat1, double lng1, double lat2, double lng2
  ); static double lengthOf(LineString line); static double lengthOf(MultiLineString multiline); static double lengthOf(GeometryCollection geometryCollection); static double lengthOf(Geometry geom); static double areaOf(Polygon poly); static double areaOf(MultiPolygon multipoly); static double areaOf(GeometryCollection geometryCollection); static double areaOf(Geometry geom); static double ringArea(LinearRing ring); static Geometry clip(Geometry obj, OSHDBBoundingBox bbox); static Geometry clip(Geometry obj, P poly); static double earthRadius; }### Answer:
@Test public void testLengthLineString() { LineString line = gf.createLineString(constructCoordinates( 0, 0, 1, 1 )); assertEquals(1.0, 157425.5 / Geo.lengthOf(line), 0.05); }
@Test public void testLengthMultiLineString() { LineString line1 = gf.createLineString(constructCoordinates( 0, 0, 1, 1 )); LineString line2 = gf.createLineString(constructCoordinates( 1, 1, 2, 0 )); MultiLineString mline = gf.createMultiLineString(new LineString[] { line1, line2 }); assertEquals(2.0, Geo.lengthOf(mline) / Geo.lengthOf(line1), 0.0001); }
@Test public void testLengthGeometryCollection() { LineString line1 = gf.createLineString(constructCoordinates( 0, 0, 1, 1 )); LineString line2 = gf.createLineString(constructCoordinates( 1, 1, 2, 0 )); Polygon poly1 = gf.createPolygon(constructRing( 0, 0, 0, 1, 1, 1, 1, 0, 0, 0 )); GeometryCollection gcoll = gf.createGeometryCollection(new Geometry[]{ line1, line2 }); assertEquals(2.0, Geo.lengthOf(gcoll) / Geo.lengthOf(line1), 0.0001); GeometryCollection gcoll2 = gf.createGeometryCollection(new Geometry[]{ line1, gf.createPoint(new Coordinate(0, 0)), poly1 }); assertEquals(1.0, Geo.lengthOf(gcoll2) / Geo.lengthOf(line1), 0.0001); }
@Test public void testLengthOther() { assertEquals(0.0, Geo.lengthOf(gf.createPoint(new Coordinate(0, 0))), 1E-22); assertEquals(0.0, Geo.lengthOf(gf.createMultiPoint(new Point[]{ gf.createPoint(new Coordinate(0, 0)), gf.createPoint(new Coordinate(1, 1)) })), 1E-22); assertEquals(0.0, Geo.lengthOf(gf.createPolygon( constructRing(0, 0, 1, 1, 0, 1, 0, 0) )), 1E-22); assertEquals(0.0, Geo.lengthOf(gf.createMultiPolygon(new Polygon[]{ gf.createPolygon(constructRing(0, 0, 1, 1, 0, 1, 0, 0)), gf.createPolygon(constructRing(1, 1, 2, 2, 1, 2, 1, 1)) })), 1E-22); }