/sigmah/src/test/java/org/sigmah/client/page/entry/editor/CoordinateEditorTest.java

http://sigma-h.googlecode.com/ · Java · 93 lines · 61 code · 25 blank · 7 comment · 0 complexity · 0aa295736904e66a6c122c202a8e9500 MD5 · raw file

  1. /*
  2. * All Sigmah code is released under the GNU General Public License v3
  3. * See COPYRIGHT.txt and LICENSE.txt.
  4. */
  5. package org.sigmah.client.page.entry.editor;
  6. import java.util.Locale;
  7. import org.junit.Assert;
  8. import org.junit.Before;
  9. import org.junit.Test;
  10. import org.sigmah.client.mock.JreCoordinateEditor;
  11. import org.sigmah.shared.map.AbstractCoordinateEditor;
  12. import org.sigmah.shared.map.CoordinateFormatException;
  13. /**
  14. * @author Alex Bertram (akbertram@gmail.com)
  15. */
  16. public class CoordinateEditorTest {
  17. private static final double DELTA = 0.00001;
  18. @Before
  19. public void before() {
  20. Locale.setDefault(Locale.ENGLISH);
  21. }
  22. @Test
  23. public void testDDdParse() throws CoordinateFormatException {
  24. JreCoordinateEditor ed = new JreCoordinateEditor("S", "N");
  25. Assert.assertEquals(6.325, ed.parse("+6.325"), DELTA);
  26. Assert.assertEquals(-6.325, ed.parse("6.325 S"), DELTA);
  27. Assert.assertEquals(-2.45, ed.parse("S 2.45"), DELTA);
  28. Assert.assertEquals(+2.0, ed.parse("2N"), DELTA);
  29. }
  30. @Test(expected = CoordinateFormatException.class)
  31. public void testNoHemiError() throws CoordinateFormatException {
  32. JreCoordinateEditor ed = new JreCoordinateEditor("S", "N");
  33. ed.parse("2.345");
  34. }
  35. public void testNoHemiOK() throws CoordinateFormatException {
  36. JreCoordinateEditor ed = new JreCoordinateEditor("W", "E");
  37. ed.setMinValue(-20);
  38. ed.setMaxValue(-21);
  39. Assert.assertEquals(-20.5, ed.parse("20.5"), 0.001);
  40. ed.setMinValue(30);
  41. ed.setMaxValue(35);
  42. Assert.assertEquals(33.3, ed.parse("33.3"), 0.001);
  43. }
  44. @Test
  45. public void testDMd() throws CoordinateFormatException {
  46. JreCoordinateEditor ed = new JreCoordinateEditor("S", "N");
  47. Assert.assertEquals(30.25, ed.parse("30 15.00\" N"), DELTA);
  48. Assert.assertEquals(-30.75, ed.parse("30 45.0000\" S"), DELTA);
  49. Assert.assertEquals(-25.25, ed.parse("S 25 15 "), DELTA);
  50. }
  51. @Test
  52. public void testDMS() throws CoordinateFormatException {
  53. JreCoordinateEditor ed = new JreCoordinateEditor("S", "N");
  54. Assert.assertEquals(25.18173056, ed.parse("25 10 54.23\" N"), DELTA);
  55. Assert.assertEquals(-176.8397222, ed.parse("176 50' 23\" S"), DELTA);
  56. }
  57. @Test
  58. public void formatDDd() {
  59. JreCoordinateEditor ed = new JreCoordinateEditor("S", "N");
  60. ed.setNotation(AbstractCoordinateEditor.Notation.DDd);
  61. Assert.assertEquals("+2.405000", ed.format(2.405));
  62. }
  63. @Test
  64. public void testNearEquator() {
  65. JreCoordinateEditor ed = new JreCoordinateEditor("S", "N");
  66. Assert.assertEquals(ed.format(-0.9392889738082886), "0? 56' 21.44\" S");
  67. }
  68. }