1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
36
37
38
39 public class FunctionalDetectorTest {
40
41
42
43
44 @Test
45 public void testFunctionalDetector() {
46
47 ToDoubleFunction<SpacecraftState> g = SpacecraftState::getMass;
48 EventHandler handler = new StopOnEvent();
49
50
51 FunctionalDetector detector = new FunctionalDetector()
52 .withMaxIter(1)
53 .withThreshold(2)
54 .withMaxCheck(3)
55 .withHandler(handler)
56 .withFunction(g);
57
58
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 }