Browse Source

refactoring: changed countFileLines and readFile methods

master
Ozan-Can Ekinci 2 years ago
parent
commit
d810a10473
  1. 8
      src/main/java/game/runGame.java
  2. 3
      src/test/java/game/runGameTest.java

8
src/main/java/game/runGame.java

@ -10,8 +10,8 @@ public class runGame {
public static String QuestionsPath = "QandA/Questions.txt"; public static String QuestionsPath = "QandA/Questions.txt";
public static String AnswersPath = "QandA/Answers.txt"; public static String AnswersPath = "QandA/Answers.txt";
public static int lines = CountFileLines(QuestionsPath); public static int lines = CountFileLines(QuestionsPath);
public static String[] arrQuestions = readFile(QuestionsPath);
public static String[] arrAnswers = readFile(AnswersPath);
public static String[] arrQuestions = readFile(QuestionsPath, lines);
public static String[] arrAnswers = readFile(AnswersPath, lines);
public static String[] splitAns; public static String[] splitAns;
public void run(int i) { public void run(int i) {
@ -40,9 +40,9 @@ public class runGame {
} }
public static String[] readFile(String Path) {
public static String[] readFile(String Path, int Lines) {
BufferedReader reader; BufferedReader reader;
String[] Arr = new String[lines];
String[] Arr = new String[Lines];
try { try {
reader = new BufferedReader(new FileReader(Path)); reader = new BufferedReader(new FileReader(Path));
String line = reader.readLine(); String line = reader.readLine();

3
src/test/java/game/runGameTest.java

@ -47,7 +47,8 @@ class runGameTest {
writer.write("Zeile 2\n"); writer.write("Zeile 2\n");
writer.write("Zeile 3\n"); writer.write("Zeile 3\n");
writer.close(); writer.close();
String[] lines = runGame.readFile(file.getAbsolutePath());
int numLine = runGame.CountFileLines(file.getAbsolutePath());
String[] lines = runGame.readFile(file.getAbsolutePath(), numLine);
assertEquals("Zeile 1", lines[0]); assertEquals("Zeile 1", lines[0]);
assertEquals("Zeile 2", lines[1]); assertEquals("Zeile 2", lines[1]);
assertEquals("Zeile 3", lines[2]); assertEquals("Zeile 3", lines[2]);

Loading…
Cancel
Save