@@ -134,4 +134,85 @@ void testSanityChecks() {
134134 assertNull (cprSurfaceEven .decodeGlobal (cprSurfaceOdd , null ));
135135 }
136136
137+ @ Test
138+ void testAirborneTimingGap () {
139+ CPREncodedPosition cprEven = CPREncodedPosition .ofAirborne (17 , false , 0x06AF1 , 0x09C16 , 0L );
140+ CPREncodedPosition cprOdd = CPREncodedPosition .ofAirborne (17 , true , 0x04706 , 0x04D58 , 0L );
141+
142+ assertEquals (10_000L , cprEven .maxGap (cprOdd ));
143+ assertEquals (10_000L , cprOdd .maxGap (cprEven ));
144+ }
145+
146+ private static void testAirborneTiming (long t1 , long t2 , boolean expectSuccess ) {
147+ CPREncodedPosition cprEven = CPREncodedPosition .ofAirborne (17 , false , 0x06AF1 , 0x09C16 , t1 );
148+ CPREncodedPosition cprOdd = CPREncodedPosition .ofAirborne (17 , true , 0x04706 , 0x04D58 , t2 );
149+
150+ Position even = cprEven .decodeGlobal (cprOdd , null );
151+ Position odd = cprOdd .decodeGlobal (cprEven , null );
152+
153+ if (expectSuccess ) {
154+ assertNotNull (even );
155+ assertNotNull (odd );
156+ } else {
157+ assertNull (even );
158+ assertNull (odd );
159+ }
160+ }
161+
162+ @ Test
163+ void testAirborneTimingChecks () {
164+ testAirborneTiming (0L , 0L , true );
165+ testAirborneTiming (0L , 10_000L , true );
166+ testAirborneTiming (0 , 10_001L , false );
167+ testAirborneTiming (10_000L , 0L , true );
168+ testAirborneTiming (10_001L , 0L , false );
169+ }
170+
171+ private static void testSurfaceTimingGap (boolean hs1 , boolean hs2 , int expect ) {
172+ CPREncodedPosition cprEven = CPREncodedPosition .ofSurface (17 , false , hs1 , 0x1ABC2 , 0x07058 , 0L );
173+ CPREncodedPosition cprOdd = CPREncodedPosition .ofSurface (17 , true , hs2 , 0x11C19 , 0x13560 , 0L );
174+
175+ assertEquals (expect , cprEven .maxGap (cprOdd ));
176+ assertEquals (expect , cprOdd .maxGap (cprEven ));
177+ }
178+
179+ @ Test
180+ void testSurfaceTimingGap () {
181+ testSurfaceTimingGap (false , false , 50_000 );
182+ testSurfaceTimingGap (false , true , 25_000 );
183+ testSurfaceTimingGap (true , false , 25_000 );
184+ testSurfaceTimingGap (true , true , 25_000 );
185+ }
186+
187+ private static void testSurfaceTiming (long t1 , boolean hs1 , long t2 , boolean hs2 , boolean expectSuccess ) {
188+ Position ref = new Position (30. , 80. , 0. );
189+
190+ CPREncodedPosition cprEven = CPREncodedPosition .ofSurface (17 , false , hs1 , 0x1ABC2 , 0x07058 , t1 );
191+ CPREncodedPosition cprOdd = CPREncodedPosition .ofSurface (17 , true , hs2 , 0x11C19 , 0x13560 , t2 );
192+
193+ Position even = cprEven .decodeGlobal (cprOdd , ref );
194+ Position odd = cprOdd .decodeGlobal (cprEven , ref );
195+
196+ if (expectSuccess ) {
197+ assertNotNull (even );
198+ assertNotNull (odd );
199+ } else {
200+ assertNull (even );
201+ assertNull (odd );
202+ }
203+ }
204+
205+ @ Test
206+ void testSurfaceTimingChecks () {
207+ testSurfaceTiming (0L , false , 0L , false , true );
208+ testSurfaceTiming (50_001L , false , 0L , false , false );
209+
210+ testSurfaceTiming (0L , true , 0L , false , true );
211+ testSurfaceTiming (0L , true , 25_000L , false , true );
212+ testSurfaceTiming (0L , true , 25_001L , false , false );
213+ testSurfaceTiming (0L , false , 25_001L , true , false );
214+ testSurfaceTiming (25_0001L , false , 0L , true , false );
215+ testSurfaceTiming (25_0001L , true , 0L , false , false );
216+ }
217+
137218}
0 commit comments