1   /* Copyright 2002-2022 CS GROUP
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.estimation.measurements;
18  
19  import org.hipparchus.geometry.euclidean.threed.Vector3D;
20  import org.hipparchus.util.FastMath;
21  import org.junit.Assert;
22  import org.junit.Test;
23  import org.orekit.Utils;
24  import org.orekit.bodies.GeodeticPoint;
25  import org.orekit.bodies.OneAxisEllipsoid;
26  import org.orekit.frames.FramesFactory;
27  import org.orekit.frames.TopocentricFrame;
28  import org.orekit.time.AbsoluteDate;
29  import org.orekit.utils.Constants;
30  import org.orekit.utils.IERSConventions;
31  
32  /** This test class is only used to test the <i>compareTo</i> default method of interface <i>ComparableMeasurement</i>.<br>
33   * This is done to test the resolution of  <a href="https://gitlab.orekit.org/orekit/orekit/issues/538"> issue #538</a> on Orekit forge. 
34   */
35  public class ComparableMeasurementTest {
36  
37      /** Test default method compareTo, see <a href="https://gitlab.orekit.org/orekit/orekit/issues/538"> issue #538</a> on Orekit forge. */
38      @Test
39      public void testDefaultCompareToIssue538() {
40          
41          // Print on console ?
42          boolean print = false;
43          
44          // Setup data
45          Utils.setDataRoot("regular-data");
46          OneAxisEllipsoid earth = new OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS, Constants.WGS84_EARTH_FLATTENING,
47                                                        FramesFactory.getITRF(IERSConventions.IERS_2010, false));
48          TopocentricFrame stationFrame = new TopocentricFrame(earth, new GeodeticPoint(FastMath.toRadians(45.0), FastMath.toRadians(0.0), 0.0), "station");
49          GroundStation station = new GroundStation(stationFrame);
50          AbsoluteDate date = AbsoluteDate.J2000_EPOCH;
51  
52          // Create a Range and Azel at same date,
53          // A 2 identical PV before date
54          // And 1 PV measurement before date with one value bigger
55          ObservableSatellite satellite = new ObservableSatellite(0);
56          Range range = new Range(station, false, date, 400e3, 1.0, 1.0, satellite);
57          AngularAzEl azel = new AngularAzEl(station, date, new double[] {1.0, 0.5}, new double[] {1.0e-2, 1.0e-2}, new double[] {1.0, 1.0}, satellite);
58          PV pv = new PV(date.shiftedBy(-1.), new Vector3D(7e3,7e3,7e3), new Vector3D(7,7,7), 1., 1e-3, 1., satellite);
59          PV pv2 = new PV(date.shiftedBy(-1.), new Vector3D(7e3,7e3,7e3), new Vector3D(7,7,7), 1., 1e-3, 1., satellite);
60          PV pv3 = new PV(date.shiftedBy(-1.), new Vector3D(7e3,7e3,7e3), new Vector3D(7,8,7), 1., 1e-3, 1., satellite);
61          
62          // Print out results
63          if (print) {
64              System.out.println("azel.compareTo(azel)  = " + azel.compareTo(azel));
65              System.out.println("pv.compareTo(azel)    = " + pv.compareTo(azel));
66              System.out.println("range.compareTo(pv2)  = " + range.compareTo(pv2));
67              System.out.println("range.compareTo(azel) = " + range.compareTo(azel));
68              System.out.println("azel.compareTo(range) = " + azel.compareTo(range));
69              System.out.println("pv.compareTo(pv3)     = " + pv.compareTo(pv3));
70              System.out.println("pv3.compareTo(pv)     = " + pv3.compareTo(pv));
71              System.out.println("pv.compareTo(pv2)     = " + pv.compareTo(pv2));
72              System.out.println("pv2.compareTo(pv)     = " + pv.compareTo(pv2));
73          }
74          
75          // Same object, only case when compareTo returns 0
76          Assert.assertEquals(azel.compareTo(azel), 0);
77          
78          // Sorted by date by default
79          Assert.assertEquals(pv.compareTo(azel), -1);
80          Assert.assertEquals(range.compareTo(pv2), +1);
81          
82          // Same date but different measurement - "bigger" measurement after "smaller" one
83          Assert.assertEquals(range.compareTo(azel), -1);
84          Assert.assertEquals(azel.compareTo(range), +1);
85          
86          // Same date, same size, but different values, "bigger" measurement after "smaller" one
87          Assert.assertEquals(pv.compareTo(pv3), -1);
88          Assert.assertEquals(pv3.compareTo(pv), +1);
89          
90          // Same date, same size, same values - Arbitrary order, always return -1
91          Assert.assertEquals(pv.compareTo(pv2), -1);
92          Assert.assertEquals(pv2.compareTo(pv), -1);
93          
94      }
95  }