Package geodress.tests

Source Code of geodress.tests.CoordinateTest

/**
* GeoDress - A program for reverse geocoding
* Copyright (C) 2010  Stefan T.
*
* See COPYING for Details.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package geodress.tests;

import geodress.exceptions.ParameterOutOfRangeException;
import geodress.model.Coordinate;
import junit.framework.Assert;

import org.junit.Test;

/**
* Tests the {@link Coordinate} class.
*
* @author Stefan T.
*/
public class CoordinateTest {

  /** test picture with EXIF data */
  private Coordinate coords;

  /**
   * Makes a test with valid coordinates.
   *
   * @throws Exception
   *             may cause an exception
   */
  @Test
  public void testValidCoordinates() throws Exception {
    coords = new Coordinate(30, 20);
    Assert.assertEquals((double) 30, coords.getLatitude());
    Assert.assertEquals((double) 20, coords.getLongitude());

    coords.setLatitude(60.8237);
    Assert.assertEquals(60.8237, coords.getLatitude());

    coords.setLongitude(-102.287);
    Assert.assertEquals(-102.287, coords.getLongitude());

    coords.setLatitude(-90);
    Assert.assertEquals((double) -90, coords.getLatitude());

    coords.setLongitude(180);
    Assert.assertEquals((double) 180, coords.getLongitude());

    coords = new Coordinate("-34.5342", "-78.2345");
    Assert.assertEquals(-34.5342, coords.getLatitude());
    Assert.assertEquals(-78.2345, coords.getLongitude());
  }

  /**
   * Makes a test with invalid coordinates.
   *
   * @throws Exception
   *             may cause an exception
   */
  @Test(expected = ParameterOutOfRangeException.class)
  public void testInvalidCoordinates1() throws Exception {
    coords = new Coordinate(43.3454, -98.2343);
    Assert.assertEquals(43.3454, coords.getLatitude());
    Assert.assertEquals(-98.2343, coords.getLongitude());

    coords.setLatitude(92.3452);
  }

  /**
   * Tests the String export of {@link Coordinate}.
   *
   * @throws Exception
   *             may cause an exception
   */
  @Test
  public void testCoordinateString() throws Exception {
    coords = new Coordinate(48.86547, 2.32122);
    Assert.assertEquals("N 48° 51,928'", coords.getLatitudeAsString());
    Assert.assertEquals("E 002° 19,273'", coords.getLongitudeAsString());
    Assert.assertEquals("N 48° 51,928' E 002° 19,273'", coords.toString());

    coords.setLatitude(40.64552);
    coords.setLongitude(-74.13763);
    Assert.assertEquals("N 40° 38,731'", coords.getLatitudeAsString());
    Assert.assertEquals("W 074° 08,258'", coords.getLongitudeAsString());
    Assert.assertEquals("N 40° 38,731' W 074° 08,258'", coords.toString());

    coords.setLatitude(-2.321);
    coords.setLongitude(8.648);
    Assert.assertEquals("S 02° 19,260'", coords.getLatitudeAsString());
    Assert.assertEquals("E 008° 38,880'", coords.getLongitudeAsString());

    coords.setLatitude(-0.321);
    coords.setLongitude(-0.648);
    Assert.assertEquals("S 00° 19,260'", coords.getLatitudeAsString());
    Assert.assertEquals("W 000° 38,880'", coords.getLongitudeAsString());
  }

  /**
   * Makes a test with invalid coordinates.
   *
   * @throws Exception
   *             may cause an exception
   */
  @Test(expected = ParameterOutOfRangeException.class)
  public void testInvalidCoordinates2() throws Exception {
    coords = new Coordinate(43.3452, -197.2344);
  }

  /**
   * Makes a test with invalid coordinates.
   *
   * @throws Exception
   *             may cause an exception
   */
  @Test(expected = ParameterOutOfRangeException.class)
  public void testInvalidCoordinates3() throws Exception {
    coords = new Coordinate("foo", "-98.2342");
  }

  /** Tests method {@link Coordinate#convertToDecimal(int, int, double)}. */
  @Test
  public void testConvertToDecimal() {
    Assert.assertEquals(48.177455556, Coordinate.convertToDecimal(48, 10,
        38.84), 0.00001);

    Assert.assertEquals(48.86547, Coordinate.convertToDecimal(48, 51,
        55.6812), 0.00001);
    Assert.assertEquals(2.32122, Coordinate
        .convertToDecimal(2, 19, 16.3812), 0.00001);

    Assert.assertEquals(40.64552, Coordinate.convertToDecimal(40, 38,
        43.8720), 0.00001);
    Assert.assertEquals(-74.13763, Coordinate.convertToDecimal(-74, -8,
        -15.4680), 0.00001);
  }
}
TOP

Related Classes of geodress.tests.CoordinateTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.