package com.ibm.util; import org.junit.Test; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertEquals; /** * Created by sveinhd on 9/18/15. */ public class CoordinateConversionTest { private CoordinateConversion testCoords = new CoordinateConversion(); @Test public void testUtm2LatLon() throws Exception { double[] expected = {60.3758408371024, 5.311877955616566}; assertEquals("utm2LatLon", expected[0], testCoords.utm2LatLon("31 V 627468 6695507")[0], 0.0000001d); assertEquals("utm2LatLon", expected[1], testCoords.utm2LatLon("31 V 627468 6695507")[1], 0.0000001d); } @Test public void testLatLon2UTM() throws Exception { assertThat(testCoords.latLon2UTM(60.37586, 5.31189).toString(), is("31 V 627468 6695507")); assertThat(testCoords.latLon2UTM(56.675429305555554, 5.4138547500000005).toString() , is("31 V 647893 6283860")); assertThat(testCoords.latLon2UTM(0, 0).toString(), is("31 N 166021 0")); assertThat(testCoords.latLon2UTM(0.1300, -0.2324).toString(), is("30 N 808084 14385")); } @Test public void negdms2LatLon() throws Exception { double[] expected = {-3.083333, -8.6}; double[] actual = testCoords.dms2LatLon(-3, 5, 0d, -8, 36, 0d); assertEquals("dms2LatLon latitude", expected[0], actual[0], 0.00001d); assertEquals("dms2LatLon longitude", expected[1], actual[1], 0.00001d); } @Test public void dms2LatLon() throws Exception { double[] expected = {60.37583333333333, 5.311889}; double[] actual = testCoords.dms2LatLon(60, 22, 33.0d, 5, 18, 42.8); assertEquals("dms2LatLon", expected[0], actual[0], 0.00001d); assertEquals("dms2LatLon", expected[1], actual[1], 0.00001d); } @Test public void latLon2dms() throws Exception { double[] expected = {60.0, 22.0, 33.0, 5.0, 18.0, 42.8003}; double[] actual = testCoords.latLon2dms(60.37583333333333, 5.311889); assertEquals("latLon2dms", expected[0], actual[0], 0.1d); assertEquals("latLon2dms", expected[1], actual[1], 0.1d); assertEquals("latLon2dms", expected[2], actual[2], 0.1d); assertEquals("latLon2dms", expected[3], actual[3], 0.1d); assertEquals("latLon2dms", expected[4], actual[4], 0.1d); assertEquals("latLon2dms", expected[5], actual[5], 0.001d); } }