refactor: create base test class for later use

This commit is contained in:
punchready 2021-06-04 03:53:00 +02:00
parent 1525fe9a41
commit 0fce509111
2 changed files with 82 additions and 69 deletions

View File

@ -0,0 +1,80 @@
package uulm.teamname.marvelous.gamelibrary.gamelogic;
import uulm.teamname.marvelous.gamelibrary.config.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.concurrent.ThreadLocalRandom;
public class BaseGameLogicTest {
protected static final Iterator<Integer> randomIntegers = ThreadLocalRandom.current().ints().iterator();
protected static final PartyConfig partyConfig = new PartyConfig();
protected static final CharacterConfig characterConfig = new CharacterConfig();
protected static final ScenarioConfig scenarioConfig = new ScenarioConfig();
protected static final ArrayList<Integer> player1Selection = new ArrayList<>();
protected static final ArrayList<Integer> player2Selection = new ArrayList<>();
protected static void generate() {
partyConfig.maxRounds = 100;
partyConfig.mindStoneCD = 2;
partyConfig.powerStoneCD = 3;
partyConfig.realityStoneCD = 4;
partyConfig.soulStoneCD = 5;
partyConfig.spaceStoneCD = 6;
partyConfig.timeStoneCD = 7;
partyConfig.mindStoneDMG = 3;
characterConfig.characters = new CharacterProperties[] {
generateCharacter(), generateCharacter(), generateCharacter(), generateCharacter(), generateCharacter(), generateCharacter(),
generateCharacter(), generateCharacter(), generateCharacter(), generateCharacter(), generateCharacter(), generateCharacter()
};
scenarioConfig.name = generateName(20);
scenarioConfig.author = generateName(20);
scenarioConfig.scenario = new FieldType[20][20];
for(int x = 0; x < scenarioConfig.scenario[0].length; x++) {
for(int y = 0; y < scenarioConfig.scenario.length; y++) {
if(Math.abs(randomIntegers.next() % 100) < 10) {
scenarioConfig.scenario[y][x] = FieldType.ROCK;
}else {
scenarioConfig.scenario[y][x] = FieldType.GRASS;
}
}
}
for(int i = 0; i < 6; i++) {
player1Selection.add(i);
}
for(int i = 6; i < 12; i++) {
player2Selection.add(i);
}
}
private static String generateName(int length) {
StringBuilder name = new StringBuilder();
for (int j = 0; j < length; j++) {
name.append((char) (
65 + Math.abs(randomIntegers.next() % 26) + 32 * Math.abs(randomIntegers.next() % 2)
));
}
return name.toString();
}
private static CharacterProperties generateCharacter() {
CharacterProperties props = new CharacterProperties();
props.name = generateName(10);
props.HP = Math.abs(randomIntegers.next() % 15 + 5);
props.MP = Math.abs(randomIntegers.next() % 5 + 2);
props.AP = Math.abs(randomIntegers.next() % 5 + 2);
props.meleeDamage = Math.abs(randomIntegers.next() % 5 + 2);
props.rangedDamage = Math.abs(randomIntegers.next() % 5 + 2);
props.attackRange = Math.abs(randomIntegers.next() % 5 + 2);
return props;
}
}

View File

@ -10,81 +10,14 @@ import uulm.teamname.marvelous.gamelibrary.entities.Character;
import uulm.teamname.marvelous.gamelibrary.requests.*; import uulm.teamname.marvelous.gamelibrary.requests.*;
import java.util.*; import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
class GameLogicTest { class GameLogicTest extends BaseGameLogicTest {
private static final Iterator<Integer> randomIntegers = ThreadLocalRandom.current().ints().iterator();
private static final PartyConfig partyConfig = new PartyConfig();
private static final CharacterConfig characterConfig = new CharacterConfig();
private static final ScenarioConfig scenarioConfig = new ScenarioConfig();
private static final ArrayList<Integer> player1Selection = new ArrayList<>();
private static final ArrayList<Integer> player2Selection = new ArrayList<>();
@BeforeAll @BeforeAll
static void setUp() { static void setUp() {
partyConfig.maxRounds = 100; generate();
partyConfig.mindStoneCD = 2;
partyConfig.powerStoneCD = 3;
partyConfig.realityStoneCD = 4;
partyConfig.soulStoneCD = 5;
partyConfig.spaceStoneCD = 6;
partyConfig.timeStoneCD = 7;
partyConfig.mindStoneDMG = 3;
characterConfig.characters = new CharacterProperties[] {
generateCharacter(), generateCharacter(), generateCharacter(), generateCharacter(), generateCharacter(), generateCharacter(),
generateCharacter(), generateCharacter(), generateCharacter(), generateCharacter(), generateCharacter(), generateCharacter()
};
scenarioConfig.name = generateName(20);
scenarioConfig.author = generateName(20);
scenarioConfig.scenario = new FieldType[20][20];
for(int x = 0; x < scenarioConfig.scenario[0].length; x++) {
for(int y = 0; y < scenarioConfig.scenario.length; y++) {
if(Math.abs(randomIntegers.next() % 100) < 10) {
scenarioConfig.scenario[y][x] = FieldType.ROCK;
}else {
scenarioConfig.scenario[y][x] = FieldType.GRASS;
}
}
}
for(int i = 0; i < 6; i++) {
player1Selection.add(i);
}
for(int i = 6; i < 12; i++) {
player2Selection.add(i);
}
}
private static String generateName(int length) {
StringBuilder name = new StringBuilder();
for (int j = 0; j < length; j++) {
name.append((char) (
65 + Math.abs(randomIntegers.next() % 26) + 32 * Math.abs(randomIntegers.next() % 2)
));
}
return name.toString();
}
private static CharacterProperties generateCharacter() {
CharacterProperties props = new CharacterProperties();
props.name = generateName(10);
props.HP = Math.abs(randomIntegers.next() % 15 + 5);
props.MP = Math.abs(randomIntegers.next() % 5 + 2);
props.AP = Math.abs(randomIntegers.next() % 5 + 2);
props.meleeDamage = Math.abs(randomIntegers.next() % 5 + 2);
props.rangedDamage = Math.abs(randomIntegers.next() % 5 + 2);
props.attackRange = Math.abs(randomIntegers.next() % 5 + 2);
return props;
} }