Commit 9868d441 authored by Jon Amos Fehling's avatar Jon Amos Fehling
Browse files

Merge branch 'development' of git.scc.kit.edu:WS-17-18/assignment-tests into development

parents c413de9c a2a73f96
......@@ -23,7 +23,7 @@ public final class Terminal {
* If enabled Terminal creates a file with TestPairs of the current run
*/
public static boolean isTestCreation = false;
private static boolean useErrorMessagesInTestCreation = true;
public static boolean useMyErrorMessagesInTestCreation = true;
private static StringBuilder testPairFile = new StringBuilder();
/**
......@@ -42,11 +42,6 @@ public final class Terminal {
*/
private static final BufferedReader IN = new BufferedReader(new InputStreamReader(System.in));
/**
* this boolean determines whether the user already outputted something for that readLine call
*/
public static boolean concatOutput = true;
/**
* Private constructor to avoid object generation.
*
......@@ -71,15 +66,15 @@ public final class Terminal {
String out = "Error, " + message;
if (isTest) {
if (concatOutput) {
OUT_TEST.add(OUT_TEST.pollLast() + "\n" + out);
} else {
String current = OUT_TEST.pollLast();
if (current == null || current.isEmpty()) {
OUT_TEST.add(out);
concatOutput = true;
} else {
OUT_TEST.add(current + "\n" + out);
}
} else if (isTestCreation) {
System.err.println(out);
if (useErrorMessagesInTestCreation) {
if (useMyErrorMessagesInTestCreation) {
testPairFile.append(out);
testPairFile.append("\n");
} else {
......@@ -101,12 +96,8 @@ public final class Terminal {
*/
public static void printLine(final Object object) {
if (isTest) {
if (concatOutput) {
OUT_TEST.add(OUT_TEST.pollLast() + "\n" + object);
} else {
OUT_TEST.add(object.toString());
concatOutput = true;
}
String current = OUT_TEST.pollLast();
OUT_TEST.add((current.isEmpty() ? "" : current + "\n") + object);
} else if (isTestCreation) {
System.out.println(object);
testPairFile.append(String.valueOf(object)).append("\n");
......@@ -157,12 +148,9 @@ public final class Terminal {
throw new RuntimeException(e);
}
else {
if (!concatOutput) {
//The program outputted nothing. To support this in tests, we append an empty line
//If the program outputted nothing we still have at least an empty line
OUT_TEST.add("");
} else {
concatOutput = false;
}
assert !IN_TEST.isEmpty()
: "Either the executed test doesn't has quit as last input\n"
+ "or your quitting mechanism doesn't work properly.\n"
......@@ -248,7 +236,7 @@ public final class Terminal {
* @param doNotUseMyErrorMessages tells the program to use 'Error, ...' instead of the error-msges for io-files
*/
public static void startTestCreation(String[] args, boolean doNotUseMyErrorMessages) {
useErrorMessagesInTestCreation = !doNotUseMyErrorMessages;
useMyErrorMessagesInTestCreation = !doNotUseMyErrorMessages;
startTestCreation(args);
}
}
......@@ -47,7 +47,6 @@ public class Assignment1TestBase extends TestBase {
* @param acceptable specify whether these args are ok or not
*/
protected void testArgs(String args[], boolean acceptable) {
Terminal.concatOutput = false;
Terminal.IN_TEST.add("quit");
StringBuilder strb = new StringBuilder();
for (int i = 0; i < args.length; i++) {
......
package final_assignment.task_1;
import edu.kit.informatik.Terminal;
/**
* Run this to manually create a .io-file
*
* @author Alexander Sommer
* @since 06.03.2018
*/
public class ManualTestCreation {
public static void main(String[] args) {
/*
If you want to submit tests, it would be useful to give a reason
why your program outputs an error for others to comprehend.
If you don't want that exactly the error-messages of your program are used in the test,
you can still find and replace them afterwards (CTRL + R).
*/
Terminal.useMyErrorMessagesInTestCreation = true;
Terminal.startTestCreation(args);
DummyMain.main(args);
Terminal.saveInputOutputPairs();
}
}
package final_assignment.task_2;
import edu.kit.informatik.Terminal;
import org.junit.jupiter.api.AfterAll;
import test.TestBase;
import test.TestPair;
import java.io.File;
/**
* This class links the DummyMain of this task and the TestBase
*
......@@ -30,7 +33,40 @@ public class Assignment2TestBase extends TestBase {
testUsingPairs(testPairs, () -> DummyMain.main(args));
}
protected String getDataFolderDirectory() {
protected static String getDataFolderDirectory() {
return "src/final_assignment/task_2/tests/data/";
}
private static int testClassCount = 0;
protected static int getTestClassCount() {
if (testClassCount == 0) {
final File folder = new File(getDataFolderDirectory() + "../");
File[] files = folder.listFiles();
if (files == null) {
return 0;
}
for (final File fileEntry : files) {
if (fileEntry.getName().contains(".java")) {
testClassCount++;
}
}
}
return testClassCount;
}
private static int runCount = 0;
@AfterAll
public static void finish() {
if (++runCount >= getTestClassCount()) {
int sum = numSucceeded + numFailed;
double percentage = (numSucceeded * 100.) / sum;
System.out.printf("You mastered %.2f %% of the %d tests!%n", percentage, sum);
}
}
}
......@@ -10,6 +10,13 @@ import edu.kit.informatik.Terminal;
*/
public class ManualTestCreation {
public static void main(String[] args) {
/*
If you want to submit tests, it would be useful to give a reason
why your program outputs an error for others to comprehend.
If you don't want that exactly the error-messages of your program are used in the test,
you can still find and replace them afterwards (CTRL + R).
*/
Terminal.useMyErrorMessagesInTestCreation = true;
Terminal.startTestCreation(args);
DummyMain.main(args);
Terminal.saveInputOutputPairs();
......
package test;
import edu.kit.informatik.Terminal;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.*;
import java.io.*;
import java.net.NetworkInterface;
......@@ -15,7 +12,6 @@ import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.logging.Handler;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
......@@ -48,7 +44,8 @@ public abstract class TestBase {
private long startTime;
private static String userId;
public static final String IO_FILE_COMMAND_LINE_ARGS_PREFIX = "! ";
protected static int numFailed = 0;
protected static int numSucceeded = 0;
/**
* Initializes testing
......@@ -104,7 +101,6 @@ public abstract class TestBase {
*/
@BeforeEach
protected void initTest(TestInfo testInfo) {
Terminal.concatOutput = true;
alwaysShowLog = false;
isPerformanceTest = false;
testPassed = false;
......@@ -161,6 +157,12 @@ public abstract class TestBase {
*/
@AfterEach
protected void cleanUp(TestInfo testInfo) {
if (testPassed) {
numSucceeded++;
} else {
numFailed++;
}
if (isPerformanceTest && testPassed) {
long endTime = System.nanoTime();
double runTime = ((double) (endTime - startTime)) / 1000000.0;
......@@ -193,7 +195,7 @@ public abstract class TestBase {
}
}
if (showAllProgramOutput && !Terminal.OUT_TEST.isEmpty()) {
if (showAllProgramOutput && !testPassed && !Terminal.OUT_TEST.isEmpty()) {
System.out.println("The output after that was:");
while (!Terminal.OUT_TEST.isEmpty()) {
......@@ -214,7 +216,6 @@ public abstract class TestBase {
if (alwaysShowLog)
printLog();
logData.clear();
Terminal.concatOutput = true;
}
......@@ -293,7 +294,6 @@ public abstract class TestBase {
* @param testedMethod is a reference to a tested program
*/
protected void testUsingPairs(TestPair[] testPairs, Runnable testedMethod) {
Terminal.concatOutput = true;
log.info("Testing using " + testPairs.length + " pairs...\n");
for (TestPair testPair : testPairs) {
......@@ -308,7 +308,7 @@ public abstract class TestBase {
String output = popProgramOutput();
assert output != null : "got no output"; // This should never happen, since this is handled by the Terminal
assert output != null : "got no output, this should never happen, since this is handled by the Terminal";
switch (testPair.getType()) {
case CHECK_EQUALS:
......
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