Commit e9d7627b authored by Alexander's avatar Alexander

Daily Release 21.03.2018

parents 7fd86439 e6697220
......@@ -40,7 +40,7 @@ public final class Terminal {
/**
* 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
......@@ -73,12 +73,13 @@ public final class Terminal {
String out = "Error, " + message;
if (isTest) {
String current = OUT_TEST.pollLast();
if (current == null || current.isEmpty()) {
OUT_TEST.add(out);
if (OUT_TEST.getLast() == null) {
OUT_TEST.pollLast();
OUT_TEST.add(new StringBuilder());
} else {
OUT_TEST.add(current + "\n" + out);
OUT_TEST.getLast().append("\n");
}
OUT_TEST.getLast().append(out);
} else if (isTestCreation) {
System.err.println(out);
if (useMyErrorMessagesInTestCreation) {
......@@ -103,8 +104,13 @@ public final class Terminal {
*/
public static void printLine(final Object object) {
if (isTest) {
String current = OUT_TEST.pollLast();
OUT_TEST.add((current == null ? "" : current + "\n") + object);
if (OUT_TEST.getLast() == null) {
OUT_TEST.pollLast();
OUT_TEST.add(new StringBuilder());
} else {
OUT_TEST.getLast().append("\n");
}
OUT_TEST.getLast().append(object);
} else if (isTestCreation) {
System.out.println(object);
testPairFile.append(String.valueOf(object)).append("\n");
......@@ -167,11 +173,12 @@ public final class Terminal {
}
}
}
//If the program outputted nothing we still have null which means "no output"
OUT_TEST.add(null);
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"
+ "Expect the second option or check the test!";
return IN_TEST.poll();
......
......@@ -58,14 +58,15 @@ public class Assignment1TestBase extends TestBase {
}
}
log.info("args[]: '" + strb.toString() + "'");
Terminal.OUT_TEST.add(null);
DummyMain.main(args);
String output = Terminal.OUT_TEST.poll();
StringBuilder output = Terminal.OUT_TEST.pollFirst();
if (acceptable) {
if (output != null && !output.equals(">>")) {
if (output != null) {
failAndLog("test should have succeeded");
}
} else {
if (output == null || !output.startsWith("Error")) {
if (output == null || !output.toString().startsWith("Error")) {
failAndLog("test should have failed");
}
}
......
......@@ -61,7 +61,7 @@ public class CaseCreator {
for (TestPair testPair : testPairs) {
testPairfile.append("> " + testPair.getInput() + "\n");
String partOutput;
StringBuilder partOutput;
StringBuilder stringBuilder = new StringBuilder();
do {
partOutput = Terminal.OUT_TEST.pollFirst();
......
......@@ -14,10 +14,10 @@ public class CaseCreator {
private final Random random = new Random();
private long rgenseed = System.currentTimeMillis();
private final int nCountries = 200;
private final int nSports = 50;
private final int nAthletes = 800;
private final int nErrors = 10;
private final int nCountries = 20;
private final int nSports = 100;
private final int nAthletes = 700;
private final int nErrors = 4;
public static void main(String args[]) {
......@@ -73,18 +73,29 @@ public class CaseCreator {
Vector<Vector<String>> athletes = new Vector<>();
Vector<String> athleteNames = new Vector<>();
Vector<String> athleteCountries = new Vector<>();
idCounter = 0;
for (int a = 0; a < nAthletes; a++) {
String id = String.format("%04d", ++idCounter);
ids.add(id);
athleteNames.add(randomPicker.pickName() + ";" + randomPicker.pickName());
athleteCountries.add(countries.elementAt(2 * random.nextInt(nCountries)));
}
for (int s = 0; s < nSports; s++) {
athletes.add(new Vector<>());
for (int a = 0; a < nAthletes; a++) {
String id = String.format("%04d", ++idCounter);
ids.add(id);
String country = countries.elementAt(2 * random.nextInt(nCountries));
athletes.elementAt(s).add(id);
String country = athleteCountries.elementAt(a);
if (random.nextInt(nAthletes +nSports) == 1)
country = countries.elementAt(2 * random.nextInt(nCountries));
athletes.elementAt(s).add(ids.elementAt(a));
athletes.elementAt(s).add(country);
pairs.add(new TestPair("add-athlete "
+ id + ";" + randomPicker.pickName()
+ ";" + randomPicker.pickName() + ";" + country + ";"
+ ids.elementAt(a) + ";" + athleteNames.elementAt(a) + ";" + country + ";"
+ sports.elementAt(s) + ";" + sports.elementAt(s), "OK"));
}
}
......@@ -94,7 +105,7 @@ public class CaseCreator {
for (int y = 1926; y <= 2018; y += 4) {
int indexAthlete = 2 * c;
int medal = random.nextInt(3);
int medal = random.nextInt(4);
String medalString = "";
if (medal == 0) medalString = "0;1;0";
......@@ -112,7 +123,7 @@ public class CaseCreator {
for (int f = 0; f < nErrors; f++) {
int indexAthlete = 2 * random.nextInt(nAthletes);
int medal = random.nextInt(3);
int medal = random.nextInt(4);
String medalString = "";
if (medal == 0) medalString = "0;1;0";
......@@ -163,7 +174,7 @@ public class CaseCreator {
testPairFile.append(testPair.getInput());
testPairFile.append("\n");
String partOutput;
StringBuilder partOutput;
StringBuilder stringBuilder = new StringBuilder();
do {
partOutput = Terminal.OUT_TEST.pollFirst();
......
......@@ -12,7 +12,7 @@ import org.junit.jupiter.api.Test;
*/
public class ErrorTests extends Assignment2TestBase {
/**
* This tests admin functionality
* This tests several admin errors
*/
@Test
@DisplayName("admin")
......@@ -28,4 +28,22 @@ public class ErrorTests extends Assignment2TestBase {
void competitionErrors() {
testWithIOFile(getDataFolderDirectory() + "error_tests/add_competition.io");
}
/**
* This tests several ioc-code errors
*/
@Test
@DisplayName("ioc-code")
void iocCodeErrors() {
testWithIOFile(getDataFolderDirectory() + "error_tests/ioc_code.io");
}
/**
* This tests several ioc-code errors
*/
@Test
@DisplayName("sports-venue")
void sportsVenueErrors() {
testWithIOFile(getDataFolderDirectory() + "error_tests/sports_venue.io");
}
}
......@@ -71,4 +71,10 @@ class IOTestsWithError extends Assignment2TestBase {
void competitionTests3() {
testWithIOFile(getDataFolderDirectory() + "competition_tests_3.io");
}
@Test
@DisplayName("competition-tests-4")
void competitionTests4() {
testWithIOFile(getDataFolderDirectory() + "competition_tests_4.io");
}
}
......@@ -25,8 +25,8 @@ public class PerformanceTest extends Assignment2TestBase {
* amount of memory.
*/
@Disabled
@Test
@Disabled
@DisplayName("PerformanceTest2")
void performanceTest2() {
enableShowTestProgress();
......@@ -36,8 +36,8 @@ public class PerformanceTest extends Assignment2TestBase {
testUsingPairs(pairs, () -> DummyMain.main(null));
}
@Disabled
@Test
@Disabled
@DisplayName("PerformanceTest3")
void performanceTest3() {
enableShowTestProgress();
......
This diff is collapsed.
......@@ -55,6 +55,12 @@ Error, ...
Error, ...
> add-athlete 0003;james;doe;deutschland;sdfsdf;sdfsdffff
Error, ...
> add-athlete 0001;max;mustermann;kanada;curling;curling
Error, ...
> add-athlete 0001;maxchen;mustermann;deutschland;curling;curling
Error, ...
> add-athlete 0001;max;muster;deutschland;curling;curling
Error, ...
> summary-athletes eislauf;eisschnelllauf
0001 max mustermann 0
0002 jane doe 0
......
Automatically created test
> add-admin sebastian;stüker;gbi_god;modus_ponens
OK
> login-admin gbi_god;modus_ponens
OK
> add-ioc-code
Error, wrong parameters
> add-ioc-code
Error, wrong parameters
> add-ioc-code ;;;
Error, wrong parameters
> add-ioc-code 0;ger;germany;1989
Error, wrong parameters
> add-ioc-code -1;ger;germany;1989
Error, wrong parameters
> add-ioc-code 0000;ger;germany;1989
Error, wrong parameters
> add-ioc-code 000;ger;germany;1989
Error, invalid id
> add-ioc-code 1000;ger;germany;1989
Error, wrong parameters
> add-ioc-code 001;gerr;germany;1989
Error, ioc-code has not length of 3
> add-ioc-code 001;ge;germany;1989
Error, ioc-code has not length of 3
> add-ioc-code 001;ger;germany;1989
OK
> add-ioc-code 002;ger;germany;1989
Error, ioc-code already exists
> add-ioc-code 001;usa;usa;1906
Error, id already exists
\ No newline at end of file
Automatically created test
> add-admin sebastian;stüker;gbi_god;modus_ponens
OK
> login-admin gbi_god;modus_ponens
OK
> add-sports-venue
Error, wrong parameters for this command
> add-sports-venue
Error, wrong parameters for this command
> add-sports-venue ;;;;;
Error, wrong parameters for this command
> add-sports-venue 001;germany;karlsruher institut für technologie;audimin;2017;1337
Error, unknown country
> add-ioc-code 001;ger;germany;1989
OK
> add-sports-venue 001;germany;karlsruher institut für technologie;audimin;2017;1337
OK
> add-sports-venue 001;germany;karlsruher institut für technologie;audimin;2017;1337
Error, this id already exists
> add-sports-venue 002;germany;karlsruher institut für technologie;bib;2017;-1
Error, negative (installed) number of chairs
> add-sports-venue 000;germany;karlsruher institut für technologie;bib;2017;42
Error, the id is out of bounds
> add-sports-venue 1000;germany;karlsruher institut für technologie;bib;2017;42
Error, the id is out of bounds
\ No newline at end of file
......@@ -106,9 +106,8 @@ public abstract class TestBase {
if (showAllProgramOutput && !testPassed && !Terminal.OUT_TEST.isEmpty()) {
System.out.println("The output after that was:");
while (!Terminal.OUT_TEST.isEmpty()) {
System.out.println(popProgramOutput());
}
while (!Terminal.OUT_TEST.isEmpty())
System.out.println(Terminal.OUT_TEST.pollFirst().toString());
}
clearData();
......@@ -160,17 +159,11 @@ public abstract class TestBase {
* @return a string containing the output
*/
protected String popProgramOutput() {
return Terminal.OUT_TEST.pollFirst();
}
/**
* Gets the next output from the output-queue and removes it
* This does the same as {@code popProgramOutput}
*
* @return a string containing the output
*/
protected String getNextProgramOutput() {
return popProgramOutput();
StringBuilder res = Terminal.OUT_TEST.pollFirst();
if (res == null)
return null;
else
return res.toString();
}
/**
......@@ -207,8 +200,13 @@ public abstract class TestBase {
for (TestPair testPair : testPairs) {
log.info("Testing " + testPair);
assert !Terminal.OUT_TEST.isEmpty()
: "got no output, this should never happen, since this is handled by the Terminal";
if (Terminal.OUT_TEST.isEmpty()) {
if (!Terminal.IN_TEST.isEmpty()) {
failAndLog("The program quitted too early\n"
+ "Please check that your program resets all static values!");
}
failAndLog("Found no more output. There is some serious issue!");
}
String output = popProgramOutput();
......@@ -242,7 +240,10 @@ public abstract class TestBase {
if (output != null) {
log.info(" Failed!\n");
printLog();
fail("Output should have been empty but was:" + output);
if (output.equals("")) {
output = "(empty string)";
}
fail("Output should have been empty but was: " + output);
}
break;
case NO_CHECK:
......
......@@ -6,7 +6,7 @@ public class TestPair {
return "Fail with " + this + "\nThe program provided no output for that command";
}
return "Fail with " + this + "\nOutput was"
return "Fail with " + this + "\nOutput was:"
+ (actualOutput.contains("\n") ? "\n" : " ")
+ actualOutput + (actualOutput.isEmpty() ? "(empty)" : "");
}
......
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