-
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
106 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
53 changes: 53 additions & 0 deletions
53
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,53 @@ | ||
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()).isEqualTo(manaBefore - 20); | ||
} | ||
|
||
@Test | ||
void atLeast20ManaNeeded() { | ||
attrs.addMana(-200); | ||
var result = (new Focus()).execute(player); | ||
assertThat(result.getMessage()) | ||
.isEqualTo("* 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(); | ||
var expected = -(playerDamage + 2 * playerAttack); | ||
// getDamage is randomized | ||
assertThat(dummy.getAttributes().getHealth()).isBetween(expected - 1, expected); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
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,49 @@ | ||
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; | ||
private PlayerAttributes attrs; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
player = new Player(); | ||
attrs = (PlayerAttributes) player.getAttributes(); | ||
} | ||
|
||
@Test | ||
void endBattleEqualLevelExperienceTest() { | ||
var dummy = new Monster("dummy", new NPCAttributes(1, 1, 1, 1)); | ||
|
||
player.getFightManager().beginFight(dummy); | ||
player.getFightManager().endBattle(); | ||
assertThat(attrs.getExperience() == 1); | ||
} | ||
|
||
@Test | ||
void endBattleMonsterHigherLevelExperienceTest() { | ||
var dummy = new Monster("dummy", new NPCAttributes(1, 1, 11, 1)); | ||
|
||
player.getFightManager().beginFight(dummy); | ||
player.getFightManager().endBattle(); | ||
assertThat(attrs.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(attrs.getExperience() == 1); | ||
} | ||
} |