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.Collections;
20 import java.util.NoSuchElementException;
21
22 import org.hipparchus.ode.events.Action;
23 import org.junit.Assert;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.mockito.Mockito;
27 import org.orekit.propagation.SpacecraftState;
28 import org.orekit.propagation.events.handlers.EventHandler;
29 import org.orekit.time.AbsoluteDate;
30
31
32
33
34
35
36 public class OrDetectorTest {
37
38
39 private MockDetector a;
40
41 private MockDetector b;
42
43 private SpacecraftState s;
44
45 private BooleanDetector or;
46
47
48 @Before
49 public void setUp() {
50 a = new MockDetector();
51 b = new MockDetector();
52 s = null;
53 or = BooleanDetector.orCombine(a, b);
54 }
55
56
57
58
59 @Test
60 public void testG() {
61
62 a.g = b.g = 0.0;
63 Assert.assertEquals(0.0, or.g(s), 0);
64 a.g = -1;
65 b.g = 0;
66 Assert.assertEquals(0.0, or.g(s), 0);
67 a.g = 0;
68 b.g = -1;
69 Assert.assertEquals(0.0, or.g(s), 0);
70
71
72 a.g = -1;
73 b.g = -1;
74 Assert.assertTrue("negative", or.g(s) < 0);
75
76
77 a.g = 0;
78 b.g = 1;
79 Assert.assertTrue("positive", or.g(s) > 0);
80 a.g = 1;
81 b.g = -1;
82 Assert.assertTrue("positive", or.g(s) > 0);
83 a.g = 1;
84 b.g = 0;
85 Assert.assertTrue("positive", or.g(s) > 0);
86 a.g = -1;
87 b.g = 1;
88 Assert.assertTrue("positive", or.g(s) > 0);
89 a.g = 1;
90 b.g = 1;
91 Assert.assertTrue("positive", or.g(s) > 0);
92
93 }
94
95
96
97
98 @Test
99 public void testCancellation() {
100 a.g = -1e-10;
101 b.g = -1e10;
102 Assert.assertTrue("negative", or.g(s) < 0);
103 a.g = -1e10;
104 b.g = -1e-10;
105 Assert.assertTrue("negative", or.g(s) < 0);
106 a.g = -1e10;
107 b.g = 1e-10;
108 Assert.assertTrue("positive", or.g(s) > 0);
109 a.g = 1e-10;
110 b.g = -1e10;
111 Assert.assertTrue("positive", or.g(s) > 0);
112 a.g = 1e10;
113 b.g = -1e-10;
114 Assert.assertTrue("positive", or.g(s) > 0);
115 a.g = -1e-10;
116 b.g = 1e10;
117 Assert.assertTrue("positive", or.g(s) > 0);
118 }
119
120
121
122
123 @Test
124 public void testInit() {
125
126 EventDetector a = Mockito.mock(EventDetector.class);
127 EventDetector b = Mockito.mock(EventDetector.class);
128 @SuppressWarnings("unchecked")
129 EventHandler<EventDetector> c = Mockito.mock(EventHandler.class);
130 BooleanDetector or = BooleanDetector.orCombine(a, b).withHandler(c);
131 AbsoluteDate t = AbsoluteDate.CCSDS_EPOCH;
132 s = Mockito.mock(SpacecraftState.class);
133 Mockito.when(s.getDate()).thenReturn(t.shiftedBy(60.0));
134
135
136 or.init(s, t);
137
138
139 Assert.assertEquals(2, or.getDetectors().size());
140 Mockito.verify(a).init(s, t);
141 Mockito.verify(b).init(s, t);
142 Mockito.verify(c).init(s, t, or);
143 }
144
145
146 @Test
147 public void testZeroDetectors() {
148
149 try {
150 BooleanDetector.orCombine(Collections.emptyList());
151 Assert.fail("Expected Exception");
152 } catch (NoSuchElementException e) {
153
154 }
155 }
156
157
158 private static class MockDetector implements EventDetector {
159
160
161 public double g = 0;
162
163 @Override
164 public void init(SpacecraftState s0, AbsoluteDate t) {
165
166 }
167
168 @Override
169 public double g(SpacecraftState s) {
170 return this.g;
171 }
172
173 @Override
174 public double getThreshold() {
175 return 0;
176 }
177
178 @Override
179 public double getMaxCheckInterval() {
180 return 0;
181 }
182
183 @Override
184 public int getMaxIterationCount() {
185 return 0;
186 }
187
188 @Override
189 public Action eventOccurred(SpacecraftState s, boolean increasing) {
190 return null;
191 }
192
193 @Override
194 public SpacecraftState resetState(SpacecraftState oldState) {
195 return null;
196 }
197 }
198 }