1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.orekit.time;
18
19 import org.junit.jupiter.api.Assertions;
20 import org.junit.jupiter.api.Test;
21 import org.orekit.Utils;
22 import org.orekit.errors.OrekitException;
23 import org.orekit.errors.OrekitMessages;
24
25 public class AGILeapSecondFilesLoaderTest {
26
27 @Test
28 public void testRegularFile() {
29
30 Utils.setDataRoot("AGI");
31
32
33 checkOffset(1950, 1, 1, 0);
34
35
36 checkOffset(1961, 1, 2, -(1.422818 + 1 * 0.001296));
37 checkOffset(1961, 8, 2, -(1.372818 + 213 * 0.001296));
38 checkOffset(1962, 1, 2, -(1.845858 + 1 * 0.0011232));
39 checkOffset(1963, 11, 2, -(1.945858 + 670 * 0.0011232));
40 checkOffset(1964, 1, 2, -(3.240130 - 365 * 0.001296));
41 checkOffset(1964, 4, 2, -(3.340130 - 274 * 0.001296));
42 checkOffset(1964, 9, 2, -(3.440130 - 121 * 0.001296));
43 checkOffset(1965, 1, 2, -(3.540130 + 1 * 0.001296));
44 checkOffset(1965, 3, 2, -(3.640130 + 60 * 0.001296));
45 checkOffset(1965, 7, 2, -(3.740130 + 182 * 0.001296));
46 checkOffset(1965, 9, 2, -(3.840130 + 244 * 0.001296));
47 checkOffset(1966, 1, 2, -(4.313170 + 1 * 0.002592));
48 checkOffset(1968, 2, 2, -(4.213170 + 762 * 0.002592));
49
50
51 checkOffset(1972, 3, 5, -10);
52 checkOffset(1972, 7, 14, -11);
53 checkOffset(1979, 12, 31, -18);
54 checkOffset(1980, 1, 22, -19);
55 checkOffset(2006, 7, 7, -33);
56 checkOffset(2010, 7, 7, -34);
57 checkOffset(2012, 7, 7, -35);
58 checkOffset(2015, 7, 7, -36);
59
60 }
61
62 @Test
63 public void testInconsistentDate() {
64 checkException("LeapSecond-inconsistent-date.dat",
65 OrekitMessages.INCONSISTENT_DATES_IN_IERS_FILE);
66 }
67
68 @Test
69 public void testNonChronological() {
70 checkException("LeapSecond-non-chronological.dat",
71 OrekitMessages.NON_CHRONOLOGICAL_DATES_IN_FILE);
72 }
73
74 @Test
75 public void testFormatError() {
76 checkException("LeapSecond-format-error.dat",
77 OrekitMessages.UNABLE_TO_PARSE_LINE_IN_FILE);
78 }
79
80 private void checkOffset(int year, int month, int day, double offset) {
81 TimeScale utc = TimeScalesFactory.getUTC();
82 AbsoluteDate date = new AbsoluteDate(year, month, day, utc);
83 Assertions.assertEquals(offset, utc.offsetFromTAI(date).toDouble(), 1.0e-10);
84 }
85
86 private void checkException(String name, OrekitMessages message) {
87 Utils.setDataRoot("AGI");
88 TimeScalesFactory.addUTCTAIOffsetsLoader(new AGILeapSecondFilesLoader(name));
89 try {
90 TimeScalesFactory.getUTC();
91 Assertions.fail("an exception should have been thrown");
92 } catch (OrekitException oe) {
93 Assertions.assertEquals(message, oe.getSpecifier());
94 }
95 }
96
97 }