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