1   /* Copyright 2022-2025 Thales Alenia Space
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  import org.hipparchus.CalculusFieldElement;
20  import org.hipparchus.Field;
21  import org.hipparchus.util.Binary64Field;
22  import org.junit.jupiter.api.Assertions;
23  import org.junit.jupiter.api.BeforeEach;
24  import org.junit.jupiter.api.Test;
25  import org.orekit.Utils;
26  
27  public class PerfectClockModelTest {
28  
29      @Test
30      public void testZero() {
31          final AbsoluteDate       t0      = new AbsoluteDate(2020, 4, 1, TimeScalesFactory.getUTC());
32          final PerfectClockModel clockModel = new PerfectClockModel();
33          for (double dt = 0.02; dt < 0.98; dt += 0.02) {
34              final ClockOffset co = clockModel.getOffset(t0.shiftedBy(dt));
35              Assertions.assertEquals(dt, co.getDate().durationFrom(t0), 1.0e-15);
36              Assertions.assertEquals(0,  co.getOffset(),                1.0e-15);
37              Assertions.assertEquals(0,  co.getRate(),                  1.0e-15);
38              Assertions.assertEquals(0,  co.getAcceleration(),          1.0e-15);
39          }
40  
41      }
42  
43      @Test
44      public void testZeroField() {
45          doTestZero(Binary64Field.getInstance());
46      }
47  
48      public <T extends CalculusFieldElement<T>> void doTestZero(final Field<T> field) {
49          final AbsoluteDate         t0  = new AbsoluteDate(2020, 4, 1, TimeScalesFactory.getUTC());
50          final FieldAbsoluteDate<T> t0F = new FieldAbsoluteDate<>(field, t0);
51          final PerfectClockModel clockModel = new PerfectClockModel();
52          for (double dt = 0.02; dt < 0.98; dt += 0.02) {
53              final T dtF = field.getZero().newInstance(dt);
54              final FieldClockOffset<T> co = clockModel.getOffset(t0F.shiftedBy(dtF));
55              Assertions.assertEquals(dt, co.getDate().durationFrom(t0).getReal(), 1.0e-15);
56              Assertions.assertEquals(0,  co.getOffset().getReal(),                1.0e-15);
57              Assertions.assertEquals(0,  co.getRate().getReal(),                  1.0e-15);
58              Assertions.assertEquals(0,  co.getAcceleration().getReal(),          1.0e-15);
59          }
60      }
61  
62      @BeforeEach
63      public void setUp() throws Exception {
64          Utils.setDataRoot("regular-data");
65      }
66  
67  }