added 4 new tests, 2 for abgabeMöglich method of HitoriMain class and 2
for avgTime method of HighscoreManager class, also added a txt file for the testmain
parent
22af3815ad
commit
df2947faef
|
@ -14,7 +14,6 @@ public class HitoriMain {
|
||||||
HitoriAPI.starter();
|
HitoriAPI.starter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public ArrayList<String> readFromFile(InputStream inputStream){
|
public ArrayList<String> readFromFile(InputStream inputStream){
|
||||||
ArrayList<String> lines = new ArrayList<>();
|
ArrayList<String> lines = new ArrayList<>();
|
||||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
00:15 Berat
|
||||||
|
11:00 Emre
|
||||||
|
08:11 Mark
|
||||||
|
07:11 Thomas
|
|
@ -2,14 +2,23 @@ package de.hs_mannheim.informatik.mvn.test;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.time.LocalTime;
|
import java.time.LocalTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.time.format.DateTimeFormatterBuilder;
|
||||||
|
import java.time.temporal.ChronoField;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import de.hs_mannheim.informatik.mvn.domain.HighscoreEintrag;
|
import de.hs_mannheim.informatik.mvn.domain.HighscoreEintrag;
|
||||||
|
import de.hs_mannheim.informatik.mvn.domain.HighscoreManager;
|
||||||
import de.hs_mannheim.informatik.mvn.domain.HitoriMain;
|
import de.hs_mannheim.informatik.mvn.domain.HitoriMain;
|
||||||
import de.hs_mannheim.informatik.mvn.gui.GameGUI;
|
import de.hs_mannheim.informatik.mvn.gui.GameGUI;
|
||||||
|
|
||||||
|
@ -374,15 +383,67 @@ class HitoriTest{
|
||||||
assertFalse(he.getName().equals("Emre"));
|
assertFalse(he.getName().equals("Emre"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test void test17() {
|
@Test
|
||||||
|
void getAvgTimeTest1() throws IOException {
|
||||||
|
String filename = "timeFileForTest.txt";
|
||||||
|
String path = "/Hitori_Highscores/timeFileForTest.txt";
|
||||||
|
InputStream inputStream = getClass().getResourceAsStream(path);
|
||||||
|
byte[] data = inputStream.readAllBytes();
|
||||||
|
String actual = new HighscoreManager().getAvgTime(data, filename);
|
||||||
|
String expected = "Durchschnittszeit: 6:39";
|
||||||
|
assertEquals(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getAvgTimeTest2() throws IOException {
|
||||||
|
String filename = "timeFileForTest.txt";
|
||||||
|
String path = "/Hitori_Highscores/timeFileForTest.txt";
|
||||||
|
InputStream inputStream = getClass().getResourceAsStream(path);
|
||||||
|
byte[] data = inputStream.readAllBytes();
|
||||||
|
String actual = new HighscoreManager().getAvgTime(data, filename);
|
||||||
|
String expected = "Durchschnittszeit: 00:10";
|
||||||
|
assertNotEquals(expected, actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void abgabeMöglichTest1() throws FileNotFoundException{
|
||||||
|
String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv";
|
||||||
|
InputStream inputStream = getClass().getResourceAsStream(path);
|
||||||
|
String[][] data = {
|
||||||
|
{"W", "B", "W", "W"},
|
||||||
|
{"W", "W", "W", "B"},
|
||||||
|
{"W", "B", "W", "W"},
|
||||||
|
{"B", "W", "W", "B"}
|
||||||
|
};
|
||||||
|
String[][] colors = {
|
||||||
|
{"W", "WGBBB", "W", "W"},
|
||||||
|
{"W", "W", "W", "WGB"},
|
||||||
|
{"W", "WGB", "W", "W"},
|
||||||
|
{"WBGGGGB", "W", "W", "WGB"}
|
||||||
|
};
|
||||||
|
boolean expected = true;
|
||||||
|
assertEquals(expected, new HitoriMain().abgabeMöglich(inputStream, data, colors));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void abgabeMöglichTest2() throws FileNotFoundException{
|
||||||
|
String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv";
|
||||||
|
InputStream inputStream = getClass().getResourceAsStream(path);
|
||||||
|
String[][] data = {
|
||||||
|
{"W", "W", "W", "W"},
|
||||||
|
{"W", "W", "W", "W"},
|
||||||
|
{"W", "W", "W", "W"},
|
||||||
|
{"W", "W", "W", "W"}
|
||||||
|
};
|
||||||
|
String[][] colors = {
|
||||||
|
{"W", "B", "W", "W"},
|
||||||
|
{"W", "W", "W", "B"},
|
||||||
|
{"W", "B", "W", "W"},
|
||||||
|
{"B", "W", "W", "B"}
|
||||||
|
};
|
||||||
|
boolean expected = false;
|
||||||
|
assertNotEquals(expected, new HitoriMain().abgabeMöglich(inputStream, data, colors));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue