DeadReckoning implements SensorEventListener, SensorCollector, DownloadListener<Map<String, Collection>> { void calculateDeltaLoop() { synchronized (mutex) { double distance; if (moving && (azimuth != null)) { distance = motionModel * timestep/100.f; delta[0] += distance * Math.sin(azimuth - baseAngle); delta[1] += distance * Math.cos(azimuth - baseAngle); } } } DeadReckoning(final Activity activity); void startSensors(); void stopSensors(); @Override void onDownloadFinished(DownloadTask task, boolean success, Map<String, Collection> data); @Override void onSensorChanged(final SensorEvent event); @Override void onAccuracyChanged(final Sensor sensor, final int accuracy); NicGeoPoint getDelta(); void setCompassFilterEnabled(boolean useLowPassFilter); void setBaseAngle(final double baseAngle);  }
@Test public void testDeltaNoMovement() { deadReckoning.delta[0] = 10.f; deadReckoning.delta[1] = 12.f; deadReckoning.moving = false; double x = deadReckoning.delta[0]; double y = deadReckoning.delta[1]; deadReckoning.calculateDeltaLoop(); assertTrue(x == deadReckoning.delta[0]); assertTrue(y == deadReckoning.delta[1]); }
@Test public void testDeltaNoAzimuth() { deadReckoning.delta[0] = 10.f; deadReckoning.delta[1] = 12.f; deadReckoning.azimuth = null; double x = deadReckoning.delta[0]; double y = deadReckoning.delta[1]; deadReckoning.calculateDeltaLoop(); assertTrue(x == deadReckoning.delta[0]); assertTrue(y == deadReckoning.delta[1]); }
@Test public void testCalculationDelta() { deadReckoning.moving = true; deadReckoning.azimuth = 1.57f; deadReckoning.motionModel = 1.f; deadReckoning.timestep = 100; deadReckoning.baseAngle = 1.57f; deadReckoning.calculateDeltaLoop(); assertEquals(0.f, deadReckoning.delta[0], 0.02f); assertEquals(1.f, deadReckoning.delta[1], 0.02f); }