package test;
import org.junit.*;
import static org.junit.Assert.*;

public class Sprite4Tester {
	private Sprite4 testSprite;
	final static private int max = 100;
	
	@Before public void setUp() {
		testSprite = new Ball4(0, 0, max, max);
	}
	
	@Test public void turnTest() {
		testSprite.turn(Math.PI/2);
		assertTrue(testSprite.heading() == Math.PI/2);
	}
	
	@Test public void xWrapBig() {
		wrapTest();
	}
	
	@Test public void xWrapSmall() {
		testSprite.turn(Math.PI);
		wrapTest();
	}
	
	@Test public void yWrapBig() {
		testSprite.turn(Math.PI/2);
		wrapTest();
	}
	
	@Test public void yWrapSmall() {
		testSprite.turn(-Math.PI/2);
		wrapTest();
	}
	
	@Test public void wrapDiagonal1() {
		testSprite.turn(Math.PI/4);
		wrapTest();
	}
	
	@Test public void wrapDiagonal2() {
		testSprite.turn(3*Math.PI/4);
		wrapTest();
	}
	
	@Test public void wrapDiagonal3() {
		testSprite.turn(5*Math.PI/4);
	}
	
	@Test public void wrapDiagonal4() {
		testSprite.turn(7*Math.PI/4);
	}
	
	public void wrapTest() {
		double xPrev = testSprite.xCenter(), yPrev = testSprite.yCenter();
		while (!testSprite.wrapped(xPrev, yPrev)) {
			testSprite.move();
			assertTrue(testSprite.centerInBounds());
			assertTrue(testSprite.headingFromCenter(xPrev, yPrev) == testSprite.heading());
			assertTrue(testSprite.distanceFromCenter(xPrev, yPrev) == testSprite.speed());
			xPrev = testSprite.xCenter();
			yPrev = testSprite.yCenter();
		}
	}
}
