magic #15
11
hortlog -s –n
Normal file
11
hortlog -s –n
Normal file
@ -0,0 +1,11 @@
|
||||
error: unknown option `-git'
|
||||
usage: git shortlog [<options>] [<revision-range>] [[--] <path>...]
|
||||
or: git log --pretty=short | git shortlog [<options>]
|
||||
|
||||
-c, --[no-]committer group by committer rather than author
|
||||
-n, --[no-]numbered sort output according to the number of commits per author
|
||||
-s, --[no-]summary suppress commit descriptions, only provides commit count
|
||||
-e, --[no-]email show the email address of each author
|
||||
-w[<w>[,<i1>[,<i2>]]] linewrap output
|
||||
--[no-]group <field> group by field
|
||||
|
||||
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 java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintStream;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class InterestingTests {
|
||||
|
||||
private Wizard wizard;
|
||||
@ -33,71 +29,6 @@ public class InterestingTests {
|
||||
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
|
||||
public void condition_spell_adds_condition() {
|
||||
Scanner testScanner = new Scanner(new ByteArrayInputStream("1\n1\n".getBytes()));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user