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 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
35
36
37
38 public class FunctionalDetectorTest {
39
40
41
42
43 @Test
44 public void testFunctionalDetector() {
45
46 ToDoubleFunction<SpacecraftState> g = SpacecraftState::getMass;
47 EventHandler<EventDetector> handler = (s, detector, increasing) -> Action.STOP;
48
49
50 FunctionalDetector detector = new FunctionalDetector()
51 .withMaxIter(1)
52 .withThreshold(2)
53 .withMaxCheck(3)
54 .withHandler(handler)
55 .withFunction(g);
56
57
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 }