1   /* Contributed in the public domain.
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.propagation.events;
18  
19  import org.hamcrest.CoreMatchers;
20  import org.hamcrest.MatcherAssert;
21  import org.hipparchus.geometry.euclidean.threed.Vector3D;
22  import org.hipparchus.ode.events.Action;
23  import org.junit.jupiter.api.Test;
24  import org.orekit.frames.FramesFactory;
25  import org.orekit.orbits.CartesianOrbit;
26  import org.orekit.propagation.SpacecraftState;
27  import org.orekit.propagation.events.handlers.EventHandler;
28  import org.orekit.propagation.events.handlers.StopOnEvent;
29  import org.orekit.time.AbsoluteDate;
30  import org.orekit.utils.PVCoordinates;
31  
32  import java.util.function.ToDoubleFunction;
33  
34  /**
35   * Unit tests for {@link FunctionalDetector}
36   *
37   * @author Evan Ward
38   */
39  public class FunctionalDetectorTest {
40  
41      /**
42       * Check {@link FunctionalDetector}.
43       */
44      @Test
45      public void testFunctionalDetector() {
46          // setup
47          ToDoubleFunction<SpacecraftState> g = SpacecraftState::getMass;
48          EventHandler handler = new StopOnEvent();
49  
50          // action
51          FunctionalDetector detector = new FunctionalDetector()
52                  .withMaxIter(1)
53                  .withThreshold(2)
54                  .withMaxCheck(3)
55                  .withHandler(handler)
56                  .withFunction(g);
57  
58          // verify
59          MatcherAssert.assertThat(detector.getMaxIterationCount(), CoreMatchers.is(1));
60          MatcherAssert.assertThat(detector.getThreshold(), CoreMatchers.is(2.0));
61          MatcherAssert.assertThat(detector.getMaxCheckInterval().currentInterval(null, true), CoreMatchers.is(3.0));
62          MatcherAssert.assertThat(detector.getHandler(), CoreMatchers.is(handler));
63          SpacecraftState state = new SpacecraftState(
64                  new CartesianOrbit(
65                          new PVCoordinates(
66                                  new Vector3D(1, 2, 3),
67                                  new Vector3D(4, 5, 6)),
68                          FramesFactory.getGCRF(),
69                          AbsoluteDate.CCSDS_EPOCH,
70                          4),
71                  5);
72          MatcherAssert.assertThat(detector.g(state), CoreMatchers.is(5.0));
73          MatcherAssert.assertThat(detector.getHandler().eventOccurred(null, detector, false), CoreMatchers.is(Action.STOP));
74          MatcherAssert.assertThat(detector.getFunction(), CoreMatchers.is(g));
75      }
76  
77  }