Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: jflight/test/GpsTest.java


1   /*
2   Project name:   JFlight
3   Hosted at:       www.sourceforge.net
4   Homepage:       jflight.sourceforge.net
5   Licence:        GNU public licence (GPL)
6   Filename:       GpsTest.java
7   Package:    jflight
8   */
9   
10  package        jflight.test;
11  
12  
13  import jflight.model.*;
14  import      jflight.gps.garmin.GarminGps;
15  import      junit.framework.*;
16  
17  /**
18  Testcases for use in the JUnit framework.<br>
19  -> Stand-alone tests that require no user-interaction or connected GPS.
20  
21  
22  
23  
24  @since          JDK1.1.x
25  @author         Ruediger Bien
26  
27  CVS-section:
28  @file_version   $Revision: 1.7 $
29  
30  */
31  
32  
33  public class GpsTest extends TestCase {
34  
35    protected Wpt   Wpt1,
36            Wpt2,
37            Wpt3,
38            Wpt4,
39            Wpt5,
40                      Wpt10, Wpt11,
41                      Wpt20, Wpt21, Wpt22, Wpt23, Wpt24;
42    protected BaseWpt w1,
43            w2,w3,w4,w5,w6,w7,w8;
44    protected BaseWpt w11,w12,w13,w14,w15,w16,w17;
45      protected GarminGps gps = new GarminGps();
46      
47      public GpsTest(String name) {
48        super(name);
49      }
50  
51    // on trig. functions the error seems to depend on the Java-implementation and relating prcision
52    protected boolean err( double realResult, double idealResult, double relError ) {
53      boolean ret;
54      if( Math.abs((realResult/idealResult)-1) < relError ) ret = true;
55      else ret = false;
56      return ret;
57    }
58  
59    protected void setUp() {
60      Wpt1 = new Wpt("waypt1", "testwaypoint1", 47.0, 11.0, Wpt.SYM_DOT );
61      Wpt2 = new Wpt("waypt2", "testwaypoint2", 47.0, 11.0, Wpt.SYM_DOT );
62      Wpt3 = new Wpt("waypt3", "testwaypoint2", 48.0, 12.0, Wpt.SYM_DOT );
63      Wpt4 = new Wpt("waypt1", "testwaypoint1", 47.0, 11.0, Wpt.SYM_DOT );
64      w1 = new BaseWpt(47.5600000, 10.7789000);
65      w2 = new BaseWpt(47.8729355, 10.5311626); // delta 1,2: 39,4 km (calculated by GPS), 332 degrees; 39.42408512168269
66      w3 = new BaseWpt(90,0);
67      w4 = new BaseWpt(-90,0);
68      w5 = new BaseWpt(-36.066666,-59.1);
69      w6 = new BaseWpt(-35.03555,-58.09265); // delta 5,6 = 146km, 218 degrees
70      w7 = new BaseWpt(-27.99642,153.02634);
71      w8 = new BaseWpt(-28.043783,152.55276); // delta 7,8 = 46,9km, 263 degrees
72  
73      w11 = new BaseWpt(47.5600000, 10.7789000);
74      w12 = new BaseWpt(47.8729355, 10.5311626);
75      w13 = new BaseWpt(1.0,1.0); // center
76      w14 = new BaseWpt(3.0,3.0); // ne
77      w15 = new BaseWpt(-1.0,3.0); // se
78      w16 = new BaseWpt(-1.0,-1.0); // sw
79      w17 = new BaseWpt(3.0,-1.0); // nw
80  
81      Wpt10 = new Wpt("Tegelberg", "", 47.5600000, 10.7789000, Wpt.SYM_DOT);
82      Wpt11 = new Wpt("Wank", "", 47.50972, 11.14583, Wpt.SYM_DOT);
83      Wpt20 = new Wpt("Ref", "", 46.0+5.0/6.0, 13.0+2.0/6.0, Wpt.SYM_DOT);
84      Wpt21 = new Wpt("", "", 46.0+4.0/6.0, 12.0+5.0/6.0, Wpt.SYM_DOT);
85      Wpt22 = new Wpt("", "", 47.0, 13.0, Wpt.SYM_DOT);
86      Wpt23 = new Wpt("", "", 47.0, 13.0+5.0/6.0, Wpt.SYM_DOT);
87      Wpt24 = new Wpt("", "", 46.0+4.0/6.0, 13.0+4.0/6.0, Wpt.SYM_DOT);
88      }
89  
90    public void testWpt1() {
91      TestCase.assert(Wpt1.equalsCrd(Wpt2) );
92    }
93    public void testWpt2() {
94      TestCase.assert( (boolean)!Wpt1.equalsCrd(Wpt3) );
95    }
96    public void testWpt3() {
97      TestCase.assert( !Wpt1.equals(Wpt3) );
98    }
99    public void testWpt4() {
100     TestCase.assert( Wpt1.equals(Wpt4) );
101   }
102 
103   public void testBaseWpt1() {
104     TestCase.assert( err(w1.dist(w2), 39.42408512168269, 0.001) );
105   }
106   public void testBaseWpt2() {
107     TestCase.assert( err(w3.dist(w4), 20014.7267961, 0.001) );
108   }
109   public void testBaseWpt3() {
110     TestCase.assert( err(w5.dist(w6), 146.4565403102081, 0.001) );
111   }
112   public void testBaseWpt4() {
113     TestCase.assert( err(w7.dist(w8), 46.78357168950175, 0.001) );
114   }
115 
116   public void testMod1() {
117     TestCase.assert( BaseWpt.mod(3.0,4.0)==3.0 );
118   }
119   public void testMod2() {
120     TestCase.assert( BaseWpt.mod(-3.0,4.0)==-3.0 );
121   }
122   
123   public void testDist1() {
124     TestCase.assert( err(w11.dist(w12), 39.424, 0.001) );
125   }
126   public void testDist2() {
127     TestCase.assert( err(w13.dist(w14), 314.397, 0.001) );
128   }
129   public void testDist3() {
130     TestCase.assert( err(w13.dist(w17), 314.397, 0.001) );
131   }
132   public void testDist4() {
133     TestCase.assert( err(w13.dist(w15), 314.493, 0.001) );
134   }
135   public void testDist5() {
136     TestCase.assert( err(w13.dist(w16), 314.493, 0.001) );
137   }
138 
139   public void testTc1() {
140     TestCase.assert( err(w11.tc(w12), 332.0506, 0.001) );
141   }
142   public void testTc2() {
143     TestCase.assert( err(w13.tc(w14), 45.0, 0.1) );
144   }
145   public void testTc3() {
146     TestCase.assert( err(w13.tc(w15), 135.0, 0.1) );
147   }
148   public void testTc4() {
149     TestCase.assert( err(w13.tc(w16), 225.0, 0.1) );
150   }
151   public void testTc5() {
152     TestCase.assert( err(w13.tc(w17), 315.0, 0.1) );
153   }
154 
155   public void testPoc() {
156     TestCase.assert( w1.poc(w11.dist(w12),w11.tc(w12)).equalsCrdNearly(w2) );
157   }
158 
159     // tests with delta x / y:
160     public void testAdd1() {
161         Wpt newWpt;
162         newWpt = Wpt10.createNewWptRelativeToThis( 13.8*2.0, -2.65*2.0 ,
163                                0, 0,
164                                "name", "comment",
165                                0 );
166         System.out.println("Real dist 1-2 is: " + Wpt10.dist(Wpt11));
167         System.out.println("Real tc   1-2 is: " + Wpt10.tc(Wpt11));
168         System.out.println("Error dist is:    " + Wpt11.dist(newWpt));
169         System.out.println("Error tc   is:    " + Wpt10.tc(newWpt));
170         TestCase.assert( Wpt11.dist(newWpt) < 1.0 );
171     }
172 
173     public void testAdd2() {
174         Wpt newWpt;
175         newWpt = Wpt20.createNewWptRelativeToThis(-18.7*2.0, -9.2*2.0 ,
176                                0, 0,
177                                "name", "comment",
178                                0 );
179         System.out.println("Real dist 1-2 is: " + Wpt20.dist(Wpt21));
180         System.out.println("Real tc   1-2 is: " + Wpt20.tc(Wpt21));
181         System.out.println("Error dist is:    " + Wpt21.dist(newWpt));
182         System.out.println("Error tc   is:    " + Wpt20.tc(newWpt));
183         TestCase.assert( Wpt21.dist(newWpt) < 1.0 );
184     }
185 
186     public void testAdd3() {
187         Wpt newWpt;
188         newWpt = Wpt20.createNewWptRelativeToThis( -12.5*2.0, 9.2*2.0 ,
189                                0, 0,
190                                "name", "comment",
191                                0 );
192         System.out.println("Real dist 1-2 is: " + Wpt20.dist(Wpt22));
193         System.out.println("Real tc   1-2 is: " + Wpt20.tc(Wpt22));
194         System.out.println("Error dist is:    " + Wpt22.dist(newWpt));
195         System.out.println("Error tc   is:    " + Wpt20.tc(newWpt));
196         TestCase.assert( Wpt22.dist(newWpt) < 1.0 );
197     }
198 
199     public void testAdd4() {
200         Wpt newWpt;
201         newWpt = Wpt20.createNewWptRelativeToThis( 18.7*2.0, 9.2*2.0 ,
202                                0, 0,
203                                "name", "comment",
204                                0 );
205         System.out.println("Real dist 1-2 is: " + Wpt20.dist(Wpt23));
206         System.out.println("Real tc   1-2 is: " + Wpt20.tc(Wpt23));
207         System.out.println("Error dist is:    " + Wpt23.dist(newWpt));
208         System.out.println("Error tc   is:    " + Wpt20.tc(newWpt));
209         TestCase.assert( Wpt23.dist(newWpt) < 1.0 );
210     }
211 
212     public void testAdd5() {
213         Wpt newWpt;
214         newWpt = Wpt20.createNewWptRelativeToThis( 12.4*2.0, -9.2*2.0 ,
215                                0, 0,
216                                "name", "comment",
217                                0 );
218         System.out.println("Real dist 1-2 is: " + Wpt20.dist(Wpt24));
219         System.out.println("Real tc   1-2 is: " + Wpt20.tc(Wpt24));
220         System.out.println("Error dist is:    " + Wpt24.dist(newWpt));
221         System.out.println("Error tc   is:    " + Wpt20.tc(newWpt));
222         TestCase.assert( Wpt24.dist(newWpt) < 1.0 );
223     }
224 
225     // test with delta / phi:
226     public void testAdd6() {
227         Wpt newWpt;
228         newWpt = Wpt20.createNewWptRelativeToThis( 0.0, 0.0 ,
229                                42.362, 244.24,
230                                "name", "comment",
231                                0 );
232         System.out.println("Real dist 1-2 is: " + Wpt20.dist(Wpt21));
233         System.out.println("Real tc   1-2 is: " + Wpt20.tc(Wpt21));
234         System.out.println("Error dist is:    " + Wpt21.dist(newWpt));
235         System.out.println("Error tc   is:    " + Wpt20.tc(newWpt));
236         TestCase.assert( Wpt21.dist(newWpt) < 1.0 );
237     }
238 
239 }
240 
241 /* copy&paste
242   public void test() {
243     assert();
244   }
245 */