added new tests
parent
f4de80f801
commit
9625a02631
|
@ -29,7 +29,6 @@ public class HitoriMain2 extends JFrame implements ActionListener{
|
|||
private static byte[] gameData;
|
||||
|
||||
public static void main(String[] args) throws FileNotFoundException{
|
||||
System.out.println("HERE");
|
||||
new MenuGUI();
|
||||
}
|
||||
|
||||
|
@ -116,7 +115,7 @@ public class HitoriMain2 extends JFrame implements ActionListener{
|
|||
|
||||
public static boolean abgabeMöglich(InputStream inputStream, String[][] data, String[][] colors) throws FileNotFoundException{
|
||||
String[][] result = getResult(data, colors);
|
||||
ArrayList<String> filteredData = getSolution(inputStream, result);
|
||||
ArrayList<String> filteredData = getSolution(inputStream);
|
||||
String[][] ergebnis = getErgebnisArray(result, filteredData);
|
||||
boolean abgabeMöglich = checkArraySame(result, ergebnis);
|
||||
return abgabeMöglich;
|
||||
|
@ -160,7 +159,7 @@ public class HitoriMain2 extends JFrame implements ActionListener{
|
|||
return result;
|
||||
}
|
||||
|
||||
public static ArrayList<String> getSolution(InputStream inputStream, String[][] result) throws FileNotFoundException{
|
||||
public static ArrayList<String> getSolution(InputStream inputStream) throws FileNotFoundException{
|
||||
ArrayList<String> filteredData = new ArrayList<>();
|
||||
boolean isUnderComment = false;
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
|
||||
|
@ -240,7 +239,7 @@ public class HitoriMain2 extends JFrame implements ActionListener{
|
|||
ArrayList<String> formattedHighscores = new ArrayList<>();
|
||||
for (HighscoreEintrag e : highscores) {
|
||||
String formattedTime = String.format("%02d:%02d", e.getTime().getHour(), e.getTime().getMinute());
|
||||
String line = formattedTime + " " + e.getName(); // Keep the name
|
||||
String line = formattedTime + " " + e.getName();
|
||||
formattedHighscores.add(line);
|
||||
}
|
||||
String fileName = filename.substring(filename.lastIndexOf('/') + 1);
|
||||
|
|
|
@ -7,12 +7,9 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import de.hs_mannheim.informatik.mvn.domain.HitoriMain2;
|
||||
import de.hs_mannheim.informatik.mvn.gui.GameGUI;
|
||||
|
||||
|
@ -172,4 +169,164 @@ class HitoriTest{
|
|||
{"B", "W", "B", "W", "W", "W", "W", "W", "W", "W"}};
|
||||
assertFalse(HitoriMain2.checkArraySame(data, colors));
|
||||
}
|
||||
|
||||
@Test
|
||||
void test12() {
|
||||
String[][] data = {
|
||||
{"W", "G", "B", "W"},
|
||||
{"G", "B", "W", "G"},
|
||||
{"B", "W", "G", "B"},
|
||||
{"W", "G", "B", "W"}};
|
||||
String[][] colors = {
|
||||
{"W", "G", "B", "W"},
|
||||
{"G", "B", "W", "G"},
|
||||
{"B", "W", "G", "B"},
|
||||
{"W", "G", "B", "W"}};
|
||||
String[][] array = {
|
||||
{"W", "W", "B", "W"},
|
||||
{"W", "B", "W", "W"},
|
||||
{"B", "W", "W", "B"},
|
||||
{"W", "W", "B", "W"}};
|
||||
assertTrue(Arrays.deepEquals(array, HitoriMain2.getResult(data, colors)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void test13() {
|
||||
String[][] data = {
|
||||
{"W", "G", "B", "W"},
|
||||
{"G", "B", "W", "G"},
|
||||
{"B", "W", "G", "B"},
|
||||
{"W", "G", "B", "W"}};
|
||||
String[][] colors = {
|
||||
{"W", "G", "B", "W"},
|
||||
{"G", "B", "W", "G"},
|
||||
{"B", "W", "G", "B"},
|
||||
{"W", "G", "B", "W"}};
|
||||
String[][] array = {
|
||||
{"W", "W", "B", "W"},
|
||||
{"G", "B", "W", "W"},
|
||||
{"B", "W", "W", "B"},
|
||||
{"W", "W", "B", "W"}};
|
||||
assertFalse(Arrays.deepEquals(array, HitoriMain2.getResult(data, colors)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void test14() throws FileNotFoundException {
|
||||
String[] ergebnis4x4 = {"0,1", "1,3", "2,1", "3,0", "3,3"};
|
||||
String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv";
|
||||
InputStream inputStream = getClass().getResourceAsStream(path);
|
||||
ArrayList<String> filteredData = HitoriMain2.getSolution(inputStream);
|
||||
assertEquals(5, filteredData.size());
|
||||
assertEquals(ergebnis4x4[0], filteredData.get(0));
|
||||
assertEquals(ergebnis4x4[1], filteredData.get(1));
|
||||
assertEquals(ergebnis4x4[2], filteredData.get(2));
|
||||
assertEquals(ergebnis4x4[3], filteredData.get(3));
|
||||
assertEquals(ergebnis4x4[4], filteredData.get(4));
|
||||
}
|
||||
|
||||
@Test
|
||||
void test15() throws FileNotFoundException {
|
||||
String[] ergebnis4x4 = {"0,0"};
|
||||
String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv";
|
||||
InputStream inputStream = getClass().getResourceAsStream(path);
|
||||
ArrayList<String> filteredData = HitoriMain2.getSolution(inputStream);
|
||||
assertNotEquals(1, filteredData.size());
|
||||
assertNotEquals(ergebnis4x4[0], filteredData.get(0));
|
||||
assertNotEquals(ergebnis4x4[0], filteredData.get(1));
|
||||
assertNotEquals(ergebnis4x4[0], filteredData.get(2));
|
||||
assertNotEquals(ergebnis4x4[0], filteredData.get(3));
|
||||
assertNotEquals(ergebnis4x4[0], filteredData.get(4));
|
||||
}
|
||||
|
||||
@Test
|
||||
void test16() {
|
||||
String[][] colors = {
|
||||
{"W", "W", "W", "W"},
|
||||
{"W", "W", "W", "W"},
|
||||
{"W", "W", "W", "W"},
|
||||
{"W", "W", "W", "W"}};
|
||||
assertTrue(Arrays.deepEquals(colors, HitoriMain2.makeColorArray(4)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void test17() {
|
||||
String[][] colors = {
|
||||
{"B", "W", "W", "W"},
|
||||
{"B", "W", "W", "W"},
|
||||
{"B", "W", "W", "W"},
|
||||
{"B", "W", "W", "W"}};
|
||||
assertFalse(Arrays.deepEquals(colors, HitoriMain2.makeColorArray(4)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void test18() throws FileNotFoundException {
|
||||
String[][] data = {
|
||||
{"3", "3", "1", "4"},
|
||||
{"4", "3", "2", "2"},
|
||||
{"1", "3", "4", "2"},
|
||||
{"3", "4", "3", "2"}};
|
||||
String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv";
|
||||
InputStream inputStream = getClass().getResourceAsStream(path);
|
||||
assertTrue(Arrays.deepEquals(data, HitoriMain2.getData(inputStream, 4)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void test19() throws FileNotFoundException {
|
||||
String[][] data = {
|
||||
{"3", "0", "1", "4"},
|
||||
{"4", "0", "2", "2"},
|
||||
{"1", "0", "4", "2"},
|
||||
{"3", "0", "3", "2"}};
|
||||
String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv";
|
||||
InputStream inputStream = getClass().getResourceAsStream(path);
|
||||
assertFalse(Arrays.deepEquals(data, HitoriMain2.getData(inputStream, 4)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void test20() {
|
||||
String[] file = {
|
||||
"3,3,1,4",
|
||||
"4,3,2,2",
|
||||
"1,3,4,2",
|
||||
"3,4,3,2",
|
||||
"",
|
||||
"//Lösung (schwarze Felder)",
|
||||
"1,2",
|
||||
"2,4",
|
||||
"3,2",
|
||||
"4,1",
|
||||
"4,4"};
|
||||
ArrayList<String> fileEntry = new ArrayList<String>();
|
||||
for(int i=0;i<file.length;i++) {
|
||||
fileEntry.add(file[i]);
|
||||
}
|
||||
String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv";
|
||||
InputStream inputStream = getClass().getResourceAsStream(path);
|
||||
ArrayList<String> ergebnisList = HitoriMain2.readFromFile(inputStream);
|
||||
assertEquals(fileEntry, ergebnisList);
|
||||
}
|
||||
|
||||
@Test
|
||||
void test21() {
|
||||
String[] file = {
|
||||
"3,3,1,0",
|
||||
"4,3,2,0",
|
||||
"1,3,4,0",
|
||||
"3,4,3,0",
|
||||
"",
|
||||
"//Lösung (schwarze Felder)",
|
||||
"1,2",
|
||||
"2,4",
|
||||
"3,2",
|
||||
"4,1",
|
||||
"4,4"};
|
||||
ArrayList<String> fileEntry = new ArrayList<String>();
|
||||
for(int i=0;i<file.length;i++) {
|
||||
fileEntry.add(file[i]);
|
||||
}
|
||||
String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv";
|
||||
InputStream inputStream = getClass().getResourceAsStream(path);
|
||||
ArrayList<String> ergebnisList = HitoriMain2.readFromFile(inputStream);
|
||||
assertNotEquals(fileEntry, ergebnisList);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue