@@ -0,0 +1,1514 @@
+package asmcup.runtime;%0A%0Aimport asmcup.vm.VM;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0A%0Aimport java.util.Arrays;%0A%0Aimport static org.junit.Assert.assertTrue;%0A%0Apublic class RobotTest %7B%0A%09Robot robot = null;%0A%0A%09@Before%0A%09public void setUp() %7B%0A%09%09robot = new Robot(42);%0A%09%09robot.position(42, 21);%0A%09%7D%0A%0A%09@Test%0A%09public void testAccelerometer() %7B%0A%09%09World world = generateEmptyWorld((int) robot.getX(), (int) robot.getY(), 2);%0A%09%09// Read Accelerometer%0A%09%09VM vm = robot.getVM();%0A%09%09vm.push8(Robot.IO_ACCELEROMETER);%0A%09%09vm.setIO(true);%0A%09%09robot.handleIO(world);%0A%0A%09%09// We did not drive, so we should expect 0 values.%0A%09%09float x = vm.popFloat();%0A%09%09float y = vm.popFloat();%0A%09%09assertTrue(%22X is 0%22, Math.abs(0.0f - x) %3C 0.001f);%0A%09%09assertTrue(%22Y is 0%22, Math.abs(0.0f - y) %3C 0.001f);%0A%09%09assertTrue(%22X == Y%22, Math.abs(x - y) %3C 0.001f);%0A%0A%09%09// Drive a little bit%0A%09%09robot.setMotor(1.0f);%0A%09%09robot.setSteer(0.5f);%0A%09%09robot.tickHardware(world);%0A%0A%0A%09%09vm.push8(Robot.IO_ACCELEROMETER);%0A%09%09vm.setIO(true);%0A%09%09robot.handleIO(world);%0A%0A%09%09// We drove, so we should not expect 0 values.%0A%09%09x = vm.popFloat();%0A%09%09y = vm.popFloat();%0A%09%09assertTrue(%22X is 0%22, Math.abs(0.0f - x) %3E 0.001f);%0A%09%09assertTrue(%22Y is 0%22, Math.abs(0.0f - y) %3E 0.001f);%0A%09%09assertTrue(%22X == Y%22, Math.abs(x - y) %3E 0.001f);%0A%09%7D%0A%0A%09public World generateEmptyWorld(int x, int y, int radius) %7B%0A%09%09World world = new World();%0A%09%09for (int i = x - radius; i %3C x + radius; ++i) %7B%0A%09%09%09for (int j = y - radius; j %3C y + radius; ++j) %7B%0A%09%09%09%09world.setTileXY(i, j, Cell.TILE_GROUND);%0A%09%09%09%7D%0A%09%09%7D%0A%0A%09%09return world;%0A%09%7D%0A%7D%0A

Add Test for accelerometer (#88)