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