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.hipparchus.geometry.euclidean.threed.Vector3D;
20  import org.hipparchus.util.MathUtils;
21  import org.junit.jupiter.api.Assertions;
22  import org.junit.jupiter.api.Test;
23  import org.orekit.frames.Frame;
24  import org.orekit.frames.FramesFactory;
25  import org.orekit.time.AbsoluteDate;
26  import org.orekit.time.TimeOffset;
27  import org.orekit.utils.PVCoordinates;
28  import org.orekit.utils.TimeStampedPVCoordinates;
29  
30  
31  class OrbitTest {
32  
33      @Test
34      void testGetPosition() {
35          // GIVEN
36          final double aIn = 1.;
37          final TestOrbit testOrbit = new TestOrbit(aIn);
38          final AbsoluteDate date = testOrbit.getDate().shiftedBy(0.);
39          // WHEN
40          final Vector3D actualPosition = testOrbit.getPosition(date, testOrbit.getFrame());
41          // THEN
42          final Vector3D expectedPosition = testOrbit.getPVCoordinates(date, testOrbit.getFrame()).getPosition();
43          Assertions.assertEquals(expectedPosition, actualPosition);
44      }
45  
46      @Test
47      void testKeplerianMeanMotionAndPeriod() {
48          // GIVEN
49          final double aIn = 1.;
50          final TestOrbit testOrbit = new TestOrbit(aIn);
51          // WHEN
52          final double meanMotion = testOrbit.getKeplerianMeanMotion();
53          final double period = testOrbit.getKeplerianPeriod();
54          final double actualValue = period * meanMotion;
55          // THEN
56          final double expectedValue = MathUtils.TWO_PI;
57          Assertions.assertEquals(expectedValue, actualValue, 1e-10);
58      }
59  
60      @Test
61      void testIsElliptical() {
62          templateTestIsElliptical(1.);
63      }
64  
65      @Test
66      void testIsNotElliptical() {
67          templateTestIsElliptical(-1.);
68      }
69  
70      private void templateTestIsElliptical(final double aIn) {
71          // GIVEN
72          final TestOrbit testOrbit = new TestOrbit(aIn);
73          // WHEN
74          final boolean actualValue = testOrbit.isElliptical();
75          // THEN
76          final boolean expectedValue = aIn > 0.;
77          Assertions.assertEquals(expectedValue, actualValue);
78      }
79  
80      private static class TestOrbit extends Orbit {
81  
82          final double a;
83  
84          protected TestOrbit(final double aIn) throws IllegalArgumentException {
85              super(FramesFactory.getGCRF(), AbsoluteDate.ARBITRARY_EPOCH, 1.);
86              this.a = aIn;
87          }
88  
89          @Override
90          public OrbitType getType() {
91              return null;
92          }
93  
94          @Override
95          public double getA() {
96              return this.a;
97          }
98  
99          @Override
100         public double getADot() {
101             return 0;
102         }
103 
104         @Override
105         public double getEquinoctialEx() {
106             return 0;
107         }
108 
109         @Override
110         public double getEquinoctialExDot() {
111             return 0;
112         }
113 
114         @Override
115         public double getEquinoctialEy() {
116             return 0;
117         }
118 
119         @Override
120         public double getEquinoctialEyDot() {
121             return 0;
122         }
123 
124         @Override
125         public double getHx() {
126             return 0;
127         }
128 
129         @Override
130         public double getHxDot() {
131             return 0;
132         }
133 
134         @Override
135         public double getHy() {
136             return 0;
137         }
138 
139         @Override
140         public double getHyDot() {
141             return 0;
142         }
143 
144         @Override
145         public double getLE() {
146             return 0;
147         }
148 
149         @Override
150         public double getLEDot() {
151             return 0;
152         }
153 
154         @Override
155         public double getLv() {
156             return 0;
157         }
158 
159         @Override
160         public double getLvDot() {
161             return 0;
162         }
163 
164         @Override
165         public double getLM() {
166             return 0;
167         }
168 
169         @Override
170         public double getLMDot() {
171             return 0;
172         }
173 
174         @Override
175         public double getE() {
176             return 0;
177         }
178 
179         @Override
180         public double getEDot() {
181             return 0;
182         }
183 
184         @Override
185         public double getI() {
186             return 0;
187         }
188 
189         @Override
190         public double getIDot() {
191             return 0;
192         }
193 
194         @Override
195         protected Vector3D initPosition() {
196             return new Vector3D(a, 0., 0.);
197         }
198 
199         @Override
200         protected TimeStampedPVCoordinates initPVCoordinates() {
201             return new TimeStampedPVCoordinates(getDate(), new PVCoordinates(initPosition(), Vector3D.ZERO));
202         }
203 
204         @Override
205         public Orbit inFrame(Frame inertialFrame) {
206             return null;
207         }
208 
209         @Override
210         public Orbit shiftedBy(double dt) {
211             return new TestOrbit(a);
212         }
213 
214         @Override
215         public Orbit shiftedBy(TimeOffset dt) {
216             return new TestOrbit(a);
217         }
218 
219         @Override
220         protected double[][] computeJacobianMeanWrtCartesian() {
221             return new double[0][];
222         }
223 
224         @Override
225         protected double[][] computeJacobianEccentricWrtCartesian() {
226             return new double[0][];
227         }
228 
229         @Override
230         protected double[][] computeJacobianTrueWrtCartesian() {
231             return new double[0][];
232         }
233 
234         @Override
235         public void addKeplerContribution(PositionAngleType type, double gm, double[] pDot) {
236 
237         }
238     }
239 
240 }