1   /* Copyright 2002-2022 CS GROUP
2    * Licensed to CS GROUP (CS) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * CS licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.orekit.time;
18  
19  
20  
21  import org.junit.Assert;
22  import org.junit.Before;
23  import org.junit.Test;
24  import org.orekit.Utils;
25  import org.orekit.utils.Constants;
26  
27  public class IRNSSScaleTest {
28  
29      @Test
30      public void testArbitrary() {
31          AbsoluteDate tIRNSS =
32              new AbsoluteDate(new DateComponents(1999, 3, 4), TimeComponents.H00, TimeScalesFactory.getIRNSS());
33          AbsoluteDate tUTC =
34              new AbsoluteDate(new DateComponents(1999, 3, 3), new TimeComponents(23, 59, 47),
35                               TimeScalesFactory.getUTC());
36          Assert.assertEquals(tUTC, tIRNSS);
37      }
38  
39      @Test
40      public void testConstant() {
41          TimeScale scale = TimeScalesFactory.getIRNSS();
42          double reference = scale.offsetFromTAI(AbsoluteDate.J2000_EPOCH);
43          for (double dt = -10000; dt < 10000; dt += 123.456789) {
44              AbsoluteDate date = AbsoluteDate.J2000_EPOCH.shiftedBy(dt * Constants.JULIAN_DAY);
45              Assert.assertEquals(reference, scale.offsetFromTAI(date), 1.0e-15);
46          }
47      }
48  
49      @Test
50      public void testSymmetry() {
51          TimeScale scale = TimeScalesFactory.getIRNSS();
52          for (double dt = -10000; dt < 10000; dt += 123.456789) {
53              AbsoluteDate date = AbsoluteDate.J2000_EPOCH.shiftedBy(dt * Constants.JULIAN_DAY);
54              double dt1 = scale.offsetFromTAI(date);
55              DateTimeComponents components = date.getComponents(scale);
56              double dt2 = scale.offsetToTAI(components.getDate(), components.getTime());
57              Assert.assertEquals( 0.0, dt1 + dt2, 1.0e-10);
58          }
59      }
60  
61      @Test
62      public void testDuringLeap() {
63          final TimeScale utc   = TimeScalesFactory.getUTC();
64          final TimeScale scale = TimeScalesFactory.getIRNSS();
65          final AbsoluteDate before = new AbsoluteDate(new DateComponents(1983, 06, 30),
66                                                       new TimeComponents(23, 59, 59),
67                                                       utc);
68          final AbsoluteDate during = before.shiftedBy(1.25);
69          Assert.assertEquals(61, utc.minuteDuration(during));
70          Assert.assertEquals(1.0, utc.getLeap(during), 1.0e-10);
71          Assert.assertEquals(60, scale.minuteDuration(during));
72          Assert.assertEquals(0.0, scale.getLeap(during), 1.0e-10);
73      }
74  
75      @Before
76      public void setUp() {
77          Utils.setDataRoot("regular-data");
78      }
79  
80  }