PageRenderTime 37ms CodeModel.GetById 20ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 6package org.sigmah.client.page.entry.editor;
 7
 8import java.util.Locale;
 9
10import org.junit.Assert;
11import org.junit.Before;
12import org.junit.Test;
13import org.sigmah.client.mock.JreCoordinateEditor;
14import org.sigmah.shared.map.AbstractCoordinateEditor;
15import org.sigmah.shared.map.CoordinateFormatException;
16
17/**
18 * @author Alex Bertram (akbertram@gmail.com)
19 */
20public class CoordinateEditorTest {
21    private static final double DELTA = 0.00001;
22    
23    @Before
24    public void before() {
25    	Locale.setDefault(Locale.ENGLISH);
26    }
27
28
29    @Test
30    public void testDDdParse() throws CoordinateFormatException {
31        JreCoordinateEditor ed = new JreCoordinateEditor("S", "N");
32        Assert.assertEquals(6.325, ed.parse("+6.325"), DELTA);
33        Assert.assertEquals(-6.325, ed.parse("6.325 S"), DELTA);
34        Assert.assertEquals(-2.45, ed.parse("S 2.45"), DELTA);
35        Assert.assertEquals(+2.0, ed.parse("2N"), DELTA);
36    }
37
38    @Test(expected = CoordinateFormatException.class)
39    public void testNoHemiError() throws CoordinateFormatException {
40
41        JreCoordinateEditor ed = new JreCoordinateEditor("S", "N");
42        ed.parse("2.345");
43
44    }
45
46    public void testNoHemiOK() throws CoordinateFormatException {
47
48        JreCoordinateEditor ed = new JreCoordinateEditor("W", "E");
49        ed.setMinValue(-20);
50        ed.setMaxValue(-21);
51        Assert.assertEquals(-20.5, ed.parse("20.5"), 0.001);
52
53        ed.setMinValue(30);
54        ed.setMaxValue(35);
55        Assert.assertEquals(33.3, ed.parse("33.3"), 0.001);
56
57    }
58
59    @Test
60    public void testDMd() throws CoordinateFormatException {
61        JreCoordinateEditor ed = new JreCoordinateEditor("S", "N");
62
63        Assert.assertEquals(30.25, ed.parse("30 15.00\"  N"), DELTA);
64        Assert.assertEquals(-30.75, ed.parse("30 45.0000\" S"), DELTA);
65        Assert.assertEquals(-25.25, ed.parse("S   25 15 "), DELTA);
66
67    }
68
69    @Test
70    public void testDMS() throws CoordinateFormatException {
71        JreCoordinateEditor ed = new JreCoordinateEditor("S", "N");
72
73        Assert.assertEquals(25.18173056, ed.parse("25 10 54.23\"  N"), DELTA);
74        Assert.assertEquals(-176.8397222, ed.parse("176 50' 23\" S"), DELTA);
75    }
76
77    @Test
78    public void formatDDd() {
79
80        JreCoordinateEditor ed = new JreCoordinateEditor("S", "N");
81        ed.setNotation(AbstractCoordinateEditor.Notation.DDd);
82        Assert.assertEquals("+2.405000", ed.format(2.405));
83    }
84
85    @Test
86    public void testNearEquator() {
87        JreCoordinateEditor ed = new JreCoordinateEditor("S", "N");
88
89        Assert.assertEquals(ed.format(-0.9392889738082886), "0? 56' 21.44\" S");
90    }
91
92
93}