magic #15
188
src/test/java/EPTest.java
Normal file
188
src/test/java/EPTest.java
Normal file
@ -0,0 +1,188 @@
|
|||||||
|
import Combat.OffensiveDamageSpell;
|
||||||
|
import Entity.Entity;
|
||||||
|
import Entity.Player;
|
||||||
|
import Job.Wizard;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.util.Scanner;
|
||||||
|
import static org.hamcrest.Matchers.*;
|
||||||
|
|
||||||
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.PrintStream;
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
public class EPTest {
|
||||||
|
|
||||||
|
private Wizard wizard;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void setup() {
|
||||||
|
wizard = new Wizard();
|
||||||
|
}
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void cleanup() {
|
||||||
|
Entity.getEntities().clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCastSpell_successfulCast() {
|
||||||
|
Scanner testScanner = new Scanner(new ByteArrayInputStream("1\n1\n".getBytes()));
|
||||||
|
wizard = new Wizard(testScanner);
|
||||||
|
|
||||||
|
Player player = new Player("Gandalf", wizard);
|
||||||
|
|
||||||
|
player.setMana(50);
|
||||||
|
player.setHealth(100);
|
||||||
|
|
||||||
|
OffensiveDamageSpell fireball = new OffensiveDamageSpell("Fireball", 20, 1,15);
|
||||||
|
player.getSpellBook().add(fireball);
|
||||||
|
|
||||||
|
int initialMana = player.getMana();
|
||||||
|
|
||||||
|
wizard.castSpell(player);
|
||||||
|
|
||||||
|
assertThat(player.getMana(), is(initialMana - fireball.getCost()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCastSpell_notEnoughMana() {
|
||||||
|
Scanner testScanner = new Scanner(new ByteArrayInputStream("1\n1\n".getBytes()));
|
||||||
|
wizard = new Wizard(testScanner);
|
||||||
|
|
||||||
|
Player player = new Player("Merlin", wizard);
|
||||||
|
player.setMana(10);
|
||||||
|
player.setHealth(100);
|
||||||
|
|
||||||
|
OffensiveDamageSpell fireball = new OffensiveDamageSpell("Fireball", 20, 1,15);
|
||||||
|
player.getSpellBook().add(fireball);
|
||||||
|
|
||||||
|
int initialMana = player.getMana();
|
||||||
|
|
||||||
|
wizard.castSpell(player);
|
||||||
|
|
||||||
|
assertThat(player.getMana(), is(initialMana));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCastSpell_indexOverBoundary() {
|
||||||
|
Scanner testScanner = new Scanner(new ByteArrayInputStream("2\n".getBytes()));
|
||||||
|
wizard = new Wizard(testScanner);
|
||||||
|
|
||||||
|
Player player = new Player("Brick", wizard);
|
||||||
|
player.setMana(50);
|
||||||
|
player.setHealth(100);
|
||||||
|
|
||||||
|
OffensiveDamageSpell fireball = new OffensiveDamageSpell("Fireball", 20, 1, 15);
|
||||||
|
player.getSpellBook().add(fireball);
|
||||||
|
|
||||||
|
ByteArrayOutputStream outContent = new ByteArrayOutputStream();
|
||||||
|
PrintStream originalOut = System.out;
|
||||||
|
System.setOut(new PrintStream(outContent));
|
||||||
|
|
||||||
|
try {
|
||||||
|
wizard.castSpell(player);
|
||||||
|
String output = outContent.toString();
|
||||||
|
assertTrue(output.contains("Invalid choice!"));
|
||||||
|
} finally {
|
||||||
|
System.setOut(originalOut);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCastSpell_indexUnderBoundary() {
|
||||||
|
Scanner testScanner = new Scanner(new ByteArrayInputStream("0\n".getBytes()));
|
||||||
|
wizard = new Wizard(testScanner);
|
||||||
|
|
||||||
|
Player player = new Player("Brick", wizard);
|
||||||
|
player.setMana(50);
|
||||||
|
player.setHealth(100);
|
||||||
|
|
||||||
|
OffensiveDamageSpell fireball = new OffensiveDamageSpell("Fireball", 20, 1, 15);
|
||||||
|
player.getSpellBook().add(fireball);
|
||||||
|
|
||||||
|
ByteArrayOutputStream outContent = new ByteArrayOutputStream();
|
||||||
|
PrintStream originalOut = System.out;
|
||||||
|
System.setOut(new PrintStream(outContent));
|
||||||
|
|
||||||
|
try {
|
||||||
|
wizard.castSpell(player);
|
||||||
|
String output = outContent.toString();
|
||||||
|
assertTrue(output.contains("Invalid choice!"));
|
||||||
|
} finally {
|
||||||
|
System.setOut(originalOut);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void select_spell_target_index_over_boundry() {
|
||||||
|
Scanner testScanner = new Scanner(new ByteArrayInputStream("1\n2\n".getBytes()));
|
||||||
|
wizard = new Wizard(testScanner);
|
||||||
|
|
||||||
|
Player player = new Player("Alfon", wizard);
|
||||||
|
player.setMana(50);
|
||||||
|
|
||||||
|
OffensiveDamageSpell fireball = new OffensiveDamageSpell("Fireball", 20, 1, 15);
|
||||||
|
player.getSpellBook().add(fireball);
|
||||||
|
|
||||||
|
ByteArrayOutputStream outContent = new ByteArrayOutputStream();
|
||||||
|
PrintStream originalOut = System.out;
|
||||||
|
System.setOut(new PrintStream(outContent));
|
||||||
|
|
||||||
|
try {
|
||||||
|
wizard.castSpell(player);
|
||||||
|
String output = outContent.toString();
|
||||||
|
assertTrue(output.contains("Invalid choice!"));
|
||||||
|
} finally {
|
||||||
|
System.setOut(originalOut);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void select_spell_target_index_under_boundry() {
|
||||||
|
Scanner testScanner = new Scanner(new ByteArrayInputStream("1\n0\n".getBytes()));
|
||||||
|
wizard = new Wizard(testScanner);
|
||||||
|
|
||||||
|
Player player = new Player("Alfon", wizard);
|
||||||
|
player.setMana(50);
|
||||||
|
|
||||||
|
OffensiveDamageSpell fireball = new OffensiveDamageSpell("Fireball", 20, 1, 15);
|
||||||
|
player.getSpellBook().add(fireball);
|
||||||
|
|
||||||
|
ByteArrayOutputStream outContent = new ByteArrayOutputStream();
|
||||||
|
PrintStream originalOut = System.out;
|
||||||
|
System.setOut(new PrintStream(outContent));
|
||||||
|
|
||||||
|
try {
|
||||||
|
wizard.castSpell(player);
|
||||||
|
String output = outContent.toString();
|
||||||
|
assertTrue(output.contains("Invalid choice!"));
|
||||||
|
} finally {
|
||||||
|
System.setOut(originalOut);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void cant_cast_spell_with_empty_spellbook() {
|
||||||
|
Scanner testScanner = new Scanner(new ByteArrayInputStream("2\n".getBytes()));
|
||||||
|
wizard = new Wizard(testScanner);
|
||||||
|
|
||||||
|
Player player = new Player("Brick", wizard);
|
||||||
|
|
||||||
|
ByteArrayOutputStream outContent = new ByteArrayOutputStream();
|
||||||
|
PrintStream originalOut = System.out;
|
||||||
|
System.setOut(new PrintStream(outContent));
|
||||||
|
|
||||||
|
try {
|
||||||
|
wizard.castSpell(player);
|
||||||
|
String output = outContent.toString();
|
||||||
|
assertTrue(output.contains("You haven't learned any spells"));
|
||||||
|
} finally {
|
||||||
|
System.setOut(originalOut);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -15,10 +15,6 @@ import static org.hamcrest.Matchers.*;
|
|||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.PrintStream;
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
public class InterestingTests {
|
public class InterestingTests {
|
||||||
|
|
||||||
private Wizard wizard;
|
private Wizard wizard;
|
||||||
@ -33,71 +29,6 @@ public class InterestingTests {
|
|||||||
Entity.getEntities().clear();
|
Entity.getEntities().clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCastSpell_successfulCast() {
|
|
||||||
Scanner testScanner = new Scanner(new ByteArrayInputStream("1\n1\n".getBytes()));
|
|
||||||
wizard = new Wizard(testScanner);
|
|
||||||
|
|
||||||
Player player = new Player("Gandalf", wizard);
|
|
||||||
|
|
||||||
player.setMana(50);
|
|
||||||
player.setHealth(100);
|
|
||||||
|
|
||||||
OffensiveDamageSpell fireball = new OffensiveDamageSpell("Fireball", 20, 1,15);
|
|
||||||
player.getSpellBook().add(fireball);
|
|
||||||
|
|
||||||
int initialMana = player.getMana();
|
|
||||||
|
|
||||||
wizard.castSpell(player);
|
|
||||||
|
|
||||||
assertThat(player.getMana(), is(initialMana - fireball.getCost()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCastSpell_notEnoughMana() {
|
|
||||||
Scanner testScanner = new Scanner(new ByteArrayInputStream("1\n1\n".getBytes()));
|
|
||||||
wizard = new Wizard(testScanner);
|
|
||||||
|
|
||||||
Player player = new Player("Merlin", wizard);
|
|
||||||
player.setMana(10);
|
|
||||||
player.setHealth(100);
|
|
||||||
|
|
||||||
OffensiveDamageSpell fireball = new OffensiveDamageSpell("Fireball", 20, 1,15);
|
|
||||||
player.getSpellBook().add(fireball);
|
|
||||||
|
|
||||||
int initialMana = player.getMana();
|
|
||||||
|
|
||||||
wizard.castSpell(player);
|
|
||||||
|
|
||||||
assertThat(player.getMana(), is(initialMana));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCastSpell_indexOutOfBounds() {
|
|
||||||
Scanner testScanner = new Scanner(new ByteArrayInputStream("2\n".getBytes()));
|
|
||||||
wizard = new Wizard(testScanner);
|
|
||||||
|
|
||||||
Player player = new Player("Brick", wizard);
|
|
||||||
player.setMana(50);
|
|
||||||
player.setHealth(100);
|
|
||||||
|
|
||||||
OffensiveDamageSpell fireball = new OffensiveDamageSpell("Fireball", 20, 1, 15);
|
|
||||||
player.getSpellBook().add(fireball);
|
|
||||||
|
|
||||||
ByteArrayOutputStream outContent = new ByteArrayOutputStream();
|
|
||||||
PrintStream originalOut = System.out;
|
|
||||||
System.setOut(new PrintStream(outContent));
|
|
||||||
|
|
||||||
try {
|
|
||||||
wizard.castSpell(player);
|
|
||||||
String output = outContent.toString();
|
|
||||||
assertTrue(output.contains("Invalid choice!"));
|
|
||||||
} finally {
|
|
||||||
System.setOut(originalOut);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void condition_spell_adds_condition() {
|
public void condition_spell_adds_condition() {
|
||||||
Scanner testScanner = new Scanner(new ByteArrayInputStream("1\n1\n".getBytes()));
|
Scanner testScanner = new Scanner(new ByteArrayInputStream("1\n1\n".getBytes()));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user