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.events.intervals;
18  
19  import org.hipparchus.util.Binary64;
20  import org.junit.jupiter.api.Assertions;
21  import org.junit.jupiter.params.ParameterizedTest;
22  import org.junit.jupiter.params.provider.ValueSource;
23  import org.mockito.Mockito;
24  import org.orekit.propagation.FieldSpacecraftState;
25  
26  class FieldAdaptableIntervalTest {
27  
28      @SuppressWarnings("unchecked")
29      @ParameterizedTest
30      @ValueSource(booleans = {true, false})
31      void testOfDouble(final boolean isForward) {
32          // GIVEN
33          final double expectedValue = 1.;
34          // WHEN
35          final FieldAdaptableInterval<?> adaptableInterval = FieldAdaptableInterval.of(expectedValue);
36          // THEN
37          final double actualValue = adaptableInterval.currentInterval(Mockito.mock(FieldSpacecraftState.class), isForward);
38          Assertions.assertEquals(expectedValue, actualValue);
39      }
40  
41      @SuppressWarnings("unchecked")
42      @ParameterizedTest
43      @ValueSource(booleans = {true, false})
44      void testOf(final boolean isForward) {
45          // GIVEN
46          final double expectedValue = 1.;
47          final AdaptableInterval adaptableInterval = AdaptableInterval.of(expectedValue);
48          // WHEN
49          final FieldAdaptableInterval<?> fieldAdaptableInterval = FieldAdaptableInterval.of(adaptableInterval);
50          // THEN
51          final double actualValue = fieldAdaptableInterval.currentInterval(Mockito.mock(FieldSpacecraftState.class), isForward);
52          Assertions.assertEquals(expectedValue, actualValue);
53      }
54  
55      @ParameterizedTest
56      @SuppressWarnings("unchecked")
57      @ValueSource(booleans = {true, false})
58      void testAdaptableIntervalOf(final boolean isForward) {
59          // GIVEN
60          final double expectedValue = 1;
61          final FieldAdaptableInterval<Binary64> interval1 = FieldAdaptableInterval.of(expectedValue);
62          final FieldAdaptableInterval<Binary64> interval2 = FieldAdaptableInterval.of(expectedValue + 1);
63          // WHEN
64          final FieldAdaptableInterval<Binary64> adaptableInterval = FieldAdaptableInterval.of(Double.POSITIVE_INFINITY, interval1, interval2);
65          // THEN
66          final double actualValue = adaptableInterval.currentInterval(Mockito.mock(FieldSpacecraftState.class), isForward);
67          Assertions.assertEquals(expectedValue, actualValue);
68      }
69  }
70