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.time;
18  
19  
20  
21  import java.util.List;
22  
23  import org.junit.Assert;
24  import org.junit.Before;
25  import org.junit.Test;
26  import org.orekit.Utils;
27  
28  public class BurstSelectorStepTest {
29  
30      @Test
31      public void testNoAlign() {
32          final TimeScale utc = TimeScalesFactory.getUTC();
33          final DatesSelector selector = new BurstSelector(3, 10.0, 60.0, null);
34          final AbsoluteDate t0 = new AbsoluteDate("2003-02-25T00:00:27.0", utc);
35          final AbsoluteDate t1 = t0.shiftedBy(71);
36          final List<AbsoluteDate> list = selector.selectDates(t0, t1);
37          Assert.assertEquals(5, list.size());
38          Assert.assertEquals( 27.0, list.get(0).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
39          Assert.assertEquals( 37.0, list.get(1).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
40          Assert.assertEquals( 47.0, list.get(2).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
41          Assert.assertEquals( 87.0, list.get(3).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
42          Assert.assertEquals( 97.0, list.get(4).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
43      }
44  
45      @Test
46      public void testAlignUTCBeforeForward() {
47          final TimeScale utc = TimeScalesFactory.getUTC();
48          final DatesSelector selector = new BurstSelector(2, 10.0, 30.0, utc);
49          final AbsoluteDate t0 = new AbsoluteDate("2003-02-25T00:00:27.0", utc);
50          final AbsoluteDate t1 = t0.shiftedBy(62);
51          final List<AbsoluteDate> list = selector.selectDates(t0, t1);
52          Assert.assertEquals(4, list.size());
53          Assert.assertEquals( 30.0, list.get(0).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
54          Assert.assertEquals( 40.0, list.get(1).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
55          Assert.assertEquals( 60.0, list.get(2).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
56          Assert.assertEquals( 70.0, list.get(3).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
57      }
58  
59      @Test
60      public void testAlignUTCBeforeBackward() {
61          final TimeScale utc = TimeScalesFactory.getUTC();
62          final DatesSelector selector = new BurstSelector(2, 10.0, 30.0, utc);
63          final AbsoluteDate t0 = new AbsoluteDate("2003-02-25T00:00:27.0", utc);
64          final AbsoluteDate t1 = t0.shiftedBy(62);
65          final List<AbsoluteDate> list = selector.selectDates(t1, t0);
66          Assert.assertEquals(4, list.size());
67          Assert.assertEquals( 70.0, list.get(0).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
68          Assert.assertEquals( 60.0, list.get(1).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
69          Assert.assertEquals( 40.0, list.get(2).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
70          Assert.assertEquals( 30.0, list.get(3).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
71      }
72  
73      @Test
74      public void testAlignUTCAfterForward() {
75          final TimeScale utc = TimeScalesFactory.getUTC();
76          final DatesSelector selector = new BurstSelector(3, 10.0, 60.0, utc);
77          final AbsoluteDate t0 = new AbsoluteDate("2003-02-25T00:00:27.0", utc);
78          final AbsoluteDate t1 = t0.shiftedBy(2);
79          final AbsoluteDate t2 = t1.shiftedBy(98);
80          final List<AbsoluteDate> list1 = selector.selectDates(t0, t1);
81          Assert.assertEquals(0, list1.size());
82          final List<AbsoluteDate> list2 = selector.selectDates(t1, t2);
83          Assert.assertEquals(4, list2.size());
84          Assert.assertEquals( 60.0, list2.get(0).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
85          Assert.assertEquals( 70.0, list2.get(1).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
86          Assert.assertEquals( 80.0, list2.get(2).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
87          Assert.assertEquals(120.0, list2.get(3).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
88      }
89  
90      @Test
91      public void testAlignUTCAfterBackward() {
92          final TimeScale utc = TimeScalesFactory.getUTC();
93          final DatesSelector selector = new BurstSelector(3, 10.0, 60.0, utc);
94          final AbsoluteDate t0 = new AbsoluteDate("2003-02-25T00:00:27.0", utc);
95          final AbsoluteDate t1 = t0.shiftedBy(2);
96          final AbsoluteDate t2 = t1.shiftedBy(98);
97          final List<AbsoluteDate> list1 = selector.selectDates(t2, t1);
98          Assert.assertEquals(4, list1.size());
99          Assert.assertEquals(120.0, list1.get(0).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
100         Assert.assertEquals( 80.0, list1.get(1).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
101         Assert.assertEquals( 70.0, list1.get(2).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
102         Assert.assertEquals( 60.0, list1.get(3).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
103         final List<AbsoluteDate> list2 = selector.selectDates(t1, t0);
104         Assert.assertEquals(0, list2.size());
105     }
106 
107     @Test
108     public void testInterruptedStream() {
109         final TimeScale utc = TimeScalesFactory.getUTC();
110         final DatesSelector selector = new BurstSelector(3, 10.0, 60.0, null);
111         final AbsoluteDate t0 = new AbsoluteDate("2003-02-25T00:00:27.0", utc);
112         final AbsoluteDate t1 = t0.shiftedBy(71);
113         final AbsoluteDate t2 = t1.shiftedBy(30);
114         final List<AbsoluteDate> list1 = selector.selectDates(t0, t1);
115         Assert.assertEquals(5, list1.size());
116         final List<AbsoluteDate> list2 = selector.selectDates(t1, t2);
117         Assert.assertEquals(1, list2.size());
118         Assert.assertEquals(10.0, list2.get(0).durationFrom(list1.get(list1.size() - 1)), 1.0e-15);
119     }
120 
121     @Test
122     public void testMissedHighRateNoReset() {
123         final TimeScale utc = TimeScalesFactory.getUTC();
124         final DatesSelector selector = new BurstSelector(3, 10.0, 60.0, null);
125         final AbsoluteDate t0 = new AbsoluteDate("2003-02-25T00:00:27.0", utc);
126         final AbsoluteDate t1 = t0.shiftedBy(71);
127         final AbsoluteDate t2 = t1.shiftedBy(30);
128         final AbsoluteDate t3 = t2.shiftedBy(19);
129         final List<AbsoluteDate> list1 = selector.selectDates(t0, t1);
130         Assert.assertEquals(5, list1.size());
131         final List<AbsoluteDate> list2 = selector.selectDates(t2, t3);
132         Assert.assertEquals(1, list2.size());
133         Assert.assertEquals(50.0, list2.get(0).durationFrom(list1.get(list1.size() - 1)), 1.0e-15);
134     }
135 
136     @Test
137     public void testResetStream() {
138         final TimeScale utc = TimeScalesFactory.getUTC();
139         final DatesSelector selector = new BurstSelector(3, 10.0, 60.0, null);
140         final AbsoluteDate t0 = new AbsoluteDate("2003-02-25T00:00:27.0", utc);
141         final AbsoluteDate t1 = t0.shiftedBy(71);
142         final AbsoluteDate t2 = t1.shiftedBy(50);
143         final AbsoluteDate t3 = t2.shiftedBy(15);
144         final List<AbsoluteDate> list1 = selector.selectDates(t0, t1);
145         Assert.assertEquals(5, list1.size());
146         final List<AbsoluteDate> list2 = selector.selectDates(t2, t3);
147         Assert.assertEquals(2, list2.size());
148         Assert.assertEquals( 0.0, list2.get(0).durationFrom(t2), 1.0e-15);
149         Assert.assertEquals(10.0, list2.get(1).durationFrom(t2), 1.0e-15);
150     }
151 
152     @Test
153     public void testShortInterval() {
154         final TimeScale utc = TimeScalesFactory.getUTC();
155         final DatesSelector selector = new BurstSelector(3, 10.0, 60.0, null);
156         final AbsoluteDate t0 = new AbsoluteDate("2003-02-25T00:00:27.0", utc);
157         final AbsoluteDate t1 = t0.shiftedBy(71);
158         final AbsoluteDate t2 = t1.shiftedBy(8);
159         final List<AbsoluteDate> list1 = selector.selectDates(t0, t1);
160         Assert.assertEquals(5, list1.size());
161         final List<AbsoluteDate> list2 = selector.selectDates(t1, t2);
162         Assert.assertEquals(0, list2.size());
163     }
164 
165     @Test
166     public void testStartMidBurstForward() {
167         final TimeScale utc = TimeScalesFactory.getUTC();
168         final DatesSelector selector = new BurstSelector(3, 10.0, 60.0, utc);
169         final AbsoluteDate t0 = new AbsoluteDate("2003-02-25T00:00:17.0", utc);
170         final AbsoluteDate t1 = t0.shiftedBy(118);
171         final List<AbsoluteDate> list1 = selector.selectDates(t0, t1);
172         Assert.assertEquals(6, list1.size());
173         Assert.assertEquals( 20.0, list1.get(0).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
174         Assert.assertEquals( 60.0, list1.get(1).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
175         Assert.assertEquals( 70.0, list1.get(2).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
176         Assert.assertEquals( 80.0, list1.get(3).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
177         Assert.assertEquals(120.0, list1.get(4).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
178         Assert.assertEquals(130.0, list1.get(5).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
179     }
180 
181     @Test
182     public void testStartMidBurstBackward() {
183         final TimeScale utc = TimeScalesFactory.getUTC();
184         final DatesSelector selector = new BurstSelector(3, 10.0, 60.0, utc);
185         final AbsoluteDate t0 = new AbsoluteDate("2003-02-25T00:00:17.0", utc);
186         final AbsoluteDate t1 = t0.shiftedBy(118);
187         final List<AbsoluteDate> list1 = selector.selectDates(t1, t0);
188         Assert.assertEquals(6, list1.size());
189         Assert.assertEquals(130.0, list1.get(0).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
190         Assert.assertEquals(120.0, list1.get(1).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
191         Assert.assertEquals( 80.0, list1.get(2).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
192         Assert.assertEquals( 70.0, list1.get(3).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
193         Assert.assertEquals( 60.0, list1.get(4).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
194         Assert.assertEquals( 20.0, list1.get(5).getComponents(utc).getTime().getSecondsInLocalDay(), 1.0e-15);
195     }
196 
197     @Before
198     public void setUp() {
199         Utils.setDataRoot("regular-data");
200     }
201 
202 }