1   /* Copyright 2022-2025 Romain Serra
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.propagation.sampling;
18  
19  import org.hipparchus.util.Binary64;
20  import org.hipparchus.util.Binary64Field;
21  import org.junit.jupiter.api.Test;
22  import org.orekit.TestUtils;
23  import org.orekit.propagation.FieldSpacecraftState;
24  import org.orekit.propagation.SpacecraftState;
25  import org.orekit.time.AbsoluteDate;
26  import org.orekit.time.FieldAbsoluteDate;
27  
28  import java.util.List;
29  
30  import static org.junit.jupiter.api.Assertions.assertEquals;
31  
32  class FieldPropagationStepRecorderTest {
33  
34      @Test
35      void copyStatesAtConstructionTest() {
36          // GIVEN
37          final FieldPropagationStepRecorder<Binary64> recorder = new FieldPropagationStepRecorder<>();
38          // WHEN
39          final List<FieldSpacecraftState<Binary64>> states = recorder.copyStates();
40          // THEN
41          assertEquals(0, states.size());
42      }
43  
44      @Test
45      void copyStatesTest() {
46          // GIVEN
47          final FieldPropagationStepRecorder<Binary64> recorder = new FieldPropagationStepRecorder<>();
48          final FieldOrekitStepInterpolator<Binary64> interpolator = createInterpolator();
49          recorder.handleStep(interpolator);
50          // WHEN
51          recorder.init(createState(), FieldAbsoluteDate.getArbitraryEpoch(Binary64Field.getInstance()));
52          // THEN
53          final List<FieldSpacecraftState<Binary64>> states = recorder.copyStates();
54          assertEquals(0, states.size());
55      }
56  
57      @Test
58      void handleStepTest() {
59          // GIVEN
60          final FieldPropagationStepRecorder<Binary64> recorder = new FieldPropagationStepRecorder<>();
61          final FieldOrekitStepInterpolator<Binary64> interpolator = createInterpolator();
62          final int expectedSize = 10;
63          // WHEN
64          for (int i = 0; i < expectedSize; ++i) {
65              recorder.handleStep(interpolator);
66          }
67          // WHEN
68          final List<FieldSpacecraftState<Binary64>> states = recorder.copyStates();
69          assertEquals(expectedSize, states.size());
70      }
71  
72      private static FieldOrekitStepInterpolator<Binary64> createInterpolator() {
73          return new FieldOrekitStepInterpolator<Binary64>() {
74              @Override
75              public FieldSpacecraftState<Binary64> getPreviousState() {
76                  return null;
77              }
78  
79              @Override
80              public FieldSpacecraftState<Binary64> getCurrentState() {
81                  return createState();
82              }
83  
84              @Override
85              public FieldSpacecraftState<Binary64> getInterpolatedState(FieldAbsoluteDate<Binary64> date) {
86                  return null;
87              }
88  
89              @Override
90              public boolean isForward() {
91                  return false;
92              }
93  
94              @Override
95              public FieldOrekitStepInterpolator<Binary64> restrictStep(FieldSpacecraftState<Binary64> newPreviousState, FieldSpacecraftState<Binary64> newCurrentState) {
96                  return null;
97              }
98          };
99      }
100 
101     private static FieldSpacecraftState<Binary64> createState() {
102         final SpacecraftState state = new SpacecraftState(TestUtils.getDefaultOrbit(AbsoluteDate.ARBITRARY_EPOCH));
103         return new FieldSpacecraftState<>(Binary64Field.getInstance(), state);
104     }
105 }