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.junit.jupiter.params.ParameterizedTest;
23  import org.junit.jupiter.params.provider.ValueSource;
24  import org.orekit.TestUtils;
25  import org.orekit.propagation.FieldSpacecraftState;
26  import org.orekit.propagation.SpacecraftState;
27  import org.orekit.time.AbsoluteDate;
28  import org.orekit.time.FieldAbsoluteDate;
29  
30  import java.util.List;
31  
32  import static org.junit.jupiter.api.Assertions.assertEquals;
33  
34  class FieldPropagationStepRecorderTest {
35  
36      @ParameterizedTest
37      @ValueSource(booleans = {true, false})
38      void testSetter(final boolean resetAutomatically) {
39          // GIVEN
40          final FieldPropagationStepRecorder<Binary64> recorder = new FieldPropagationStepRecorder<Binary64>();
41          // WHEN
42          recorder.setResetAutomatically(resetAutomatically);
43          // THEN
44          assertEquals(resetAutomatically, recorder.isResetAutomatically());
45      }
46  
47      @ParameterizedTest
48      @ValueSource(booleans = {true, false})
49      void testGetter(final boolean resetAutomatically) {
50          // GIVEN
51  
52          // WHEN
53          final FieldPropagationStepRecorder<Binary64> recorder = new FieldPropagationStepRecorder<Binary64>(resetAutomatically);
54          // THEN
55          assertEquals(resetAutomatically, recorder.isResetAutomatically());
56      }
57  
58      @Test
59      void copyStatesAtConstructionTest() {
60          // GIVEN
61          final FieldPropagationStepRecorder<Binary64> recorder = new FieldPropagationStepRecorder<>();
62          // WHEN
63          final List<FieldSpacecraftState<Binary64>> states = recorder.copyStates();
64          // THEN
65          assertEquals(0, states.size());
66      }
67  
68      @Test
69      void copyStatesTest() {
70          // GIVEN
71          final FieldPropagationStepRecorder<Binary64> recorder = new FieldPropagationStepRecorder<>();
72          final FieldOrekitStepInterpolator<Binary64> interpolator = createInterpolator();
73          recorder.handleStep(interpolator);
74          // WHEN
75          recorder.init(createState(), FieldAbsoluteDate.getArbitraryEpoch(Binary64Field.getInstance()));
76          // THEN
77          final List<FieldSpacecraftState<Binary64>> states = recorder.copyStates();
78          assertEquals(0, states.size());
79      }
80  
81      @Test
82      void handleStepTest() {
83          // GIVEN
84          final FieldPropagationStepRecorder<Binary64> recorder = new FieldPropagationStepRecorder<>();
85          final FieldOrekitStepInterpolator<Binary64> interpolator = createInterpolator();
86          final int expectedSize = 10;
87          // WHEN
88          for (int i = 0; i < expectedSize; ++i) {
89              recorder.handleStep(interpolator);
90          }
91          // WHEN
92          final List<FieldSpacecraftState<Binary64>> states = recorder.copyStates();
93          assertEquals(expectedSize, states.size());
94      }
95  
96      private static FieldOrekitStepInterpolator<Binary64> createInterpolator() {
97          return new FieldOrekitStepInterpolator<Binary64>() {
98              @Override
99              public FieldSpacecraftState<Binary64> getPreviousState() {
100                 return null;
101             }
102 
103             @Override
104             public FieldSpacecraftState<Binary64> getCurrentState() {
105                 return createState();
106             }
107 
108             @Override
109             public FieldSpacecraftState<Binary64> getInterpolatedState(FieldAbsoluteDate<Binary64> date) {
110                 return null;
111             }
112 
113             @Override
114             public boolean isForward() {
115                 return false;
116             }
117 
118             @Override
119             public FieldOrekitStepInterpolator<Binary64> restrictStep(FieldSpacecraftState<Binary64> newPreviousState, FieldSpacecraftState<Binary64> newCurrentState) {
120                 return null;
121             }
122         };
123     }
124 
125     private static FieldSpacecraftState<Binary64> createState() {
126         final SpacecraftState state = new SpacecraftState(TestUtils.getDefaultOrbit(AbsoluteDate.ARBITRARY_EPOCH));
127         return new FieldSpacecraftState<>(Binary64Field.getInstance(), state);
128     }
129 }