public void testCercaContextWithObstacles() {
NativeSensorPortStub nativeSensorPortStub = new NativeSensorPortStub();
nativeSensorPortStub.setISensorPort(0, sensorStub);
NativeSensorPort nativeSensorPort = NativeSensorPort.getInstance();
nativeSensorPort.setBehaviour(nativeSensorPortStub);
UltrasonicSensor sensor = new UltrasonicSensor(SensorPort.S1);
sensorStub.setPosX(0);
sensorStub.setPosY(0);
sensorStub.setHeading(90);
// Continous-Modus testen (ist der default-Modus):
assertEquals(255, sensor.getDistance());
// Ein Obstacle, aber nicht per Sensor erreichbar:
obstacles.add(new Obstacle(100, 20));
sensorStub.setObstacles(obstacles);
sleep15ms();
assertEquals(255, sensor.getDistance());
// Ein Obstacle vor dem Sensor:
Obstacle tempObst = new Obstacle(0, 0);
int halfObstHeightInCm = (int) ((tempObst.getActiveBounds().height/2) / ArenaGui.FACTOR_PX_CM);
tempObst.setPosY((int) ((20 + halfObstHeightInCm) * ArenaGui.FACTOR_PX_CM));
obstacles.add(tempObst);
sensorStub.setObstacles(obstacles);
sleep15ms();
assertEquals(20, sensor.getDistance());
// Ping-Modus testen:
sensor.ping();
int dist[] = new int[8];
sensor.getDistances(dist);
for (int i = 0; i < dist.length; i++) {
assertEquals(20, dist[i]);
}
}