1   package org.orekit.files.iirv;
2   
3   import org.junit.jupiter.api.BeforeEach;
4   import org.junit.jupiter.api.Test;
5   import org.orekit.Utils;
6   import org.orekit.errors.OrekitException;
7   import org.orekit.errors.OrekitIllegalArgumentException;
8   import org.orekit.files.iirv.terms.CheckSumTerm;
9   import org.orekit.files.iirv.terms.CoordinateSystemTerm;
10  import org.orekit.files.iirv.terms.CrossSectionalAreaTerm;
11  import org.orekit.files.iirv.terms.DataSourceTerm;
12  import org.orekit.files.iirv.terms.DayOfYearTerm;
13  import org.orekit.files.iirv.terms.DragCoefficientTerm;
14  import org.orekit.files.iirv.terms.IIRVTermUtils;
15  import org.orekit.files.iirv.terms.MassTerm;
16  import org.orekit.files.iirv.terms.MessageClassTerm;
17  import org.orekit.files.iirv.terms.MessageEndConstantTerm;
18  import org.orekit.files.iirv.terms.MessageIDTerm;
19  import org.orekit.files.iirv.terms.MessageSourceTerm;
20  import org.orekit.files.iirv.terms.MessageStartConstantTerm;
21  import org.orekit.files.iirv.terms.MessageTypeTerm;
22  import org.orekit.files.iirv.terms.OriginIdentificationTerm;
23  import org.orekit.files.iirv.terms.OriginatorRoutingIndicatorTerm;
24  import org.orekit.files.iirv.terms.PositionVectorComponentTerm;
25  import org.orekit.files.iirv.terms.RoutingIndicatorTerm;
26  import org.orekit.files.iirv.terms.SequenceNumberTerm;
27  import org.orekit.files.iirv.terms.SolarReflectivityCoefficientTerm;
28  import org.orekit.files.iirv.terms.SpareConstantTerm;
29  import org.orekit.files.iirv.terms.SupportIdCodeTerm;
30  import org.orekit.files.iirv.terms.TransferTypeConstantTerm;
31  import org.orekit.files.iirv.terms.VectorTypeTerm;
32  import org.orekit.files.iirv.terms.VehicleIdCodeTerm;
33  import org.orekit.files.iirv.terms.VelocityVectorComponentTerm;
34  import org.orekit.files.iirv.terms.base.DoubleValuedIIRVTerm;
35  
36  import static org.junit.jupiter.api.Assertions.assertEquals;
37  import static org.junit.jupiter.api.Assertions.assertFalse;
38  import static org.junit.jupiter.api.Assertions.assertThrows;
39  import static org.junit.jupiter.api.Assertions.assertTrue;
40  
41  /**
42   * Tests various functionality related to individual IIRV terms
43   */
44  public class IIRVTermTest {
45  
46      @BeforeEach
47      public void setUp() {
48          // Sets the root of data to read
49          Utils.setDataRoot("regular-data");
50      }
51  
52      /**
53       * Test initialization of {@link org.orekit.files.iirv.terms.CheckSumTerm}
54       */
55      @Test
56      void testCheckSumTerm() {
57          // Verify valid inputs are accepted
58          assertEquals(12, new CheckSumTerm(12).value());
59          assertEquals(12, new CheckSumTerm("012").value());
60          assertEquals("012", new CheckSumTerm("012").toEncodedString());
61  
62          // Verify errors are thrown for incorrect inputs
63          assertThrows(OrekitIllegalArgumentException.class, () -> new CheckSumTerm(1000));
64          assertThrows(OrekitIllegalArgumentException.class, () -> new CheckSumTerm("x"));
65          assertThrows(OrekitIllegalArgumentException.class, () -> new CheckSumTerm(-12));
66  
67          // Verify checksum validation
68          assertTrue(CheckSumTerm.validateLineCheckSum("00000000000000000-0000000001"));
69          assertFalse(CheckSumTerm.validateLineCheckSum("00000000000000000-0000000000"));
70          assertTrue(CheckSumTerm.validateLineCheckSum("00000000000000000 0000000000"));
71          assertFalse(CheckSumTerm.validateLineCheckSum("00000000000000000 0000000001"));
72  
73          // Verify checksum computation
74          MessageClassTerm term1 = MessageClassTerm.NOMINAL; // "10" = 1 + 0 = 1
75          DayOfYearTerm term2 = new DayOfYearTerm(202); // "202" = 2+0+2 = 4
76          VelocityVectorComponentTerm term3 = new VelocityVectorComponentTerm(-5.211); // "-5.211" = 1+5+2+1+1 = 10
77  
78          assertEquals(1, CheckSumTerm.fromIIRVTerms(term1).value());
79          assertEquals(4, CheckSumTerm.fromIIRVTerms(term2).value());
80          assertEquals(10, CheckSumTerm.fromIIRVTerms(term3).value());
81          assertEquals(15, CheckSumTerm.fromIIRVTerms(term1, term2, term3).value());
82      }
83  
84      /**
85       * Test initialization of {@link org.orekit.files.iirv.terms.CoordinateSystemTerm}
86       */
87      @Test
88      void testCoordinateSystemTerm() {
89  
90  
91          // Check all the valid values
92          assertEquals(new CoordinateSystemTerm("1"), CoordinateSystemTerm.GEOCENTRIC_TRUE_OF_DATE_ROTATING);
93          assertEquals(new CoordinateSystemTerm("2"), CoordinateSystemTerm.GEOCENTRIC_MEAN_B1950);
94          assertEquals(new CoordinateSystemTerm("3"), CoordinateSystemTerm.HELIOCENTRIC_B1950);
95          assertEquals(new CoordinateSystemTerm("4"), CoordinateSystemTerm.JPL_RESERVED_1);
96          assertEquals(new CoordinateSystemTerm("5"), CoordinateSystemTerm.JPL_RESERVED_2);
97          assertEquals(new CoordinateSystemTerm("6"), CoordinateSystemTerm.GEOCENTRIC_MEAN_OF_J2000);
98          assertEquals(new CoordinateSystemTerm("7"), CoordinateSystemTerm.HELIOCENTRIC_J2000);
99  
100         // Verify initialization is same from string/integer
101         assertEquals(new CoordinateSystemTerm("6"), new CoordinateSystemTerm(6));
102 
103         // hashCode
104         assertEquals(new CoordinateSystemTerm("6").hashCode(), new CoordinateSystemTerm(6).hashCode());
105 
106         // Verify errors are thrown for incorrect inputs
107         assertThrows(OrekitIllegalArgumentException.class, () -> new CoordinateSystemTerm("0"));
108         assertThrows(OrekitIllegalArgumentException.class, () -> new CoordinateSystemTerm("-1"));
109         assertThrows(OrekitIllegalArgumentException.class, () -> new CoordinateSystemTerm(" 1"));
110         assertThrows(OrekitIllegalArgumentException.class, () -> new CoordinateSystemTerm("1 "));
111         assertThrows(OrekitIllegalArgumentException.class, () -> new CoordinateSystemTerm(0));
112         assertThrows(OrekitIllegalArgumentException.class, () -> new CoordinateSystemTerm(-1));
113         assertThrows(OrekitIllegalArgumentException.class, () -> new CoordinateSystemTerm(8));
114         assertThrows(OrekitIllegalArgumentException.class, () -> new CoordinateSystemTerm("8"));
115 
116         // Verify Orekit frame retrieval
117         assertEquals("GTOD/2010 simple EOP", CoordinateSystemTerm.GEOCENTRIC_TRUE_OF_DATE_ROTATING.getFrame().toString());
118         assertEquals("EME2000", CoordinateSystemTerm.GEOCENTRIC_MEAN_OF_J2000.getFrame().toString());
119         assertEquals("Sun/inertial", CoordinateSystemTerm.HELIOCENTRIC_J2000.getFrame().toString());
120 
121         // Unmapped frames
122         assertThrows(OrekitException.class, CoordinateSystemTerm.GEOCENTRIC_MEAN_B1950::getFrame);
123         assertThrows(OrekitException.class, CoordinateSystemTerm.HELIOCENTRIC_B1950::getFrame);
124         assertThrows(OrekitException.class, CoordinateSystemTerm.JPL_RESERVED_1::getFrame);
125         assertThrows(OrekitException.class, CoordinateSystemTerm.JPL_RESERVED_2::getFrame);
126         assertThrows(OrekitException.class, CoordinateSystemTerm.JPL_RESERVED_2::getFrame);
127     }
128 
129     /**
130      * Test initialization of {@link org.orekit.files.iirv.terms.CrossSectionalAreaTerm}
131      */
132     @Test
133     void testCrossSectionalAreaTerm() {
134         assertEquals(CrossSectionalAreaTerm.UNUSED, new CrossSectionalAreaTerm(0));
135 
136         assertEquals(new CrossSectionalAreaTerm("23181"), new CrossSectionalAreaTerm(231.81));
137         assertEquals(new CrossSectionalAreaTerm("23181"), new CrossSectionalAreaTerm(231.811));
138         assertEquals(new CrossSectionalAreaTerm("23181"), new CrossSectionalAreaTerm(231.808));
139 
140         assertEquals(new CrossSectionalAreaTerm("23181").hashCode(), new CrossSectionalAreaTerm(231.808).hashCode());
141     }
142 
143     /**
144      * Test initialization of {@link org.orekit.files.iirv.terms.DataSourceTerm}
145      */
146     @Test
147     void testDataSourceTerm() {
148         assertEquals(DataSourceTerm.NOMINAL, new DataSourceTerm("1"));
149         assertEquals(DataSourceTerm.NOMINAL, new DataSourceTerm(1));
150         assertEquals(DataSourceTerm.REAL_TIME, new DataSourceTerm("2"));
151         assertEquals(DataSourceTerm.REAL_TIME, new DataSourceTerm(2));
152         assertEquals(DataSourceTerm.OFFLINE, new DataSourceTerm("3"));
153         assertEquals(DataSourceTerm.OFFLINE, new DataSourceTerm(3));
154         assertEquals(DataSourceTerm.OFFLINE_MEAN, new DataSourceTerm("4"));
155         assertEquals(DataSourceTerm.OFFLINE_MEAN, new DataSourceTerm(4));
156     }
157 
158     /**
159      * Test initialization of {@link org.orekit.files.iirv.terms.DragCoefficientTerm}
160      */
161     @Test
162     void testDragCoefficientTerm() {
163         assertEquals(new DragCoefficientTerm("1234"), new DragCoefficientTerm(12.34));
164         assertEquals(DragCoefficientTerm.UNUSED, new DragCoefficientTerm(0));
165 
166     }
167 
168     /**
169      * Test initialization of {@link org.orekit.files.iirv.terms.MassTerm}
170      */
171     @Test
172     void testMassTerm() {
173         assertEquals(new MassTerm("00010000"), new MassTerm(1000.0));
174         assertEquals(MassTerm.UNUSED, new MassTerm(0));
175     }
176 
177     /**
178      * Test initialization of {@link org.orekit.files.iirv.terms.MessageClassTerm}
179      */
180     @Test
181     void testMessageClassTerm() {
182         assertEquals(MessageClassTerm.NOMINAL, new MessageClassTerm(10));
183         assertEquals(MessageClassTerm.NOMINAL, new MessageClassTerm("10"));
184         assertEquals(MessageClassTerm.INFLIGHT_UPDATE, new MessageClassTerm(15));
185         assertEquals(MessageClassTerm.INFLIGHT_UPDATE, new MessageClassTerm("15"));
186 
187         // Check rejected
188         assertThrows(OrekitIllegalArgumentException.class, () -> new MessageClassTerm(1));
189         assertThrows(OrekitIllegalArgumentException.class, () -> new MessageClassTerm("1"));
190         assertThrows(OrekitIllegalArgumentException.class, () -> new MessageClassTerm(-10));
191     }
192 
193     /**
194      * Test initialization of {@link org.orekit.files.iirv.terms.MessageEndConstantTerm}
195      */
196     @Test
197     void testMessageEndConstantTerm() {
198         assertEquals(new MessageEndConstantTerm().value(), "ITERM");
199         assertEquals(new MessageEndConstantTerm().value(), MessageEndConstantTerm.MESSAGE_END_TERM_STRING);
200     }
201 
202     /**
203      * Test initialization of {@link org.orekit.files.iirv.terms.MessageIDTerm}
204      */
205     @Test
206     void testMessageIDTerm() {
207         assertEquals(new MessageIDTerm(9381225), new MessageIDTerm("9381225"));
208 
209         // Check non-number within string
210         assertThrows(OrekitIllegalArgumentException.class, () -> new MessageIDTerm("938122A"));
211     }
212 
213     /**
214      * Test initialization of {@link MessageSourceTerm}
215      */
216     @Test
217     void testMessageSourceConstantTerm() {
218         assertEquals("0", MessageSourceTerm.DEFAULT.value());
219         assertEquals("0", new MessageSourceTerm("0").value());
220         assertEquals("A", new MessageSourceTerm("A").value());
221         assertEquals("a", new MessageSourceTerm("a").value());
222 
223         assertThrows(OrekitIllegalArgumentException.class, () -> new MessageSourceTerm(","));
224         assertThrows(OrekitIllegalArgumentException.class, () -> new MessageSourceTerm(""));
225     }
226 
227     /**
228      * Test initialization of {@link org.orekit.files.iirv.terms.MessageStartConstantTerm}
229      */
230     @Test
231     void testMessageStartConstantTerm() {
232         assertEquals("GIIRV", new MessageStartConstantTerm().value());
233     }
234 
235     /**
236      * Test initialization of {@link MessageTypeTerm}
237      */
238     @Test
239     void testMessageTypeConstantTerm() {
240         assertEquals(new MessageTypeTerm("03"), MessageTypeTerm.DEFAULT);
241         assertEquals("03", new MessageTypeTerm("03").value());
242         assertEquals("B9", new MessageTypeTerm("B9").value());
243         assertEquals("a ", new MessageTypeTerm("a ").value());
244 
245         assertThrows(OrekitIllegalArgumentException.class, () -> new MessageTypeTerm("$2"));
246         assertThrows(OrekitIllegalArgumentException.class, () -> new MessageTypeTerm("222"));
247         assertThrows(OrekitIllegalArgumentException.class, () -> new MessageTypeTerm("q"));
248     }
249 
250     /**
251      * Test initialization of {@link org.orekit.files.iirv.terms.OriginatorRoutingIndicatorTerm}
252      */
253     @Test
254     void testOriginatorRoutingIndicatorTerm() {
255         assertEquals(new OriginatorRoutingIndicatorTerm("GCQU"), OriginatorRoutingIndicatorTerm.GCQU);
256         assertEquals(new OriginatorRoutingIndicatorTerm("GAQD"), OriginatorRoutingIndicatorTerm.GAQD);
257     }
258 
259     /**
260      * Test initialization of {@link org.orekit.files.iirv.terms.OriginIdentificationTerm}
261      */
262     @Test
263     void testOriginIdentificationTerm() {
264         assertEquals(new OriginIdentificationTerm(" "), OriginIdentificationTerm.GSFC);
265         assertEquals(new OriginIdentificationTerm("Z"), OriginIdentificationTerm.WLP);
266         assertEquals(new OriginIdentificationTerm("E"), OriginIdentificationTerm.ETR);
267         assertEquals(new OriginIdentificationTerm("L"), OriginIdentificationTerm.JPL);
268         assertEquals(new OriginIdentificationTerm("W"), OriginIdentificationTerm.WTR);
269         assertEquals(new OriginIdentificationTerm("J"), OriginIdentificationTerm.JSC);
270         assertEquals(new OriginIdentificationTerm("P"), OriginIdentificationTerm.PMR);
271         assertEquals(new OriginIdentificationTerm("A"), OriginIdentificationTerm.CSTC);
272         assertEquals(new OriginIdentificationTerm("K"), OriginIdentificationTerm.KMR);
273         assertEquals(new OriginIdentificationTerm("C"), OriginIdentificationTerm.CNES);
274 
275         // Check can't initialize from the name of the originator string
276         assertThrows(OrekitIllegalArgumentException.class, () -> new OriginIdentificationTerm("GSFC"));
277     }
278 
279     /**
280      * Test initialization of {@link org.orekit.files.iirv.terms.PositionVectorComponentTerm} and
281      * {@link org.orekit.files.iirv.terms.base.DoubleValuedIIRVTerm}
282      */
283     @Test
284     void testPositionVectorComponentTerm() {
285 
286         // Verify: initializes correctly from positive double
287         assertEquals(new PositionVectorComponentTerm(1800799.012), new PositionVectorComponentTerm(" 000001800799"));
288 
289         // Verify: initializes correctly from negative double
290         assertEquals(new PositionVectorComponentTerm(-2068482.799), new PositionVectorComponentTerm("-000002068483"));
291 
292         // Verify: initializes correctly from positive integer
293         final int posComponentInt = 2954112;
294         final long posComponentLong = 2954112L;
295         final String posComponentString = " 000002954112";
296         assertEquals(new PositionVectorComponentTerm(posComponentInt), new PositionVectorComponentTerm(posComponentString));
297 
298         // Verify: initializes correctly from positive long
299         assertEquals(new PositionVectorComponentTerm(posComponentLong), new PositionVectorComponentTerm(posComponentInt));
300 
301         // Verify: initializes correctly from negative integer
302         assertEquals(new PositionVectorComponentTerm(-2954112), new PositionVectorComponentTerm("-000002954112"));
303 
304         // Verify: toInt method works as expected
305         assertEquals(posComponentInt, new PositionVectorComponentTerm(posComponentLong).toInt());
306 
307         // Verify: value computation from integer (never used, but doesn't hurt to check in case of updates to term formats)
308         assertEquals(1234, DoubleValuedIIRVTerm.computeValueFromString("1234", 0));
309 
310         // Check for error: initialize with wrong number of characters (too few)
311         assertThrows(OrekitIllegalArgumentException.class, () -> new PositionVectorComponentTerm(" 00000799"));
312 
313         // Check for error: initialize with wrong number of characters (too many)
314         assertThrows(OrekitIllegalArgumentException.class, () -> new PositionVectorComponentTerm(" 00000000000000799"));
315 
316         // Check for error: initialize with non-numeric character
317         assertThrows(OrekitIllegalArgumentException.class, () -> new PositionVectorComponentTerm(" 0000079a"));
318 
319         // Check for error: initialize with no sign character
320         assertThrows(OrekitIllegalArgumentException.class, () -> new PositionVectorComponentTerm("0000001800799"));
321 
322         // Check for error: initialize with number that is too large for the maximum precision
323         assertThrows(OrekitIllegalArgumentException.class, () -> new PositionVectorComponentTerm(99999999999991L));
324         assertThrows(OrekitIllegalArgumentException.class, () -> new PositionVectorComponentTerm(-99999999999991L));
325 
326         // Check that +/- zero are the same
327         PositionVectorComponentTerm positiveZero = new PositionVectorComponentTerm(" 000000000000");
328         PositionVectorComponentTerm negativeZero = new PositionVectorComponentTerm("-000000000000");
329         assertEquals(positiveZero.toInt(), negativeZero.toInt());
330         assertEquals(positiveZero.value(), negativeZero.value());
331         assertEquals(positiveZero.toEncodedString(), negativeZero.toEncodedString());
332     }
333 
334     /**
335      * Test initialization of {@link org.orekit.files.iirv.terms.RoutingIndicatorTerm}
336      */
337     @Test
338     void testRoutingIndicatorTerm() {
339         assertEquals(new RoutingIndicatorTerm("GSFC"), RoutingIndicatorTerm.GSFC);
340         assertEquals(new RoutingIndicatorTerm(" WLP"), RoutingIndicatorTerm.WLP);
341         assertEquals(new RoutingIndicatorTerm(" ETR"), RoutingIndicatorTerm.ETR);
342         assertEquals(new RoutingIndicatorTerm(" JPL"), RoutingIndicatorTerm.JPL);
343         assertEquals(new RoutingIndicatorTerm(" WTR"), RoutingIndicatorTerm.WTR);
344         assertEquals(new RoutingIndicatorTerm(" JSC"), RoutingIndicatorTerm.JSC);
345         assertEquals(new RoutingIndicatorTerm(" PMR"), RoutingIndicatorTerm.PMR);
346         assertEquals(new RoutingIndicatorTerm("CSTC"), RoutingIndicatorTerm.CSTC);
347         assertEquals(new RoutingIndicatorTerm(" KMR"), RoutingIndicatorTerm.KMR);
348         assertEquals(new RoutingIndicatorTerm("CNES"), RoutingIndicatorTerm.CNES);
349         assertEquals(new RoutingIndicatorTerm("MANY"), RoutingIndicatorTerm.MANY);
350 
351         // Check can't initialize from the name of the originator string
352         assertThrows(OrekitIllegalArgumentException.class, () -> new RoutingIndicatorTerm(" "));
353 
354         // Check that a space is needed before three-character ones
355         assertThrows(OrekitIllegalArgumentException.class, () -> new RoutingIndicatorTerm("KMR"));
356     }
357 
358     /**
359      * Test initialization of {@link org.orekit.files.iirv.terms.SequenceNumberTerm}
360      */
361     @Test
362     void testSequenceNumberTerm() {
363         assertEquals(new SequenceNumberTerm("000"), new SequenceNumberTerm(0));
364         assertEquals(new SequenceNumberTerm("123"), new SequenceNumberTerm(123));
365 
366         // Check min/max
367         assertThrows(OrekitIllegalArgumentException.class, () -> new SequenceNumberTerm(-1));
368         assertThrows(OrekitIllegalArgumentException.class, () -> new SequenceNumberTerm(1000));
369     }
370 
371     /**
372      * Test initialization of {@link org.orekit.files.iirv.terms.SolarReflectivityCoefficientTerm}
373      */
374     @Test
375     void testSolarReflectivityCoefficientTerm() {
376 
377         // Test string vs int
378         assertEquals(new SolarReflectivityCoefficientTerm(" 1000000"), new SolarReflectivityCoefficientTerm(1));
379 
380         // Test unused
381         assertEquals(SolarReflectivityCoefficientTerm.UNUSED, new SolarReflectivityCoefficientTerm(0));
382 
383         // Test negative
384         assertEquals(new SolarReflectivityCoefficientTerm("-1000001"), new SolarReflectivityCoefficientTerm(-1.000001));
385 
386         // Test rounding
387         assertEquals(new SolarReflectivityCoefficientTerm("-1000001"), new SolarReflectivityCoefficientTerm(-1.0000006));
388 
389         // Test overflow checking
390         assertThrows(OrekitIllegalArgumentException.class, () -> new SolarReflectivityCoefficientTerm(10));
391     }
392 
393     /**
394      * Test initialization of {@link org.orekit.files.iirv.terms.SpareConstantTerm}
395      */
396     @Test
397     void testSpareConstantTerm() {
398         assertEquals(new SpareConstantTerm().value(), " ");
399         assertEquals(new SpareConstantTerm().value(), SpareConstantTerm.SPARE_TERM_STRING);
400     }
401 
402     /**
403      * Test initialization of {@link org.orekit.files.iirv.terms.SupportIdCodeTerm}
404      */
405     @Test
406     void testSupportIdCodeTerm() {
407         assertEquals(new SupportIdCodeTerm("3254"), new SupportIdCodeTerm(3254));
408 
409         // Check min/max
410         assertThrows(OrekitIllegalArgumentException.class, () -> new SupportIdCodeTerm(-1));
411         assertThrows(OrekitIllegalArgumentException.class, () -> new SupportIdCodeTerm(10000));
412     }
413 
414     /**
415      * Test initialization of {@link org.orekit.files.iirv.terms.TransferTypeConstantTerm}
416      */
417     @Test
418     void testTransferTypeConstantTerm() {
419         assertEquals(new TransferTypeConstantTerm().value(), "1");
420         assertEquals(new TransferTypeConstantTerm().value(), TransferTypeConstantTerm.TRANSFER_TYPE_TERM_STRING);
421     }
422 
423     /**
424      * Test initialization of {@link org.orekit.files.iirv.terms.VectorTypeTerm}
425      */
426     @Test
427     void testVectorTypeTerm() {
428         assertEquals(VectorTypeTerm.FREE_FLIGHT, new VectorTypeTerm("1"));
429         assertEquals(VectorTypeTerm.FORCED, new VectorTypeTerm("2"));
430         assertEquals(VectorTypeTerm.SPARE3, new VectorTypeTerm("3"));
431         assertEquals(VectorTypeTerm.MANEUVER_IGNITION, new VectorTypeTerm("4"));
432         assertEquals(VectorTypeTerm.MANEUVER_CUTOFF, new VectorTypeTerm("5"));
433         assertEquals(VectorTypeTerm.REENTRY, new VectorTypeTerm("6"));
434         assertEquals(VectorTypeTerm.POWERED_FLIGHT, new VectorTypeTerm("7"));
435         assertEquals(VectorTypeTerm.STATIONARY, new VectorTypeTerm("8"));
436         assertEquals(VectorTypeTerm.SPARE9, new VectorTypeTerm("9"));
437 
438         // Init from integer
439         assertEquals(new VectorTypeTerm(8), new VectorTypeTerm("8"));
440     }
441 
442     /**
443      * Test initialization of {@link org.orekit.files.iirv.terms.VehicleIdCodeTerm}
444      */
445     @Test
446     void testVehicleIdCodeTerm() {
447         assertEquals(VehicleIdCodeTerm.DEFAULT, new VehicleIdCodeTerm(1));
448         assertEquals(new VehicleIdCodeTerm(2), new VehicleIdCodeTerm("02"));
449 
450         // 0 not allowed
451         assertThrows(OrekitIllegalArgumentException.class, () -> new VehicleIdCodeTerm(0));
452 
453         // Single digit
454         assertThrows(OrekitIllegalArgumentException.class, () -> new VehicleIdCodeTerm("1"));
455     }
456 
457     /**
458      * Test initialization of {@link org.orekit.files.iirv.terms.VelocityVectorComponentTerm} and
459      * {@link org.orekit.files.iirv.terms.base.DoubleValuedIIRVTerm}
460      */
461     @Test
462     void testVelocityVectorComponentTerm() {
463 
464         // Verify: initializes correctly from positive double
465         assertEquals(new VelocityVectorComponentTerm(1800.799), new VelocityVectorComponentTerm(" 000001800799"));
466 
467         // Verify: initializes correctly from negative double
468         assertEquals(new VelocityVectorComponentTerm(-1800.799), new VelocityVectorComponentTerm("-000001800799"));
469 
470         // Verify: initializes correctly from positive integer
471         assertEquals(new VelocityVectorComponentTerm(1800), new VelocityVectorComponentTerm(" 000001800000"));
472 
473         // Verify: initializes correctly from positive long
474         assertEquals(new VelocityVectorComponentTerm(1800L), new VelocityVectorComponentTerm(1800));
475 
476         // Verify: initializes correctly from negative integer
477         assertEquals(new VelocityVectorComponentTerm(-1800), new VelocityVectorComponentTerm("-000001800000"));
478 
479         // Verify: correctly rounds up to integer
480         assertEquals(new VelocityVectorComponentTerm(1800.99999), new VelocityVectorComponentTerm(" 000001801000"));
481 
482         // Verify: correctly rounds up to ones place
483         assertEquals(new VelocityVectorComponentTerm(1800.7999), new VelocityVectorComponentTerm(" 000001800800"));
484 
485         // Verify: correctly rounds down to integer
486         assertEquals(new VelocityVectorComponentTerm(1800.00001), new VelocityVectorComponentTerm(" 000001800000"));
487 
488         // Verify: correctly rounds down to floating point
489         assertEquals(new VelocityVectorComponentTerm(1800.7991), new VelocityVectorComponentTerm(" 000001800799"));
490 
491         // Verify: correctly rounds up to floating point
492         assertEquals(new VelocityVectorComponentTerm(1800.7925), new VelocityVectorComponentTerm(" 000001800793"));
493 
494         // Verify: correctly rounds negative number
495         assertEquals(new VelocityVectorComponentTerm(-1800.7999), new VelocityVectorComponentTerm("-000001800800"));
496 
497         // Verify: same hash code
498         assertEquals(new VelocityVectorComponentTerm(1800.799).hashCode(), new VelocityVectorComponentTerm(" 000001800799").hashCode());
499 
500         // Check that +/- zero are the same
501         VelocityVectorComponentTerm posZeroOne = new VelocityVectorComponentTerm(" 000000000000");
502         VelocityVectorComponentTerm posZeroTwo = new VelocityVectorComponentTerm(1e-16);
503         VelocityVectorComponentTerm negZeroOne = new VelocityVectorComponentTerm("-000000000000");
504         VelocityVectorComponentTerm negZeroTwo = new VelocityVectorComponentTerm(-1e-16);
505         assertEquals(posZeroOne.toEncodedString(), posZeroTwo.toEncodedString());
506         assertEquals(posZeroOne.toEncodedString(), negZeroOne.toEncodedString());
507         assertEquals(posZeroOne.toEncodedString(), negZeroTwo.toEncodedString());
508 
509         // Check for error: initialize with wrong number of characters (too few)
510         assertThrows(OrekitIllegalArgumentException.class, () -> new VelocityVectorComponentTerm(" 00000799"));
511 
512         // Check for error: initialize with wrong number of characters (too many)
513         assertThrows(OrekitIllegalArgumentException.class, () -> new VelocityVectorComponentTerm(" 00000000000000799"));
514 
515         // Check for error: initialize with non-numeric character
516         assertThrows(OrekitIllegalArgumentException.class, () -> new VelocityVectorComponentTerm(" 0000079a"));
517 
518         // Check for error: initialize with no sign character
519         assertThrows(OrekitIllegalArgumentException.class, () -> new VelocityVectorComponentTerm("0000001800799"));
520 
521         // Check for error: initialize with number that is too large for the maximum precision
522         assertThrows(OrekitIllegalArgumentException.class, () -> new VelocityVectorComponentTerm(9999999999.999));
523         assertThrows(OrekitIllegalArgumentException.class, () -> new VelocityVectorComponentTerm(-9999999999.999));
524 
525 
526     }
527 
528     /**
529      * Test line padding manipulation, implemented in {@link org.orekit.files.iirv.terms.IIRVTermUtils#addPadding}
530      */
531     @Test
532     void testLinePadding() {
533         final String testString = "X";
534 
535         assertEquals("--X", IIRVTermUtils.addPadding(testString, '-', 3, true));
536         assertEquals("X--", IIRVTermUtils.addPadding(testString, '-', 3, false));
537         assertEquals("---", IIRVTermUtils.addPadding("", '-', 3, false));
538 
539         // Negative value input for size
540         assertThrows(OrekitException.class, () -> IIRVTermUtils.addPadding(testString, '-', -1, true));
541 
542     }
543 }