Commit 694f87a3 authored by uglke's avatar uglke

Merge branch 'development' into 'development'

Use StringBuilder in Terminal instead of always overwriting old String

See merge request WS-17-18/assignment-tests!53
parents 3e2f1062 55dd075d
...@@ -40,7 +40,7 @@ public final class Terminal { ...@@ -40,7 +40,7 @@ public final class Terminal {
/** /**
* This field represents the output from a tested program to a test * This field represents the output from a tested program to a test
*/ */
public static final LinkedList<String> OUT_TEST = new LinkedList<>(); public static final LinkedList<StringBuilder> OUT_TEST = new LinkedList<>();
/** /**
* Reads text from the "standard" input stream, buffering characters so as to provide for the efficient reading * Reads text from the "standard" input stream, buffering characters so as to provide for the efficient reading
...@@ -73,12 +73,13 @@ public final class Terminal { ...@@ -73,12 +73,13 @@ public final class Terminal {
String out = "Error, " + message; String out = "Error, " + message;
if (isTest) { if (isTest) {
String current = OUT_TEST.pollLast(); if (OUT_TEST.getLast() == null) {
if (current == null || current.isEmpty()) { OUT_TEST.pollLast();
OUT_TEST.add(out); OUT_TEST.add(new StringBuilder());
} else { } else {
OUT_TEST.add(current + "\n" + out); OUT_TEST.getLast().append("\n");
} }
OUT_TEST.getLast().append(out);
} else if (isTestCreation) { } else if (isTestCreation) {
System.err.println(out); System.err.println(out);
if (useMyErrorMessagesInTestCreation) { if (useMyErrorMessagesInTestCreation) {
...@@ -103,8 +104,13 @@ public final class Terminal { ...@@ -103,8 +104,13 @@ public final class Terminal {
*/ */
public static void printLine(final Object object) { public static void printLine(final Object object) {
if (isTest) { if (isTest) {
String current = OUT_TEST.pollLast(); if (OUT_TEST.getLast() == null) {
OUT_TEST.add((current == null ? "" : current + "\n") + object); OUT_TEST.pollLast();
OUT_TEST.add(new StringBuilder());
} else {
OUT_TEST.getLast().append("\n");
}
OUT_TEST.getLast().append(object);
} else if (isTestCreation) { } else if (isTestCreation) {
System.out.println(object); System.out.println(object);
testPairFile.append(String.valueOf(object)).append("\n"); testPairFile.append(String.valueOf(object)).append("\n");
...@@ -167,11 +173,12 @@ public final class Terminal { ...@@ -167,11 +173,12 @@ public final class Terminal {
} }
} }
} }
//If the program outputted nothing we still have null which means "no output" //If the program outputted nothing we still have null which means "no output"
OUT_TEST.add(null); OUT_TEST.add(null);
assert !IN_TEST.isEmpty() assert !IN_TEST.isEmpty()
: "Either the executed test doesn't has quit as last input\n" : "Either the executed test doesn't have quit as last input\n"
+ "or your quitting mechanism doesn't work properly.\n" + "or your quitting mechanism doesn't work properly.\n"
+ "Expect the second option or check the test!"; + "Expect the second option or check the test!";
return IN_TEST.poll(); return IN_TEST.poll();
......
...@@ -58,14 +58,15 @@ public class Assignment1TestBase extends TestBase { ...@@ -58,14 +58,15 @@ public class Assignment1TestBase extends TestBase {
} }
} }
log.info("args[]: '" + strb.toString() + "'"); log.info("args[]: '" + strb.toString() + "'");
Terminal.OUT_TEST.add(null);
DummyMain.main(args); DummyMain.main(args);
String output = Terminal.OUT_TEST.poll(); StringBuilder output = Terminal.OUT_TEST.pollFirst();
if (acceptable) { if (acceptable) {
if (output != null && !output.equals(">>")) { if (output != null) {
failAndLog("test should have succeeded"); failAndLog("test should have succeeded");
} }
} else { } else {
if (output == null || !output.startsWith("Error")) { if (output == null || !output.toString().startsWith("Error")) {
failAndLog("test should have failed"); failAndLog("test should have failed");
} }
} }
......
...@@ -61,7 +61,7 @@ public class CaseCreator { ...@@ -61,7 +61,7 @@ public class CaseCreator {
for (TestPair testPair : testPairs) { for (TestPair testPair : testPairs) {
testPairfile.append("> " + testPair.getInput() + "\n"); testPairfile.append("> " + testPair.getInput() + "\n");
String partOutput; StringBuilder partOutput;
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
do { do {
partOutput = Terminal.OUT_TEST.pollFirst(); partOutput = Terminal.OUT_TEST.pollFirst();
......
...@@ -174,7 +174,7 @@ public class CaseCreator { ...@@ -174,7 +174,7 @@ public class CaseCreator {
testPairFile.append(testPair.getInput()); testPairFile.append(testPair.getInput());
testPairFile.append("\n"); testPairFile.append("\n");
String partOutput; StringBuilder partOutput;
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
do { do {
partOutput = Terminal.OUT_TEST.pollFirst(); partOutput = Terminal.OUT_TEST.pollFirst();
......
...@@ -25,7 +25,6 @@ public class PerformanceTest extends Assignment2TestBase { ...@@ -25,7 +25,6 @@ public class PerformanceTest extends Assignment2TestBase {
* amount of memory. * amount of memory.
*/ */
@Disabled
@Test @Test
@DisplayName("PerformanceTest2") @DisplayName("PerformanceTest2")
void performanceTest2() { void performanceTest2() {
...@@ -36,7 +35,6 @@ public class PerformanceTest extends Assignment2TestBase { ...@@ -36,7 +35,6 @@ public class PerformanceTest extends Assignment2TestBase {
testUsingPairs(pairs, () -> DummyMain.main(null)); testUsingPairs(pairs, () -> DummyMain.main(null));
} }
@Disabled
@Test @Test
@DisplayName("PerformanceTest3") @DisplayName("PerformanceTest3")
void performanceTest3() { void performanceTest3() {
......
...@@ -106,9 +106,8 @@ public abstract class TestBase { ...@@ -106,9 +106,8 @@ public abstract class TestBase {
if (showAllProgramOutput && !testPassed && !Terminal.OUT_TEST.isEmpty()) { if (showAllProgramOutput && !testPassed && !Terminal.OUT_TEST.isEmpty()) {
System.out.println("The output after that was:"); System.out.println("The output after that was:");
while (!Terminal.OUT_TEST.isEmpty()) { while (!Terminal.OUT_TEST.isEmpty())
System.out.println(popProgramOutput()); System.out.println(Terminal.OUT_TEST.pollFirst().toString());
}
} }
clearData(); clearData();
...@@ -160,17 +159,14 @@ public abstract class TestBase { ...@@ -160,17 +159,14 @@ public abstract class TestBase {
* @return a string containing the output * @return a string containing the output
*/ */
protected String popProgramOutput() { protected String popProgramOutput() {
return Terminal.OUT_TEST.pollFirst(); //Shouldn't ever happen, but if it does, we effectively have no output
} if (Terminal.OUT_TEST.isEmpty())
return null;
/** StringBuilder res = Terminal.OUT_TEST.pollFirst();
* Gets the next output from the output-queue and removes it if (res == null)
* This does the same as {@code popProgramOutput} return null;
* else
* @return a string containing the output return res.toString();
*/
protected String getNextProgramOutput() {
return popProgramOutput();
} }
/** /**
...@@ -207,14 +203,11 @@ public abstract class TestBase { ...@@ -207,14 +203,11 @@ public abstract class TestBase {
for (TestPair testPair : testPairs) { for (TestPair testPair : testPairs) {
log.info("Testing " + testPair); log.info("Testing " + testPair);
assert !Terminal.OUT_TEST.isEmpty()
: "got no output, this should never happen, since this is handled by the Terminal";
String output = popProgramOutput(); String output = popProgramOutput();
switch (testPair.getType()) { switch (testPair.getType()) {
case CHECK_EQUALS: case CHECK_EQUALS:
if (!testPair.getOutput().equals(output)) { if (output == null || !testPair.getOutput().equals(output)) {
log.info(" Failed!\n"); log.info(" Failed!\n");
printLog(); printLog();
assertEquals(testPair.getOutput(), output); assertEquals(testPair.getOutput(), output);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment