@Test public void testTakeDamage() throws Exception { int startHealth = humanCharacter.getHealth(); humanCharacter.takeDamage(startHealth - 1); assertEquals(startHealth - (startHealth - 1), humanCharacter.getHealth()); humanCharacter.takeDamage(startHealth - 1); }
@Test public void testTakeDamage() throws Exception { // Get the starting health int startHealth = humanCharacter.getHealth(); // Make the player take damage humanCharacter.takeDamage(5); assertEquals( "The player is not taking damage properly", startHealth - 5, humanCharacter.getHealth()); }
@Test public void testFireBullet() throws Exception { // Todo Implent Test humanCharacter.fireBullet(null); boolean bulletInGame = false; for (MovingEntity movingEntity : this.game.getMovingEntities()) { if (movingEntity.getClass() == Bullet.class) { Bullet bullet = (Bullet) movingEntity; if (bullet.getShooter() == humanCharacter) { bulletInGame = true; } } } assertTrue(bulletInGame); }
@Test public void testMove() throws Exception { Vector2 location = new Vector2(1, 1); humanCharacter.move(location, false); assertEquals(location, humanCharacter.getLocation()); location = new Vector2(-1, 1); Vector2 properLocation = new Vector2(0, 1); humanCharacter.move(location, false); assertEquals(properLocation, humanCharacter.getLocation()); location = new Vector2(1, -1); properLocation = new Vector2(1, 0); humanCharacter.move(location, false); assertEquals(properLocation, humanCharacter.getLocation()); location = new Vector2(1, -1); properLocation = new Vector2(1, 0); humanCharacter.move(location, false); assertEquals(properLocation, humanCharacter.getLocation()); location = new Vector2(801, 1); properLocation = new Vector2(800, 1); humanCharacter.setLocation(properLocation, false); humanCharacter.move(location, false); assertEquals(properLocation, humanCharacter.getLocation()); location = new Vector2(1, 481); properLocation = new Vector2(1, 480); humanCharacter.setLocation(properLocation, false); humanCharacter.move(location, false); assertEquals(properLocation, humanCharacter.getLocation()); }
@Test public void testGetScore() throws Exception { assertEquals(0, humanCharacter.getScore()); }
@Test public void testChangeRole() throws Exception { Role startingRole = humanCharacter.getRole(); int startingHealth = humanCharacter.getHealth(); int startingDamage = humanCharacter.getDamage(); int startingSpeed = humanCharacter.getSpeed(); int startingFireRate = humanCharacter.getFireRate(); Role newRole = new Sniper(); humanCharacter.changeRole(newRole); assertNotEquals("the role has not changed", startingRole, humanCharacter.getRole()); assertEquals("the new role is not the one that was set", newRole, humanCharacter.getRole()); assertNotEquals( "the health has not changed after switching role", startingHealth, humanCharacter.getHealth()); assertNotEquals( "the damage has not changed after switching role", startingDamage, humanCharacter.getDamage()); assertNotEquals( "the speed has not changed after switching role", startingSpeed, humanCharacter.getSpeed()); assertNotEquals( "the fire-rate has not changed after switching role", startingFireRate, humanCharacter.getFireRate()); }
@Test public void testGetRole() throws Exception { assertEquals(role, humanCharacter.getRole()); }
@Test public void testGetDirection() throws Exception { // The default direction when an object is initialized will be 0 int direction = (int) humanCharacter.getAngle(); assertEquals("The initial direction was not set properly", 0, direction); }