package asmcup.runtime;

import asmcup.vm.VM;
import org.junit.Before;
import org.junit.Test;

import java.util.Arrays;

import static org.junit.Assert.assertTrue;

public class RobotTest {
	Robot robot = null;

	@Before
	public void setUp() {
		robot = new Robot(42);
		robot.position(42, 21);
	}

	@Test
	public void testAccelerometer() {
		World world = generateEmptyWorld((int) robot.getX(), (int) robot.getY(), 2);
		// Read Accelerometer
		VM vm = robot.getVM();
		vm.push8(Robot.IO_ACCELEROMETER);
		vm.setIO(true);
		robot.handleIO(world);

		// We did not drive, so we should expect 0 values.
		float x = vm.popFloat();
		float y = vm.popFloat();
		assertTrue("X is 0", Math.abs(0.0f - x) < 0.001f);
		assertTrue("Y is 0", Math.abs(0.0f - y) < 0.001f);
		assertTrue("X == Y", Math.abs(x - y) < 0.001f);

		// Drive a little bit
		robot.setMotor(1.0f);
		robot.setSteer(0.5f);
		robot.tickHardware(world);


		vm.push8(Robot.IO_ACCELEROMETER);
		vm.setIO(true);
		robot.handleIO(world);

		// We drove, so we should not expect 0 values.
		x = vm.popFloat();
		y = vm.popFloat();
		assertTrue("X is 0", Math.abs(0.0f - x) > 0.001f);
		assertTrue("Y is 0", Math.abs(0.0f - y) > 0.001f);
		assertTrue("X == Y", Math.abs(x - y) > 0.001f);
	}

	public World generateEmptyWorld(int x, int y, int radius) {
		World world = new World();
		for (int i = x - radius; i < x + radius; ++i) {
			for (int j = y - radius; j < y + radius; ++j) {
				world.setTileXY(i, j, Cell.TILE_GROUND);
			}
		}

		return world;
	}
}

@@ -114,16 +114,109 @@
 rrays;%0A%0A
+import static org.junit.Assert.assertEquals;%0Aimport static org.junit.Assert.assertNotEquals;%0A
 import s
@@ -250,16 +250,16 @@
 rtTrue;%0A
-
 %0Apublic 
@@ -754,146 +754,80 @@
 sert
-True(%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
+Equals(0, x, 0.001f);%0A%09%09assertEquals(0, y, 0.001f);%0A%09%09assertEquals(x, y,
  0.0
@@ -1119,146 +1119,91 @@
 sert
-True(%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
+NotEquals(0f, x, 0.001f);%0A%09%09assertNotEquals(0f, y, 0.001f);%0A%09%09assertNotEquals(x, y,
  0.0

Simplify asserts in RobotTest (#98)