-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix experience being not calculated correctly (#142)
- Loading branch information
Showing
4 changed files
with
103 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/test/java/pl/uj/io/cuteanimals/action/ability/FocusTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package pl.uj.io.cuteanimals.action.ability; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import pl.uj.io.cuteanimals.model.Monster; | ||
import pl.uj.io.cuteanimals.model.NPCAttributes; | ||
import pl.uj.io.cuteanimals.model.Player; | ||
import pl.uj.io.cuteanimals.model.PlayerAttributes; | ||
|
||
class FocusTest { | ||
private Player player; | ||
private Monster dummy; | ||
private PlayerAttributes attrs; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
player = new Player(); | ||
attrs = (PlayerAttributes) player.getAttributes(); | ||
player.getAttributes().addLevel(4); | ||
|
||
dummy = new Monster("dummy", new NPCAttributes(0, 1, 1, 0)); | ||
player.getFightManager().beginFight(dummy); | ||
var focus = new Focus(); | ||
focus.execute(player); | ||
} | ||
|
||
@Test | ||
void shouldDrain20Mana() { | ||
var manaBefore = attrs.getMana(); | ||
player.getFightManager().attack(); | ||
assertThat(attrs.getMana() == manaBefore - 20); | ||
} | ||
|
||
@Test | ||
void atLeast20ManaNeeded() { | ||
attrs.addMana(-200); | ||
var result = (new Focus()).execute(player); | ||
assertThat( | ||
result.getMessage() | ||
.equals("Not enough mana! You need at least 20 mana to use this ability.")); | ||
} | ||
|
||
@Test | ||
void attackShouldInflictAdditionalDamage() { | ||
player.getFightManager().attack(); | ||
var playerAttack = player.getAttributes().getAttack(); | ||
var playerDamage = attrs.getDamage(); | ||
assertThat(dummy.getAttributes().getHealth() == -(playerDamage + 2 * playerAttack)); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/test/java/pl/uj/io/cuteanimals/model/fight/FightManagerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package pl.uj.io.cuteanimals.model.fight; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import pl.uj.io.cuteanimals.model.Monster; | ||
import pl.uj.io.cuteanimals.model.NPCAttributes; | ||
import pl.uj.io.cuteanimals.model.Player; | ||
import pl.uj.io.cuteanimals.model.PlayerAttributes; | ||
|
||
class FightManagerTest { | ||
private Player player; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
player = new Player(); | ||
} | ||
|
||
@Test | ||
void endBattleEqualLevelExperienceTest() { | ||
var dummy = new Monster("dummy", new NPCAttributes(1, 1, 1, 1)); | ||
|
||
player.getFightManager().beginFight(dummy); | ||
player.getFightManager().endBattle(); | ||
assertThat(((PlayerAttributes) player.getAttributes()).getExperience() == 1); | ||
} | ||
|
||
@Test | ||
void endBattleMonsterHigherLevelExperienceTest() { | ||
var dummy = new Monster("dummy", new NPCAttributes(1, 1, 11, 1)); | ||
|
||
player.getFightManager().beginFight(dummy); | ||
player.getFightManager().endBattle(); | ||
assertThat(((PlayerAttributes) player.getAttributes()).getExperience() == 1 + 5); | ||
} | ||
|
||
@Test | ||
void endBattleMonsterLowerLevelExperienceTest() { | ||
player.getAttributes().addLevel(1); | ||
var dummy = new Monster("dummy", new NPCAttributes(1, 1, 11, 1)); | ||
|
||
player.getFightManager().beginFight(dummy); | ||
player.getFightManager().endBattle(); | ||
assertThat(((PlayerAttributes) player.getAttributes()).getExperience() == 1); | ||
} | ||
} |