Commit ca65ce64 authored by Jon Amos Fehling's avatar Jon Amos Fehling
Browse files

add test for empty outputs

parent 03c9d393
......@@ -70,7 +70,7 @@ public final class Terminal {
if (current == null || current.isEmpty()) {
OUT_TEST.add(out);
} else {
OUT_TEST.add(current + "\n" + out);
OUT_TEST.add((current.equals(">>") ? "" : current + "\n") + out);
}
} else if (isTestCreation) {
System.err.println(out);
......@@ -97,7 +97,7 @@ public final class Terminal {
public static void printLine(final Object object) {
if (isTest) {
String current = OUT_TEST.pollLast();
OUT_TEST.add((current.isEmpty() ? "" : current + "\n") + object);
OUT_TEST.add((current.equals(">>") ? "" : current + "\n") + object);
} else if (isTestCreation) {
System.out.println(object);
testPairFile.append(String.valueOf(object)).append("\n");
......@@ -149,7 +149,7 @@ public final class Terminal {
}
else {
//If the program outputted nothing we still have at least an empty line
OUT_TEST.add("");
OUT_TEST.add(">>");
assert !IN_TEST.isEmpty()
: "Either the executed test doesn't has quit as last input\n"
......
......@@ -61,7 +61,7 @@ public class Assignment1TestBase extends TestBase {
DummyMain.main(args);
String output = Terminal.OUT_TEST.poll();
if (acceptable) {
if (output != null && !output.equals("")) {
if (output != null && !output.equals(">>")) {
failAndLog("test should have succeeded");
}
} else {
......
......@@ -11,7 +11,7 @@ class IOTestsWithError extends Assignment2TestBase {
@Test
@DisplayName("venue-test")
void venueTest() {
testWithIOFile(getDataFolderDirectory() + "venue_tests.io");
testWithIOFile(getDataFolderDirectory() + "error_tests/venue_tests.io");
}
/**
......@@ -20,7 +20,7 @@ class IOTestsWithError extends Assignment2TestBase {
@Test
@DisplayName("ioc-code-tests")
void iocCodeTest() {
testWithIOFile(getDataFolderDirectory() + "ioc_codes_tests.io");
testWithIOFile(getDataFolderDirectory() + "error_tests/ioc_codes_tests.io");
}
/**
......@@ -29,7 +29,7 @@ class IOTestsWithError extends Assignment2TestBase {
@Test
@DisplayName("sport-tests")
void sportTests() {
testWithIOFile(getDataFolderDirectory() + "sport_tests.io");
testWithIOFile(getDataFolderDirectory() + "error_tests/sport_tests.io");
}
/**
......@@ -38,7 +38,7 @@ class IOTestsWithError extends Assignment2TestBase {
@Test
@DisplayName("athlete-tests")
void athleteTests() {
testWithIOFile(getDataFolderDirectory() + "athlete_tests.io");
testWithIOFile(getDataFolderDirectory() + "error_tests/athlete_tests.io");
}
/**
......
......@@ -138,4 +138,4 @@ hslbxb mhzbtx
(7,827,mdw,iunmgurgdb,0,1,0,1)
(8,319,qie,hugfleibgj,0,0,0,0)
(9,683,zbs,boqrrcngxx,0,0,0,0)
(10,734,mij,xkgezgcywo,0,0,0,0)
(10,734,mij,xkgezgcywo,0,0,0,0)
\ No newline at end of file
......@@ -11,5 +11,10 @@ OK
OK
> add-competition 0001;2002;canada;eishockey;eishockey;-1;0;0
Error, wrong number of medals
> add-competition 0001;1926;canada;eishockey;eishockey;1;0;0
> add-competition 0001;1926;argentinien;eishockey;eishockey;1;0;0
Error, year 1926 is before year of registration.
> reset
OK
> olympic-medal-table
> reset
OK
\ No newline at end of file
......@@ -57,4 +57,11 @@ Error, ...
Error, ...
> summary-athletes eislauf;eisschnelllauf
0001 max mustermann 0
0002 jane doe 0
\ No newline at end of file
0002 jane doe 0
> reset
OK
> add-olympic-sport eislauf;eisschnelllauf
OK
> summary-athletes eislauf;eisschnelllauf
> reset
OK
\ No newline at end of file
......@@ -36,4 +36,9 @@ Error, ...
1924 116 ecu ecuador
1984 112 bhu bhutan
1992 115 cze tschechien
1992 118 ger deutschland
\ No newline at end of file
1992 118 ger deutschland
> reset
OK
> list-ioc-codes
> reset
OK
\ No newline at end of file
......@@ -26,4 +26,9 @@ bobsport skeleton
curling curling
eishockey eishockey
eislauf eiskunstlauf
eislauf eisschnelllauf
\ No newline at end of file
eislauf eisschnelllauf
> reset
OK
> list-olympic-sports
> reset
OK
\ No newline at end of file
......@@ -48,4 +48,11 @@ Error, ...
> list-sports-venues spanien
(1 020 barcelona 1000)
(2 001 madrid 100000)
(3 010 madrid 100000)
\ No newline at end of file
(3 010 madrid 100000)
> reset
OK
> add-ioc-code 117;esp;spanien;1900
OK
> list-sports-venues spanien
> reset
OK
\ No newline at end of file
......@@ -48,4 +48,5 @@ OK
> reset
OK
> list-ioc-codes
> reset
OK
\ No newline at end of file
......@@ -312,7 +312,13 @@ public abstract class TestBase {
switch (testPair.getType()) {
case CHECK_EQUALS:
if (!output.equals(testPair.getOutput())) {
if (testPair.getOutput().equals("")) {
if (!output.equals(">>")) {
log.info(" Failed!\n");
printLog();
fail("Output should have been empty but was:"+output);
}
} else if (!output.equals(testPair.getOutput())) {
log.info(" Failed!\n");
printLog();
assertEquals(testPair.getOutput(), output);
......@@ -435,7 +441,9 @@ public abstract class TestBase {
*/
private TestPair getIOTestPair(StringBuilder builder, String input) {
final String startsWithPostfix = "...";
String output = builder.deleteCharAt(builder.length() - 1).toString();
String output = "";
if (builder.length() != 0)
output = builder.deleteCharAt(builder.length() - 1).toString();
if (output.startsWith(ERROR_PREFIX)) {
return new TestPair(input, output, TestPair.Type.CHECK_FOR_ERROR);
}
......
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