MCPcopy Create free account
hub / github.com/akeranen/the-one / testHostMoving

Method testHostMoving

test/MapBasedMovementTest.java:195–229  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

193 }
194
195 public void testHostMoving() {
196 final int NROF = 15;
197
198 setupMapData(null, "1,1", null);
199 DTNHost h1 = setupHost();
200 Coord loc = h1.getLocation().clone();
201
202 for (int i=0; i<NROF; i++) {
203 h1.move(1);
204 // should always be 1 meter a way from the previous place
205 assertEquals(1.0, loc.distance(h1.getLocation()));
206 loc = h1.getLocation().clone();
207 }
208
209 h1 = setupHost();
210 loc = h1.getLocation().clone();
211 for (int i=0; i<NROF; i++ ) {
212 h1.move(2);
213 // should move 2 steps away from previous location
214 double dist = loc.distance(h1.getLocation());
215 assertTrue(dist == 2 || dist == 0 || dist == Math.sqrt(2));
216 loc = h1.getLocation().clone();
217 }
218
219 h1 = setupHost();
220 loc = h1.getLocation().clone();
221 for (int i=0; i<NROF; i++ ) {
222 h1.move(3);
223 // should move 3 steps away from previous location
224 double dist = loc.distance(h1.getLocation());
225 assertTrue(dist == 3 || dist == 1 || dist == Math.sqrt(1+2*2) ||
226 dist == Math.sqrt(2));
227 loc = h1.getLocation().clone();
228 }
229 }
230
231 private DTNHost setupHost() {
232 TestUtils utils = new TestUtils(null, null, s);

Callers

nothing calls this directly

Calls 6

setupMapDataMethod · 0.95
setupHostMethod · 0.95
getLocationMethod · 0.95
moveMethod · 0.95
distanceMethod · 0.95
cloneMethod · 0.80

Tested by

no test coverage detected