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.orbits;
18  
19  import org.junit.jupiter.api.Assertions;
20  import org.junit.jupiter.api.Test;
21  import org.junit.jupiter.params.ParameterizedTest;
22  import org.junit.jupiter.params.provider.EnumSource;
23  import org.junit.jupiter.params.provider.ValueSource;
24  import org.orekit.errors.OrekitException;
25  import org.orekit.errors.OrekitMessages;
26  
27  class EquinoctialLongitudeArgumentUtilityTest {
28  
29      private static final double EX = 0.1;
30      private static final double EY = 0.66;
31      private static final double TOLERANCE = 1e-10;
32      
33      @Test
34      void testMeanToTrueAndBack() {
35          // GIVEN
36          final double expectedLongitudeArgument = 3.;
37          // WHEN
38          final double intermediateLongitudeArgument = EquinoctialLongitudeArgumentUtility.meanToTrue(EX, EY,
39                  expectedLongitudeArgument);
40          final double actualLongitudeArgument = EquinoctialLongitudeArgumentUtility.trueToMean(EX, EY,
41                  intermediateLongitudeArgument);
42          // THEN
43          Assertions.assertEquals(expectedLongitudeArgument, actualLongitudeArgument, TOLERANCE);
44      }
45  
46      @Test
47      void testEccentricToTrueAndBack() {
48          // GIVEN
49          final double expectedLongitudeArgument = 3.;
50          // WHEN
51          final double intermediateLongitudeArgument = EquinoctialLongitudeArgumentUtility.eccentricToTrue(EX, EY,
52                  expectedLongitudeArgument);
53          final double actualLongitudeArgument = EquinoctialLongitudeArgumentUtility.trueToEccentric(EX, EY,
54                  intermediateLongitudeArgument);
55          // THEN
56          Assertions.assertEquals(expectedLongitudeArgument, actualLongitudeArgument, TOLERANCE);
57      }
58  
59      @Test
60      void testEccentricToMeanAndBack() {
61          // GIVEN
62          final double expectedLongitudeArgument = 3.;
63          // WHEN
64          final double intermediateLongitudeArgument = EquinoctialLongitudeArgumentUtility.eccentricToMean(EX, EY,
65                  expectedLongitudeArgument);
66          final double actualLongitudeArgument = EquinoctialLongitudeArgumentUtility.meanToEccentric(EX, EY,
67                  intermediateLongitudeArgument);
68          // THEN
69          Assertions.assertEquals(expectedLongitudeArgument, actualLongitudeArgument, TOLERANCE);
70      }
71  
72      @Test
73      void testMeanToEccentricException() {
74          // GIVEN
75          final double nanLongitudeArgument = Double.NaN;
76          // WHEN & THEN
77          Assertions.assertThrows(OrekitException.class, () -> EquinoctialLongitudeArgumentUtility.meanToEccentric(EX, EY,
78                  nanLongitudeArgument), OrekitMessages.UNABLE_TO_COMPUTE_ECCENTRIC_LONGITUDE_ARGUMENT.toString());
79      }
80  
81      @ParameterizedTest
82      @EnumSource(PositionAngleType.class)
83      void testConvertL(final PositionAngleType inputType) {
84          // GIVEN
85          final double expectedLongitudeArgument = 3.;
86          final PositionAngleType intermediateType = PositionAngleType.ECCENTRIC;
87          // WHEN
88          final double intermediateLongitudeArgument = EquinoctialLongitudeArgumentUtility.convertL(inputType,
89                  expectedLongitudeArgument, EX, EY, intermediateType);
90          final double actualLongitudeArgument = EquinoctialLongitudeArgumentUtility.convertL(intermediateType,
91                  intermediateLongitudeArgument, EX, EY, inputType);
92          // THEN
93          Assertions.assertEquals(expectedLongitudeArgument, actualLongitudeArgument, TOLERANCE);
94      }
95  
96      @ParameterizedTest
97      @ValueSource(doubles = {1e3, 5e3, 1e4, 1e5, 5e5})
98      void testIssue1525(final double lM) {
99          final double ex = 0.44940492906694396;
100         final double ey = 0.56419162961687;
101         Assertions.assertDoesNotThrow(() -> EquinoctialLongitudeArgumentUtility.meanToEccentric(ex, ey, lM));
102     }
103 }