1   /* Copyright 2002-2025 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.files.rinex.observation;
18  
19  import java.util.ArrayList;
20  import java.util.List;
21  
22  import org.junit.jupiter.api.Assertions;
23  import org.junit.jupiter.api.BeforeEach;
24  import org.junit.jupiter.api.Test;
25  import org.orekit.Utils;
26  import org.orekit.errors.OrekitIllegalArgumentException;
27  import org.orekit.errors.OrekitMessages;
28  import org.orekit.gnss.SatInSystem;
29  import org.orekit.gnss.SatelliteSystem;
30  import org.orekit.time.AbsoluteDate;
31  
32  public class RinexObservationTest {
33  
34      @BeforeEach
35      public void setUp() {
36          // Sets the root of data to read
37          Utils.setDataRoot("regular-data");
38      }
39  
40      @Test
41      public void testGenerateRegular() {
42          final double interval = 300.0;
43          final int    n        = 100;
44          RinexObservation rinexObservation = generate(AbsoluteDate.ARBITRARY_EPOCH,
45                                                       AbsoluteDate.ARBITRARY_EPOCH.shiftedBy((n - 1) * interval),
46                                                       interval, n);
47          Assertions.assertEquals(n, rinexObservation.getObservationDataSets().size());
48      }
49  
50      @Test
51      public void testWrongSampling() {
52          final double interval = 300.0;
53          final int    n        = 100;
54          RinexObservation rinexObservation = generate(AbsoluteDate.ARBITRARY_EPOCH,
55                                                       AbsoluteDate.ARBITRARY_EPOCH.shiftedBy((n - 1) * interval),
56                                                       interval, n - 10);
57          final List<ObservationDataSet> ods = rinexObservation.getObservationDataSets();
58          final AbsoluteDate lastGenerated = ods.get(ods.size() - 1).getDate();
59          try {
60              rinexObservation.addObservationDataSet(dummyMeasurement(lastGenerated.shiftedBy(0.75 * interval)));
61              Assertions.fail("an exception should have been thrown");
62          } catch (OrekitIllegalArgumentException oiae) {
63              Assertions.assertEquals(OrekitMessages.INCONSISTENT_SAMPLING_DATE, oiae.getSpecifier());
64          }
65      }
66  
67      @Test
68      public void testOutOfRange() {
69          final double interval = 300.0;
70          final int    n        = 100;
71          RinexObservation rinexObservation = generate(AbsoluteDate.ARBITRARY_EPOCH,
72                                                       AbsoluteDate.ARBITRARY_EPOCH.shiftedBy((n - 1) * interval),
73                                                       interval, n);
74          final List<ObservationDataSet> ods = rinexObservation.getObservationDataSets();
75          final AbsoluteDate lastGenerated = ods.get(ods.size() - 1).getDate();
76          try {
77              rinexObservation.addObservationDataSet(dummyMeasurement(lastGenerated.shiftedBy(interval)));
78              Assertions.fail("an exception should have been thrown");
79          } catch (OrekitIllegalArgumentException oiae) {
80              Assertions.assertEquals(OrekitMessages.OUT_OF_RANGE_DATE, oiae.getSpecifier());
81          }
82      }
83  
84      private RinexObservation generate(final AbsoluteDate first, final AbsoluteDate last,
85                                        final double interval, final int n) {
86          final RinexObservation rinexObservation = new RinexObservation();
87          rinexObservation.getHeader().setInterval(interval);
88          rinexObservation.getHeader().setTFirstObs(first);
89          rinexObservation.getHeader().setTLastObs(last);
90          for (int i = 0; i < n; ++i) {
91              rinexObservation.addObservationDataSet(dummyMeasurement(first.shiftedBy(i * interval)));
92          }
93          return rinexObservation;
94      }
95  
96      private ObservationDataSet dummyMeasurement(final AbsoluteDate date) {
97          return new ObservationDataSet(new SatInSystem(SatelliteSystem.GALILEO, 11),
98                                        date, 0, 0, new ArrayList<>());
99      }
100 
101 }