Commit fa561aaa authored by Alexander's avatar Alexander
Browse files

Daily release 12.03.2018

parents ecad95b5 17651f29
......@@ -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 == null ? "" : current + "\n") + object);
} else if (isTestCreation) {
System.out.println(object);
testPairFile.append(String.valueOf(object)).append("\n");
......@@ -148,8 +148,8 @@ public final class Terminal {
throw new RuntimeException(e);
}
else {
//If the program outputted nothing we still have at least an empty line
OUT_TEST.add("");
//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"
......
......@@ -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 {
......
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();
}
}
......@@ -9,7 +9,6 @@ public class PerformanceTests extends Assignment1TestBase {
@Test
@DisplayName("PerformanceTest1")
void performanceTest1() {
enablePerformanceTest();
String path = "src/final_assignment/task_1/tests/data/performance_test_1.io";
TestPair[] pairs = loadTestPairsFromIOFile(path);
String args[] = {"torus", "20", "2"};
......
package final_assignment.task_2;
import edu.kit.informatik.Terminal;
import org.junit.jupiter.api.*;
import test.TestBase;
import test.TestPair;
import java.io.*;
import java.net.NetworkInterface;
import java.net.Socket;
import java.net.SocketException;
import java.util.Enumeration;
import static org.junit.jupiter.api.Assertions.fail;
/**
* This class links the DummyMain of this task and the TestBase
*
......@@ -11,6 +19,10 @@ import test.TestPair;
* @since 23.02.2018
*/
public class Assignment2TestBase extends TestBase {
private static String userId;
private boolean isPerformanceTest;
private long startTime;
/**
* Tests the program linked with the DummyMain with the specified io-file
*
......@@ -30,7 +42,150 @@ 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 = numSucceededTests + numFailedTests;
double percentage = (numSucceededTests * 100.) / sum;
System.out.printf("\n\nYou mastered %.2f %% of the %d tests!%n", percentage, sum);
}
}
// Performance Test stuff
@BeforeEach
void disablePerformanceTest() {
isPerformanceTest = false;
}
private double getReferenceTime() {
long startTime = System.nanoTime();
int value = 1337;
for (int i = 0; i < Math.pow(2, 21); i++) {
value += i;
if (value > Math.pow(2, 21)) {
value %= i;
}
}
long endTime = System.nanoTime();
double time = (endTime - startTime) / 1000000.0;
System.out.println("The reference time is: " + time + " ms. Ref-value: " + value + ".");
return time;
}
@AfterEach
public void measurePerformance(TestInfo testInfo) {
if (isPerformanceTest && testPassed) {
long endTime = System.nanoTime();
double runTime = ((double) (endTime - startTime)) / 1000000.0;
double refTime = getReferenceTime();
double standardRunTime = runTime / refTime * 30.0;
System.out.println("Your run time for test '" + getTestName(testInfo) + "' is " + runTime + " ms.");
System.out.println("Standard run time based on your run time is " + standardRunTime + " ms.");
try {
Socket socket = new Socket("vaelum.de", 12000);
PrintWriter out = new PrintWriter(socket.getOutputStream());
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
out.print(userId + "\n");
out.flush();
out.print(getTestName(testInfo) + "\n");
out.flush();
out.print("" + standardRunTime + "\n");
out.flush();
System.out.println(in.readLine() + "\n");
in.close();
out.close();
socket.close();
} catch (IOException e2) {
System.out.println(e2 + "\n");
}
}
}
private static String getMacAddress() {
try {
Enumeration<NetworkInterface> networks = NetworkInterface.getNetworkInterfaces();
while (networks.hasMoreElements()) {
NetworkInterface network = networks.nextElement();
byte[] mac = network.getHardwareAddress();
if (mac != null) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < mac.length; i++) {
sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? ":" : ""));
}
return sb.toString();
}
}
} catch (SocketException e) {
e.printStackTrace();
}
fail("Unable to get mac address.");
return null;
}
@BeforeAll
public static void checkUserId() {
userId = getMacAddress();
final String USER_ID_FILENAME = "UserId.id";
try (final BufferedReader reader = new BufferedReader(new FileReader(USER_ID_FILENAME))) {
userId = reader.readLine();
reader.close();
} catch (final IOException e) {
try {
PrintWriter of = new PrintWriter(USER_ID_FILENAME);
of.println(userId);
of.close();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
}
}
protected void enablePerformanceTest() {
isPerformanceTest = true;
checkUserId();
startTime = System.nanoTime();
}
}
......@@ -14,10 +14,10 @@ public class CaseCreator {
private final Random random = new Random();
private long rgenseed = System.currentTimeMillis();
private final int nCountries = 20;
private final int nSports = 20;
private final int nAthletes = 21;
private final int nErrors = 100;
private final int nCountries = 200;
private final int nSports = 50;
private final int nAthletes = 800;
private final int nErrors = 10;
public static void main(String args[]) {
......@@ -57,7 +57,7 @@ public class CaseCreator {
ids.add(id);
pairs.add(new TestPair("add-ioc-code " + id + ";" + countries.elementAt(2 * i + 1) + ";"
+ countries.elementAt(2 * i) + ";2000", "OK"));
+ countries.elementAt(2 * i) + ";1946", "OK"));
}
ids.clear();
......@@ -130,7 +130,7 @@ public class CaseCreator {
for (int s = 0; s < nSports; s++) {
pairs.add(new TestPair("summary-athletes " + sports.elementAt(s), ""));
pairs.add(new TestPair("summary-athletes " + sports.elementAt(s) + ";" + sports.elementAt(s), ""));
}
pairs.add(new TestPair("olympic-medal-table", ""));
......
package final_assignment.task_2;
import program_examples.Main;
/**
......
......@@ -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");
}
/**
......@@ -55,4 +55,10 @@ class IOTestsWithError extends Assignment2TestBase {
void competitionTests2() {
testWithIOFile(getDataFolderDirectory() + "competition_tests_2.io");
}
@Test
@DisplayName("competition-tests-3")
void competitionTests3() {
testWithIOFile(getDataFolderDirectory() + "competition_tests_3.io");
}
}
package final_assignment.task_2.tests;
import final_assignment.task_2.Assignment2TestBase;
import final_assignment.task_2.DummyMain;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import test.TestPair;
public class PerformanceTest extends Assignment2TestBase {
@Test
@DisplayName("performance-test-1")
public void performanceTest1() {
String path = getDataFolderDirectory() + "performance/performance_test_1.io";
TestPair[] pairs = loadTestPairsFromIOFile(path);
enablePerformanceTest();
testUsingPairs(pairs, () -> DummyMain.main(null));
}
/**
* The following 2 performance tests are disabled because they wont finish in acceptable time
* unless your implementation has a good time complexity. Fell free to enable them
* by removing '@Disabled'. You may run them individually because they need a hugh
* amount of memory.
*/
@Disabled
@Test
@DisplayName("PerformanceTest2")
void performanceTest2() {
String path = getDataFolderDirectory() + "performance/performance_test_2.io";
TestPair[] pairs = loadTestPairsFromIOFile(path);
enablePerformanceTest();
testUsingPairs(pairs, () -> DummyMain.main(null));
}
@Disabled
@Test
@DisplayName("PerformanceTest3")
void performanceTest3() {
String path = getDataFolderDirectory() + "performance/performance_test_3.io";
TestPair[] pairs = loadTestPairsFromIOFile(path);
enablePerformanceTest();
testUsingPairs(pairs, () -> DummyMain.main(null));
}
}
......@@ -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
This diff is collapsed.
......@@ -5,9 +5,16 @@ OK
OK
> add-olympic-sport eishockey;eishockey
OK
> add-ioc-code 111;arg;argentinien;1920
> add-ioc-code 111;arg;argentinien;1940
OK
> add-athlete 0001;max;mustermann;argentinien;eishockey;eishockey
OK
> add-competition 0001;2002;canada;eishockey;eishockey;-1;0;0
Error, wrong number of medals
\ No newline at end of file
Error, wrong number of medals
> 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
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