code-coverage-Emilia #24
20
src/main/java/Entity/Chest.java
Normal file
20
src/main/java/Entity/Chest.java
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package Entity;
|
||||||
|
|
||||||
|
public class Chest extends Entity {
|
||||||
|
|
||||||
|
private Position position;
|
||||||
|
|
||||||
|
public Chest(String name, Position position) {
|
||||||
|
super(name);
|
||||||
|
this.position = position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Position getPosition() {
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPosition(Position position) {
|
||||||
|
this.position = position;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -31,9 +31,6 @@ public class Shade extends Monster implements CanMove, CanAttack {
|
|||||||
if (isDead()) {
|
if (isDead()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (health == MIN_HEALTH) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (health == MAX_HEALTH) {
|
if (health == MAX_HEALTH) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,9 +36,7 @@ public class Troll extends Monster implements CanMove, CanAttack {
|
|||||||
if (isDead()) {
|
if (isDead()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (health == MIN_HEALTH) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (health == MAX_HEALTH) {
|
if (health == MAX_HEALTH) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,13 +27,13 @@ public class MonsterTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shade_cannot_move_after_death() {
|
void shade_cannot_moveTo_after_death() {
|
||||||
defaultShade.kill();
|
defaultShade.kill();
|
||||||
assertThat(false, equalTo(defaultShade.moveTo(defaultDestination, mockWorld)));
|
assertThat(false, equalTo(defaultShade.moveTo(defaultDestination, mockWorld)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void troll_cannot_move_after_death() {
|
void troll_cannot_moveTo_after_death() {
|
||||||
defaultTroll.kill();
|
defaultTroll.kill();
|
||||||
assertThat(false, equalTo(defaultTroll.moveTo(defaultDestination, mockWorld)));
|
assertThat(false, equalTo(defaultTroll.moveTo(defaultDestination, mockWorld)));
|
||||||
}
|
}
|
||||||
@@ -130,13 +130,13 @@ public class MonsterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shade_cannot_heal_when_out_of_energy() {
|
void shade_cannot_heal_when_out_of_energy() {
|
||||||
Shade shade = new Shade(Shade.MAX_HEALTH, Shade.MIN_ENERGY, Shade.DEFAULT_POSITION);
|
Shade shade = new Shade(Shade.MAX_HEALTH - 1, Shade.MIN_ENERGY, Shade.DEFAULT_POSITION);
|
||||||
assertThat(shade.heal(), equalTo(false));
|
assertThat(shade.heal(), equalTo(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void troll_cannot_heal_when_out_of_energy() {
|
void troll_cannot_heal_when_out_of_energy() {
|
||||||
Troll troll = new Troll(Troll.MAX_HEALTH, Troll.MIN_ENERGY, Troll.DEFAULT_POSITION);
|
Troll troll = new Troll(Troll.MAX_HEALTH - 1, Troll.MIN_ENERGY, Troll.DEFAULT_POSITION);
|
||||||
assertThat(troll.heal(), equalTo(false));
|
assertThat(troll.heal(), equalTo(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,8 +257,136 @@ public class MonsterTest {
|
|||||||
assertThat(defaultTroll.heal(), equalTo(false));
|
assertThat(defaultTroll.heal(), equalTo(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
// HÄR BÖRJAR BESLUTSTABELLSTESTERNA
|
@Test
|
||||||
|
void shade_wont_heal_at_max_health() {
|
||||||
|
assertThat(defaultShade.heal(), equalTo(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void troll_wont_heal_at_max_health() {
|
||||||
|
assertThat(defaultTroll.heal(), equalTo(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shade_taking_damage_greater_than_health_dies() {
|
||||||
|
defaultShade.takeDamage(Shade.MAX_HEALTH+1);
|
||||||
|
assertThat(defaultShade.isDead(), equalTo(true));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void troll_taking_damage_greater_than_health_dies() {
|
||||||
|
defaultTroll.takeDamage(Troll.MAX_HEALTH + 1);
|
||||||
|
assertThat(defaultTroll.isDead(), equalTo(true));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shade_wont_move_at_zero_energy() {
|
||||||
|
defaultShade = new Shade(Shade.MAX_HEALTH, Shade.MIN_ENERGY, Shade.DEFAULT_POSITION);
|
||||||
|
assertThat(defaultShade.move(mockWorld), equalTo(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void troll_wont_move_at_zero_energy() {
|
||||||
|
defaultTroll = new Troll(Troll.MAX_HEALTH, Troll.MIN_ENERGY, Troll.DEFAULT_POSITION);
|
||||||
|
assertThat(defaultTroll.move(mockWorld), equalTo(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void cant_create_shade_with_negative_energy() {
|
||||||
|
defaultShade = new Shade(Shade.MAX_HEALTH, Shade.MIN_ENERGY - 1, Shade.DEFAULT_POSITION);
|
||||||
|
assertThat(defaultShade.getEnergy(), equalTo(Shade.MIN_ENERGY));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void cant_create_troll_with_negative_energy() {
|
||||||
|
defaultTroll = new Troll(Troll.MAX_HEALTH, Troll.MIN_ENERGY - 1, Troll.DEFAULT_POSITION);
|
||||||
|
assertThat(defaultTroll.getEnergy(), equalTo(Troll.MIN_ENERGY));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void cant_create_shade_with_no_health() {
|
||||||
|
defaultShade = new Shade(Shade.MIN_HEALTH, Shade.MAX_ENERGY, Shade.DEFAULT_POSITION);
|
||||||
|
assertThat(defaultShade.getHealth(), greaterThan(Shade.MIN_HEALTH));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void cant_create_troll_with_no_health() {
|
||||||
|
defaultTroll = new Troll(Troll.MIN_HEALTH, Troll.MAX_ENERGY, Troll.DEFAULT_POSITION);
|
||||||
|
assertThat(defaultTroll.getHealth(), greaterThan(Troll.MIN_HEALTH));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shade_cant_take_negative_damage() {
|
||||||
|
assertThat(defaultShade.takeDamage(-9), equalTo(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void troll_cant_take_negative_damage() {
|
||||||
|
assertThat(defaultTroll.takeDamage(-9), equalTo(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shade_wont_move_when_dead() {
|
||||||
|
defaultShade.kill();
|
||||||
|
assertThat(defaultShade.move(mockWorld), equalTo(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void troll_wont_move_when_dead() {
|
||||||
|
defaultTroll.kill();
|
||||||
|
assertThat(defaultTroll.move(mockWorld), equalTo(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shade_wont_moveTo_at_zero_energy() {
|
||||||
|
defaultShade = new Shade(Shade.MAX_HEALTH, Shade.MIN_ENERGY, Shade.DEFAULT_POSITION);
|
||||||
|
assertThat(defaultShade.moveTo(defaultDestination, mockWorld), equalTo(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void troll_wont_moveTo_at_zero_energy() {
|
||||||
|
defaultTroll = new Troll(Troll.MAX_HEALTH, Troll.MIN_ENERGY, Troll.DEFAULT_POSITION);
|
||||||
|
assertThat(defaultTroll.moveTo(defaultDestination, mockWorld), equalTo(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void cant_create_shade_with_more_than_max_health() {
|
||||||
|
defaultShade = new Shade(Shade.MAX_HEALTH + 1, Shade.MAX_ENERGY, Shade.DEFAULT_POSITION);
|
||||||
|
assertThat(defaultShade.getHealth(), lessThanOrEqualTo(Shade.MAX_HEALTH));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void cant_create_troll_with_more_than_max_health() {
|
||||||
|
defaultTroll = new Troll(Troll.MAX_HEALTH + 1, Troll.MAX_ENERGY, Troll.DEFAULT_POSITION);
|
||||||
|
assertThat(defaultTroll.getHealth(), lessThanOrEqualTo(Troll.MAX_HEALTH));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void cant_create_shade_with_more_than_max_energy() {
|
||||||
|
defaultShade = new Shade(Shade.MAX_HEALTH, Shade.MAX_ENERGY + 1, Shade.DEFAULT_POSITION);
|
||||||
|
assertThat(defaultShade.getEnergy(), lessThanOrEqualTo(Shade.MAX_ENERGY));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void cant_create_troll_with_more_than_max_energy() {
|
||||||
|
defaultTroll = new Troll(Troll.MAX_HEALTH, Troll.MAX_ENERGY + 1, Troll.DEFAULT_POSITION);
|
||||||
|
assertThat(defaultTroll.getEnergy(), lessThanOrEqualTo(Troll.MAX_ENERGY));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shade_can_move_to_tile_with_non_player_entity() {
|
||||||
|
Chest mockChest = mock(Chest.class);
|
||||||
|
when(mockChest.getPosition()).thenReturn(defaultDestination);
|
||||||
|
Map<Position, Entity> entitiesAtDestination = new HashMap();
|
||||||
|
entitiesAtDestination.put(defaultDestination, mockChest);
|
||||||
|
when(mockWorld.getPositionEntityMap()).thenReturn(entitiesAtDestination);
|
||||||
|
|
||||||
|
assertThat(defaultShade.moveTo(defaultDestination, mockWorld), equalTo(true));
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// HÄR BÖRJAR BESLUTSTABELLSTESTERNA
|
||||||
|
//
|
||||||
@Test
|
@Test
|
||||||
void decision_table_t1() {
|
void decision_table_t1() {
|
||||||
defaultTroll.kill();
|
defaultTroll.kill();
|
||||||
|
|||||||
Reference in New Issue
Block a user