changed methods from static to instance methods

main
Berat Kocak 2025-01-10 18:27:54 +01:00
parent 47779b0b60
commit 22af3815ad
7 changed files with 72 additions and 68 deletions

View File

@ -23,7 +23,11 @@ import de.hs_mannheim.informatik.mvn.gui.HighscoreMenuGUI;
public class HighscoreManager { public class HighscoreManager {
public static void sortByTime(byte[] data, String filename) throws IOException { public static void main(String[] args) {
new HighscoreManager();
}
public void sortByTime(byte[] data, String filename) throws IOException {
ArrayList<HighscoreEintrag> highscores = new ArrayList<>(); ArrayList<HighscoreEintrag> highscores = new ArrayList<>();
try (BufferedReader reader = new BufferedReader( try (BufferedReader reader = new BufferedReader(
new InputStreamReader(new ByteArrayInputStream(data), StandardCharsets.UTF_8))) { new InputStreamReader(new ByteArrayInputStream(data), StandardCharsets.UTF_8))) {
@ -66,7 +70,7 @@ public class HighscoreManager {
overwriteContentOfFile(formattedHighscores, file); overwriteContentOfFile(formattedHighscores, file);
} }
private static void overwriteContentOfFile(ArrayList<String> formattedHighscores, File file) throws FileNotFoundException, IOException { private void overwriteContentOfFile(ArrayList<String> formattedHighscores, File file) throws FileNotFoundException, IOException {
try (BufferedWriter writer = new BufferedWriter( try (BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8))) { new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8))) {
for (String entry : formattedHighscores) { for (String entry : formattedHighscores) {
@ -76,7 +80,7 @@ public class HighscoreManager {
} }
} }
public static String getAvgTime(byte[] data, String filename) throws IOException { public String getAvgTime(byte[] data, String filename) throws IOException {
int totalSeconds = 0; int totalSeconds = 0;
int count = 0; int count = 0;
try (BufferedReader reader = new BufferedReader( try (BufferedReader reader = new BufferedReader(
@ -106,7 +110,7 @@ public class HighscoreManager {
} }
} }
public static void copyResourceIfNotExists(String resourcePathInJar, File outFile) throws IOException { public void copyResourceIfNotExists(String resourcePathInJar, File outFile) throws IOException {
if (outFile.exists()) { if (outFile.exists()) {
return; return;
} }

View File

@ -15,7 +15,7 @@ public class HitoriMain {
} }
public static 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))) {
String line; String line;
@ -28,7 +28,7 @@ public class HitoriMain {
return lines; return lines;
} }
public static String[][] getData(InputStream inputStream, int rows) throws FileNotFoundException{ public String[][] getData(InputStream inputStream, int rows) throws FileNotFoundException{
String[][] data = new String[rows][rows]; String[][] data = new String[rows][rows];
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) { try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
String line; String line;
@ -43,7 +43,7 @@ public class HitoriMain {
return data; return data;
} }
public static String[][] makeColorArray(int size){ public String[][] makeColorArray(int size){
String[][] colors = new String[size][size]; String[][] colors = new String[size][size];
for(int i=0;i<size;i++){ for(int i=0;i<size;i++){
for(int j=0;j<size;j++){ for(int j=0;j<size;j++){
@ -53,7 +53,7 @@ public class HitoriMain {
return colors; return colors;
} }
public static boolean checkArraySame(String[][] ergebnis,String[][] result){ public boolean checkArraySame(String[][] ergebnis,String[][] result){
int count = 0; int count = 0;
for(int i=0;i<result.length;i++){ for(int i=0;i<result.length;i++){
for(int j=0;j<result.length;j++){ for(int j=0;j<result.length;j++){
@ -73,7 +73,7 @@ public class HitoriMain {
} }
} }
public static boolean abgabeMöglich(InputStream inputStream, String[][] data, String[][] colors) throws FileNotFoundException{ public boolean abgabeMöglich(InputStream inputStream, String[][] data, String[][] colors) throws FileNotFoundException{
String[][] result = getResult(data, colors); String[][] result = getResult(data, colors);
ArrayList<String> filteredData = getSolution(inputStream); ArrayList<String> filteredData = getSolution(inputStream);
String[][] ergebnis = getErgebnisArray(result, filteredData); String[][] ergebnis = getErgebnisArray(result, filteredData);
@ -81,14 +81,14 @@ public class HitoriMain {
return abgabeMöglich; return abgabeMöglich;
} }
public static String[] getCords(int i, int j){ public String[] getCords(int i, int j){
String yKoordinate = String.valueOf(i); String yKoordinate = String.valueOf(i);
String xKoordinate = String.valueOf(j); String xKoordinate = String.valueOf(j);
String[] position = {yKoordinate, xKoordinate}; String[] position = {yKoordinate, xKoordinate};
return position; return position;
} }
public static String[][] getResult(String[][] data, String[][] colors){ public String[][] getResult(String[][] data, String[][] colors){
String[][] result = new String[data.length][data.length]; String[][] result = new String[data.length][data.length];
for(int i=0;i<data.length;i++){ for(int i=0;i<data.length;i++){
for(int j=0;j<data.length;j++){ for(int j=0;j<data.length;j++){
@ -103,7 +103,7 @@ public class HitoriMain {
return result; return result;
} }
public static ArrayList<String> getSolution(InputStream inputStream) throws FileNotFoundException{ public ArrayList<String> getSolution(InputStream inputStream) throws FileNotFoundException{
ArrayList<String> filteredData = new ArrayList<>(); ArrayList<String> filteredData = new ArrayList<>();
boolean isUnderComment = false; boolean isUnderComment = false;
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) { try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
@ -130,7 +130,7 @@ public class HitoriMain {
return filteredData; return filteredData;
} }
public static String[][] getErgebnisArray(String[][] result, ArrayList<String> filteredData){ public String[][] getErgebnisArray(String[][] result, ArrayList<String> filteredData){
String[][] ergebnis = new String[result.length][result.length]; String[][] ergebnis = new String[result.length][result.length];
for(int i=0;i<result.length;i++){ for(int i=0;i<result.length;i++){
for(int j=0;j<result.length;j++){ for(int j=0;j<result.length;j++){
@ -148,7 +148,7 @@ public class HitoriMain {
return ergebnis; return ergebnis;
} }
public static String[] getGameButtonNames() { public String[] getGameButtonNames() {
String[] buttonNames = { String[] buttonNames = {
"4x4 - leicht", "4x4 - leicht",
"5x5 - leicht", "5x5 - leicht",
@ -160,7 +160,7 @@ public class HitoriMain {
return buttonNames; return buttonNames;
} }
public static String[] getGamePath() { public String[] getGamePath() {
String[] buttonPaths = { String[] buttonPaths = {
"/Hitori_Spielfelder/Hitori4x4_leicht.csv", "/Hitori_Spielfelder/Hitori4x4_leicht.csv",
"/Hitori_Spielfelder/Hitori5x5leicht.csv", "/Hitori_Spielfelder/Hitori5x5leicht.csv",
@ -172,7 +172,7 @@ public class HitoriMain {
return buttonPaths; return buttonPaths;
} }
public static String[] getHighscorePathNames() { public String[] getHighscorePathNames() {
String[] buttonPaths = { String[] buttonPaths = {
"resources/Hitori_Highscores/Hitori4x4_leicht.txt", "resources/Hitori_Highscores/Hitori4x4_leicht.txt",
"resources/Hitori_Highscores/Hitori5x5leicht.txt", "resources/Hitori_Highscores/Hitori5x5leicht.txt",
@ -184,7 +184,7 @@ public class HitoriMain {
return buttonPaths; return buttonPaths;
} }
public static String[] getHighscoreButtonNames() { public String[] getHighscoreButtonNames() {
String[] buttonNames = { String[] buttonNames = {
"Highscore 4x4 - leicht", "Highscore 4x4 - leicht",
"Highscore 5x5 - leicht", "Highscore 5x5 - leicht",

View File

@ -16,7 +16,7 @@ public class GameGUI extends JFrame implements ActionListener {
private static long elapsedSeconds; private static long elapsedSeconds;
private static byte[] gameData; private static byte[] gameData;
public static void paintGame(InputStream inputStream, CardLayout cl, JPanel main, JButton[][] buttons, String[][] colors, Stack<String> madeMoves, String[][] data, String path0) throws IOException{ public void paintGame(InputStream inputStream, CardLayout cl, JPanel main, JButton[][] buttons, String[][] colors, Stack<String> madeMoves, String[][] data, String path0) throws IOException{
elapsedSeconds = 0; elapsedSeconds = 0;
gameData = inputStream.readAllBytes(); gameData = inputStream.readAllBytes();
String[] filepath = new String[2]; String[] filepath = new String[2];
@ -46,7 +46,7 @@ public class GameGUI extends JFrame implements ActionListener {
zurückButton.addActionListener(e -> {backOneStep(cl, main, madeMoves, buttons, colors, gameGrid);}); zurückButton.addActionListener(e -> {backOneStep(cl, main, madeMoves, buttons, colors, gameGrid);});
JButton resetButton = new JButton("Zurücksetzen"); JButton resetButton = new JButton("Zurücksetzen");
resetButton.addActionListener(e -> {try { resetButton.addActionListener(e -> {try {
HitoriAPI.totalResetButtonCatcher(inputStream, cl, main, buttons, colors, madeMoves, data, path0); new HitoriAPI().totalResetButtonCatcher(inputStream, cl, main, buttons, colors, madeMoves, data, path0);
} catch (FileNotFoundException e1) { } catch (FileNotFoundException e1) {
e1.printStackTrace(); e1.printStackTrace();
}}); }});
@ -58,7 +58,7 @@ public class GameGUI extends JFrame implements ActionListener {
topGrid.add(timeLabel); topGrid.add(timeLabel);
topGrid.revalidate(); topGrid.revalidate();
topGrid.repaint(); topGrid.repaint();
boolean isOkay = HitoriAPI.abgabeMöglichCatcher(inputStream, data, colors); boolean isOkay = new HitoriAPI().abgabeMöglichCatcher(inputStream, data, colors);
levelFinished[0] = isOkay; levelFinished[0] = isOkay;
Timer timer = new Timer(); Timer timer = new Timer();
startTimer(); startTimer();
@ -82,7 +82,7 @@ public class GameGUI extends JFrame implements ActionListener {
abgebenButton.addActionListener(e -> { abgebenButton.addActionListener(e -> {
try { try {
InputStream newStream = new ByteArrayInputStream(gameData); InputStream newStream = new ByteArrayInputStream(gameData);
levelFinished[0] = HitoriAPI.abgabeMöglichCatcher(newStream, data, colors); levelFinished[0] = new HitoriAPI().abgabeMöglichCatcher(newStream, data, colors);
} catch (FileNotFoundException e1) { } catch (FileNotFoundException e1) {
e1.printStackTrace(); e1.printStackTrace();
} }
@ -111,13 +111,13 @@ public class GameGUI extends JFrame implements ActionListener {
cl.show(main, "GAME"); cl.show(main, "GAME");
} }
private static void addMove(String[][] colors, int i, int j, String lastLetterString, Stack<String> madeMoves){ private void addMove(String[][] colors, int i, int j, String lastLetterString, Stack<String> madeMoves){
colors[i][j] += lastLetterString; colors[i][j] += lastLetterString;
String newMove = i+"."+j+"."+lastLetterString; String newMove = i+"."+j+"."+lastLetterString;
madeMoves.push(newMove); madeMoves.push(newMove);
} }
private static void changeButtonColor(JButton button, Color foreground, Color background) { private void changeButtonColor(JButton button, Color foreground, Color background) {
button.setOpaque(true); button.setOpaque(true);
button.setForeground(foreground); button.setForeground(foreground);
button.setContentAreaFilled(true); button.setContentAreaFilled(true);
@ -126,7 +126,7 @@ public class GameGUI extends JFrame implements ActionListener {
button.setBackground(background); button.setBackground(background);
} }
public static void paintButton(CardLayout cl, JPanel main, JButton button, String[] pos, String[][] colors, Stack<String> madeMoves, JPanel grid, JButton[][] buttons){ public void paintButton(CardLayout cl, JPanel main, JButton button, String[] pos, String[][] colors, Stack<String> madeMoves, JPanel grid, JButton[][] buttons){
int i = Integer.parseInt(pos[0]); int i = Integer.parseInt(pos[0]);
int j = Integer.parseInt(pos[1]); int j = Integer.parseInt(pos[1]);
String col = colors[i][j]; String col = colors[i][j];
@ -156,7 +156,7 @@ public class GameGUI extends JFrame implements ActionListener {
addMove(colors, i, j, lastLetterString, madeMoves); addMove(colors, i, j, lastLetterString, madeMoves);
} }
public static void backOneStep(CardLayout cl, JPanel main, Stack<String> movesMade, JButton[][] buttons, String[][] colors, JPanel grid){ public void backOneStep(CardLayout cl, JPanel main, Stack<String> movesMade, JButton[][] buttons, String[][] colors, JPanel grid){
String move = movesMade.pop(); String move = movesMade.pop();
String[] line = move.split("\\."); String[] line = move.split("\\.");
int i = Integer.parseInt(line[0]); int i = Integer.parseInt(line[0]);
@ -185,7 +185,7 @@ public class GameGUI extends JFrame implements ActionListener {
removeMove(colors, i, j, grid, buttons); removeMove(colors, i, j, grid, buttons);
} }
private static void removeMove(String[][] colors, int i, int j, JPanel grid, JButton[][] buttons) { private void removeMove(String[][] colors, int i, int j, JPanel grid, JButton[][] buttons) {
String colorString = colors[i][j]; String colorString = colors[i][j];
String colorStringWithoutLastElement = colorString.substring(0, colorString.length() - 1); String colorStringWithoutLastElement = colorString.substring(0, colorString.length() - 1);
colors[i][j] = colorStringWithoutLastElement; colors[i][j] = colorStringWithoutLastElement;
@ -193,7 +193,7 @@ public class GameGUI extends JFrame implements ActionListener {
gridUpdate(grid, buttons); gridUpdate(grid, buttons);
} }
public static void gridUpdate(JPanel grid, JButton[][] buttons){ public void gridUpdate(JPanel grid, JButton[][] buttons){
grid.removeAll(); grid.removeAll();
grid.repaint(); grid.repaint();
for(int i = 0; i<buttons.length; i++){ for(int i = 0; i<buttons.length; i++){
@ -205,13 +205,13 @@ public class GameGUI extends JFrame implements ActionListener {
} }
} }
public static String startTimer() { public String startTimer() {
startTime = System.currentTimeMillis(); startTime = System.currentTimeMillis();
elapsedSeconds = 0; elapsedSeconds = 0;
return "Zeit: 00:00"; return "Zeit: 00:00";
} }
public static String stopTimer() { public String stopTimer() {
timer.cancel(); timer.cancel();
long minutes = elapsedSeconds % 3600 / 60; long minutes = elapsedSeconds % 3600 / 60;
long seconds = elapsedSeconds % 60; long seconds = elapsedSeconds % 60;
@ -224,7 +224,7 @@ public class GameGUI extends JFrame implements ActionListener {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
} }
public static JButton[][] makeButtonArray(String[][] data){ public JButton[][] makeButtonArray(String[][] data){
JButton[][] buttons = new JButton[data.length][data.length]; JButton[][] buttons = new JButton[data.length][data.length];
for(int i=0;i<data.length;i++){ for(int i=0;i<data.length;i++){
for(int j=0;j<data.length;j++){ for(int j=0;j<data.length;j++){
@ -236,14 +236,14 @@ public class GameGUI extends JFrame implements ActionListener {
return buttons; return buttons;
} }
public static void totalResetButton(InputStream inputStream, CardLayout cl, JPanel main, JButton[][] buttonArray, String[][] colors,Stack<String> madeMoves,String[][] data,String path) throws FileNotFoundException{ public void totalResetButton(InputStream inputStream, CardLayout cl, JPanel main, JButton[][] buttonArray, String[][] colors,Stack<String> madeMoves,String[][] data,String path) throws FileNotFoundException{
madeMoves.clear(); madeMoves.clear();
for(int i = 0; i<data.length;i++){ for(int i = 0; i<data.length;i++){
for(int j = 0; j<data.length;j++){ for(int j = 0; j<data.length;j++){
colors[i][j] = "W"; colors[i][j] = "W";
buttonArray[i][j] = null; buttonArray[i][j] = null;
} }
HitoriAPI.repaintGameCatcher(data, inputStream, cl, main, colors, madeMoves, data, path); new HitoriAPI().repaintGameCatcher(data, inputStream, cl, main, colors, madeMoves, data, path);
} }
} }
} }

View File

@ -12,8 +12,8 @@ import javax.swing.JPanel;
import de.hs_mannheim.informatik.mvn.facade.HitoriAPI; import de.hs_mannheim.informatik.mvn.facade.HitoriAPI;
public class HighscoreMenuGUI extends JFrame implements ActionListener { public class HighscoreMenuGUI extends JFrame implements ActionListener {
final String[] pathNames = HitoriAPI.getHighscorePathNamesCatcher(); final String[] pathNames = new HitoriAPI().getHighscorePathNamesCatcher();
final String[] buttonNames = HitoriAPI.getHighscoreButtonNamesCatcher(); final String[] buttonNames = new HitoriAPI().getHighscoreButtonNamesCatcher();
public HighscoreMenuGUI(CardLayout cl, JPanel main) { public HighscoreMenuGUI(CardLayout cl, JPanel main) {
JPanel highscorePanel = new JPanel(new BorderLayout()); JPanel highscorePanel = new JPanel(new BorderLayout());
@ -23,7 +23,7 @@ public class HighscoreMenuGUI extends JFrame implements ActionListener {
buttonPanel.add(button); buttonPanel.add(button);
final int index = i; final int index = i;
button.addActionListener(e -> { button.addActionListener(e -> {
HitoriAPI.loadHighscore(index, pathNames, cl, main); new HitoriAPI().loadHighscore(index, pathNames, cl, main);
}); });
} }
JButton zurückButton = new JButton("Zurück"); JButton zurückButton = new JButton("Zurück");

View File

@ -18,8 +18,8 @@ import javax.swing.JPanel;
import de.hs_mannheim.informatik.mvn.facade.HitoriAPI; import de.hs_mannheim.informatik.mvn.facade.HitoriAPI;
public class HighscoreTableGUI { public class HighscoreTableGUI {
public static void showHighscores(CardLayout cl, JPanel main, byte[] data, String filename) throws IOException { public void showHighscores(CardLayout cl, JPanel main, byte[] data, String filename) throws IOException {
HitoriAPI.sortByTimeCatcher(data,filename); new HitoriAPI().sortByTimeCatcher(data,filename);
data = Files.readAllBytes(new File(filename).toPath()); data = Files.readAllBytes(new File(filename).toPath());
JPanel highscorePanel = new JPanel(new BorderLayout()); JPanel highscorePanel = new JPanel(new BorderLayout());
List<String> lines = new ArrayList<>(); List<String> lines = new ArrayList<>();
@ -48,7 +48,7 @@ public class HighscoreTableGUI {
} }
highscorePanel.add(entryPanel, BorderLayout.CENTER); highscorePanel.add(entryPanel, BorderLayout.CENTER);
String avgString = HitoriAPI.getAvgTimeCatcher(data,filename); String avgString = new HitoriAPI().getAvgTimeCatcher(data,filename);
JLabel avgTime = new JLabel(avgString); JLabel avgTime = new JLabel(avgString);
highscorePanel.add(avgTime, BorderLayout.NORTH); highscorePanel.add(avgTime, BorderLayout.NORTH);
} else { } else {

View File

@ -21,8 +21,8 @@ public class MenuGUI extends JFrame implements ActionListener {
public MenuGUI(){ public MenuGUI(){
JPanel menuPanel = new JPanel(new BorderLayout()); JPanel menuPanel = new JPanel(new BorderLayout());
JPanel buttonPanel = new JPanel(new GridLayout(7,1,10,10)); JPanel buttonPanel = new JPanel(new GridLayout(7,1,10,10));
final String[] buttonNames = HitoriAPI.getGameButtonNamesCatcher(); final String[] buttonNames = new HitoriAPI().getGameButtonNamesCatcher();
final String[] buttonPaths = HitoriAPI.getGamePathCatcher(); final String[] buttonPaths = new HitoriAPI().getGamePathCatcher();
for(int i=0;i<buttonNames.length;i++){ for(int i=0;i<buttonNames.length;i++){
JButton button = new JButton(buttonNames[i]); JButton button = new JButton(buttonNames[i]);
buttonPanel.add(button); buttonPanel.add(button);
@ -32,7 +32,7 @@ public class MenuGUI extends JFrame implements ActionListener {
int j = count[0]; int j = count[0];
filepath[0] = buttonPaths[j]; filepath[0] = buttonPaths[j];
filepath[1] = num[0]; filepath[1] = num[0];
HitoriAPI.loadGame(filepath, cl, main, gameData); new HitoriAPI().loadGame(filepath, cl, main, gameData);
}); });
} }
JButton highscoreButton = new JButton("Highscores"); JButton highscoreButton = new JButton("Highscores");

View File

@ -22,7 +22,7 @@ class HitoriTest{
{"W", "W", "W"}, {"W", "W", "W"},
{"W", "W", "W"} {"W", "W", "W"}
}; };
assertTrue(Arrays.deepEquals(array3x3, HitoriMain.makeColorArray(3))); assertTrue(Arrays.deepEquals(array3x3, new HitoriMain().makeColorArray(3)));
} }
@Test @Test
@ -31,12 +31,12 @@ class HitoriTest{
{"W", "W", "W"}, {"W", "W", "W"},
{"W", "W", "W"}, {"W", "W", "W"},
}; };
assertFalse(Arrays.deepEquals(array3x2, HitoriMain.makeColorArray(3))); assertFalse(Arrays.deepEquals(array3x2, new HitoriMain().makeColorArray(3)));
} }
@Test @Test
void checkStartTimeTest() { void checkStartTimeTest() {
assertEquals("Zeit: 00:00", GameGUI.startTimer()); assertEquals("Zeit: 00:00", new GameGUI().startTimer());
} }
@Test @Test
@ -51,7 +51,7 @@ class HitoriTest{
{"W", "W", "W", "B"}, {"W", "W", "W", "B"},
{"W", "B", "W", "W"}, {"W", "B", "W", "W"},
{"B", "W", "W", "B"}}; {"B", "W", "W", "B"}};
assertFalse(HitoriMain.checkArraySame(data, colors)); assertFalse(new HitoriMain().checkArraySame(data, colors));
} }
@Test @Test
@ -67,7 +67,7 @@ class HitoriTest{
{"W", "B", "W", "W"}, {"W", "B", "W", "W"},
{"B", "W", "W", "B"}}; {"B", "W", "W", "B"}};
assertTrue(HitoriMain.checkArraySame(data, colors)); assertTrue(new HitoriMain().checkArraySame(data, colors));
} }
@Test @Test
@ -84,7 +84,7 @@ class HitoriTest{
{"W", "B", "W", "W", "W"}, {"W", "B", "W", "W", "W"},
{"W", "B", "W", "W", "W"}, {"W", "B", "W", "W", "W"},
{"W", "B", "W", "W", "W"}}; {"W", "B", "W", "W", "W"}};
assertFalse(HitoriMain.checkArraySame(data, colors)); assertFalse(new HitoriMain().checkArraySame(data, colors));
} }
@Test @Test
@ -101,19 +101,19 @@ class HitoriTest{
{"B", "W", "W", "B", "W"}, {"B", "W", "W", "B", "W"},
{"W", "W", "B", "W", "W"}, {"W", "W", "B", "W", "W"},
{"B", "W", "W", "W", "B"}}; {"B", "W", "W", "W", "B"}};
assertTrue(HitoriMain.checkArraySame(data, colors)); assertTrue(new HitoriMain().checkArraySame(data, colors));
} }
@Test @Test
void getCordsTest1() { void getCordsTest1() {
String[] array = {"3", "4"}; String[] array = {"3", "4"};
assertFalse(Arrays.deepEquals(array, HitoriMain.getCords(3, 3))); assertFalse(Arrays.deepEquals(array, new HitoriMain().getCords(3, 3)));
} }
@Test @Test
void getCordsTest2() { void getCordsTest2() {
String[] array = {"3", "4"}; String[] array = {"3", "4"};
assertTrue(Arrays.deepEquals(array, HitoriMain.getCords(3, 4))); assertTrue(Arrays.deepEquals(array, new HitoriMain().getCords(3, 4)));
} }
@Test @Test
@ -140,7 +140,7 @@ class HitoriTest{
{"B", "W", "B", "W", "W", "B", "W", "W", "W", "W"}, {"B", "W", "B", "W", "W", "B", "W", "W", "W", "W"},
{"W", "W", "W", "B", "W", "W", "B", "W", "B", "W"}, {"W", "W", "W", "B", "W", "W", "B", "W", "B", "W"},
{"B", "W", "B", "W", "W", "W", "W", "W", "W", "B"}}; {"B", "W", "B", "W", "W", "W", "W", "W", "W", "B"}};
assertTrue(HitoriMain.checkArraySame(data, colors)); assertTrue(new HitoriMain().checkArraySame(data, colors));
} }
@Test @Test
@ -167,7 +167,7 @@ class HitoriTest{
{"B", "W", "B", "W", "W", "B", "W", "W", "W", "W"}, {"B", "W", "B", "W", "W", "B", "W", "W", "W", "W"},
{"W", "W", "W", "B", "W", "W", "B", "W", "B", "W"}, {"W", "W", "W", "B", "W", "W", "B", "W", "B", "W"},
{"B", "W", "B", "W", "W", "W", "W", "W", "W", "W"}}; {"B", "W", "B", "W", "W", "W", "W", "W", "W", "W"}};
assertFalse(HitoriMain.checkArraySame(data, colors)); assertFalse(new HitoriMain().checkArraySame(data, colors));
} }
@Test @Test
@ -187,7 +187,7 @@ class HitoriTest{
{"W", "B", "W", "W"}, {"W", "B", "W", "W"},
{"B", "W", "W", "B"}, {"B", "W", "W", "B"},
{"W", "W", "B", "W"}}; {"W", "W", "B", "W"}};
assertTrue(Arrays.deepEquals(array, HitoriMain.getResult(data, colors))); assertTrue(Arrays.deepEquals(array, new HitoriMain().getResult(data, colors)));
} }
@Test @Test
@ -207,7 +207,7 @@ class HitoriTest{
{"G", "B", "W", "W"}, {"G", "B", "W", "W"},
{"B", "W", "W", "B"}, {"B", "W", "W", "B"},
{"W", "W", "B", "W"}}; {"W", "W", "B", "W"}};
assertFalse(Arrays.deepEquals(array, HitoriMain.getResult(data, colors))); assertFalse(Arrays.deepEquals(array, new HitoriMain().getResult(data, colors)));
} }
@Test @Test
@ -215,7 +215,7 @@ class HitoriTest{
String[] ergebnis4x4 = {"0,1", "1,3", "2,1", "3,0", "3,3"}; String[] ergebnis4x4 = {"0,1", "1,3", "2,1", "3,0", "3,3"};
String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv"; String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv";
InputStream inputStream = getClass().getResourceAsStream(path); InputStream inputStream = getClass().getResourceAsStream(path);
ArrayList<String> filteredData = HitoriMain.getSolution(inputStream); ArrayList<String> filteredData = new HitoriMain().getSolution(inputStream);
assertEquals(5, filteredData.size()); assertEquals(5, filteredData.size());
assertEquals(ergebnis4x4[0], filteredData.get(0)); assertEquals(ergebnis4x4[0], filteredData.get(0));
assertEquals(ergebnis4x4[1], filteredData.get(1)); assertEquals(ergebnis4x4[1], filteredData.get(1));
@ -229,7 +229,7 @@ class HitoriTest{
String[] ergebnis4x4 = {"0,0"}; String[] ergebnis4x4 = {"0,0"};
String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv"; String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv";
InputStream inputStream = getClass().getResourceAsStream(path); InputStream inputStream = getClass().getResourceAsStream(path);
ArrayList<String> filteredData = HitoriMain.getSolution(inputStream); ArrayList<String> filteredData = new HitoriMain().getSolution(inputStream);
assertNotEquals(1, filteredData.size()); assertNotEquals(1, filteredData.size());
assertNotEquals(ergebnis4x4[0], filteredData.get(0)); assertNotEquals(ergebnis4x4[0], filteredData.get(0));
assertNotEquals(ergebnis4x4[0], filteredData.get(1)); assertNotEquals(ergebnis4x4[0], filteredData.get(1));
@ -245,7 +245,7 @@ class HitoriTest{
{"W", "W", "W", "W"}, {"W", "W", "W", "W"},
{"W", "W", "W", "W"}, {"W", "W", "W", "W"},
{"W", "W", "W", "W"}}; {"W", "W", "W", "W"}};
assertTrue(Arrays.deepEquals(colors, HitoriMain.makeColorArray(4))); assertTrue(Arrays.deepEquals(colors, new HitoriMain().makeColorArray(4)));
} }
@Test @Test
@ -255,7 +255,7 @@ class HitoriTest{
{"B", "W", "W", "W"}, {"B", "W", "W", "W"},
{"B", "W", "W", "W"}, {"B", "W", "W", "W"},
{"B", "W", "W", "W"}}; {"B", "W", "W", "W"}};
assertFalse(Arrays.deepEquals(colors, HitoriMain.makeColorArray(4))); assertFalse(Arrays.deepEquals(colors, new HitoriMain().makeColorArray(4)));
} }
@Test @Test
@ -267,7 +267,7 @@ class HitoriTest{
{"3", "4", "3", "2"}}; {"3", "4", "3", "2"}};
String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv"; String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv";
InputStream inputStream = getClass().getResourceAsStream(path); InputStream inputStream = getClass().getResourceAsStream(path);
assertTrue(Arrays.deepEquals(data, HitoriMain.getData(inputStream, 4))); assertTrue(Arrays.deepEquals(data, new HitoriMain().getData(inputStream, 4)));
} }
@Test @Test
@ -279,7 +279,7 @@ class HitoriTest{
{"3", "0", "3", "2"}}; {"3", "0", "3", "2"}};
String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv"; String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv";
InputStream inputStream = getClass().getResourceAsStream(path); InputStream inputStream = getClass().getResourceAsStream(path);
assertFalse(Arrays.deepEquals(data, HitoriMain.getData(inputStream, 4))); assertFalse(Arrays.deepEquals(data, new HitoriMain().getData(inputStream, 4)));
} }
@Test @Test
@ -302,7 +302,7 @@ class HitoriTest{
} }
String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv"; String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv";
InputStream inputStream = getClass().getResourceAsStream(path); InputStream inputStream = getClass().getResourceAsStream(path);
ArrayList<String> ergebnisList = HitoriMain.readFromFile(inputStream); ArrayList<String> ergebnisList = new HitoriMain().readFromFile(inputStream);
assertEquals(fileEntry, ergebnisList); assertEquals(fileEntry, ergebnisList);
} }
@ -326,7 +326,7 @@ class HitoriTest{
} }
String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv"; String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv";
InputStream inputStream = getClass().getResourceAsStream(path); InputStream inputStream = getClass().getResourceAsStream(path);
ArrayList<String> ergebnisList = HitoriMain.readFromFile(inputStream); ArrayList<String> ergebnisList = new HitoriMain().readFromFile(inputStream);
assertNotEquals(fileEntry, ergebnisList); assertNotEquals(fileEntry, ergebnisList);
} }
@ -339,11 +339,11 @@ class HitoriTest{
{"B", "W", "W", "B"}}; {"B", "W", "W", "B"}};
String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv"; String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv";
InputStream inputStream = getClass().getResourceAsStream(path); InputStream inputStream = getClass().getResourceAsStream(path);
ArrayList<String> filteredData = HitoriMain.getSolution(inputStream); ArrayList<String> filteredData = new HitoriMain().getSolution(inputStream);
InputStream newStream = getClass().getResourceAsStream(path); InputStream newStream = getClass().getResourceAsStream(path);
int rows = 4; int rows = 4;
String[][] data = HitoriMain.getData(newStream, rows); String[][] data = new HitoriMain().getData(newStream, rows);
assertTrue(Arrays.deepEquals(ergebnis1, HitoriMain.getErgebnisArray(data, filteredData))); assertTrue(Arrays.deepEquals(ergebnis1, new HitoriMain().getErgebnisArray(data, filteredData)));
} }
@Test @Test
@ -355,11 +355,11 @@ class HitoriTest{
{"W", "W", "W", "W"}}; {"W", "W", "W", "W"}};
String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv"; String path = "/Hitori_Spielfelder/Hitori4x4_leicht.csv";
InputStream inputStream = getClass().getResourceAsStream(path); InputStream inputStream = getClass().getResourceAsStream(path);
ArrayList<String> filteredData = HitoriMain.getSolution(inputStream); ArrayList<String> filteredData = new HitoriMain().getSolution(inputStream);
InputStream newStream = getClass().getResourceAsStream(path); InputStream newStream = getClass().getResourceAsStream(path);
int rows = 4; int rows = 4;
String[][] data = HitoriMain.getData(newStream, rows); String[][] data = new HitoriMain().getData(newStream, rows);
assertFalse(Arrays.deepEquals(ergebnis1, HitoriMain.getErgebnisArray(data, filteredData))); assertFalse(Arrays.deepEquals(ergebnis1, new HitoriMain().getErgebnisArray(data, filteredData)));
} }
@Test @Test