Commit 29ed3709 authored by uhflp's avatar uhflp Committed by ungpk
Browse files

Daily release 28.02.2018

parent a202d2de
......@@ -24,6 +24,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;
private static StringBuilder testPairFile = new StringBuilder();
/**
......@@ -63,13 +64,19 @@ public final class Terminal {
* @param message the error message to be printed
*/
public static void printError(final String message) {
String out = "Error, " + message;
if (isTest) {
OUT_TEST.add("Error, " + message);
OUT_TEST.add(out);
} else if (isTestCreation) {
System.err.println("Error, " + message);
testPairFile.append("Error, ...\n");
System.err.println(out);
if (useErrorMessagesInTestCreation) {
testPairFile.append(out);
} else {
testPairFile.append("Error, ...\n");
}
} else {
System.err.println("Error, " + message);
System.err.println(out);
}
}
......@@ -110,7 +117,7 @@ public final class Terminal {
* differently when passing the provided parameter to the System.out.println(Object)
* method.)
*/
printLine(charArray);
printLine((Object) charArray);
}
/**
......@@ -213,4 +220,15 @@ public final class Terminal {
testPairFile.append("\n");
}
}
/**
* This automatically adds the specified command line args to the test creation
*
* @param args are the args to add
* @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;
startTestCreation(args);
}
}
......@@ -5,7 +5,7 @@ import program_examples.Main;
/**
* Dummy for your main class. DummyMain should inherit from your main class.
* Be sure to use the right main class.
* <p>
*
* Dev-Notice: Don't commit on this file, just change it locally.
* You can use 'git update-index --assume-unchanged <this file>' to disable committing.
* To reenable it use git update-index --no-assume-unchanged <this file>'.
......
package final_assignment.task_1.tests;
import final_assignment.task_1.Assignment1TestBase;
import final_assignment.task_1.DummyMain;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import test.TestPair;
......@@ -14,26 +13,8 @@ public class PerformanceTests extends Assignment1TestBase {
String path = "src/final_assignment/task_1/tests/data/performance_test_1.io";
TestPair[] pairs = loadTestPairsFromIOFile(path);
String args[] = {"torus", "20", "2"};
testUsingPairs(pairs, args);
testUsingPairs(pairs, args);
testUsingPairs(pairs, args);
testUsingPairs(pairs, args);
testUsingPairs(pairs, args);
testUsingPairs(pairs, args);
testUsingPairs(pairs, args);
testUsingPairs(pairs, args);
testUsingPairs(pairs, args);
testUsingPairs(pairs, args);
testUsingPairs(pairs, args);
testUsingPairs(pairs, args);
testUsingPairs(pairs, args);
testUsingPairs(pairs, args);
testUsingPairs(pairs, args);
testUsingPairs(pairs, args);
testUsingPairs(pairs, args);
testUsingPairs(pairs, args);
testUsingPairs(pairs, args);
testUsingPairs(pairs, args);
testUsingPairs(pairs, args);
for (int i = 0; i < 20; i++) {
testUsingPairs(pairs, args);
}
}
}
package final_assignment.task_2;
import edu.kit.informatik.Terminal;
import test.TestPair;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Random;
import java.util.Vector;
public class CaseCreator {
private static StringBuilder testPairfile;
private static final Random random = new Random();
private static long rgenseed = System.currentTimeMillis();
private static final int nCountries = 20;
private static final int nSports = 4;
private static final int nAthletes = 2300; //nAthletes*nSports<10000
private static final int nCompetitions = 200000;
public static void main(String args[]) {
Terminal.isTest = true;
for (int i = 0; i < 1; i++) {
rgenseed = System.currentTimeMillis();
random.setSeed(rgenseed);
createTest();
}
}
private static void createTest() {
System.out.println("Creating input...");
testPairfile = new StringBuilder();
Terminal.IN_TEST.clear();
Terminal.OUT_TEST.clear();
Vector<TestPair> pairs = new Vector<TestPair>();
pairs.add(new TestPair("add-admin Vorname;Nachname;tester;123123123", "OK"));
pairs.add(new TestPair("login-admin tester;123123123", "OK"));
Vector<String> ids = new Vector<>();
Vector<String> countries = new Vector<>();
for (int i = 0; i < nCountries; i++) {
String country = new String();
do {
country = randomString("abcdefghijklmnobqrstuvwxyz", 10);
} while (countries.contains(country));
countries.add(country);
do {
country = randomString("abcdefghijklmnobqrstuvwxyz", 3);
} while (countries.contains(country));
countries.add(country);
String id = new String();
do {
id = randomString("123456789", 3);
} while (ids.contains(id));
ids.add(id);
pairs.add(new TestPair("add-ioc-code " + id + ";" + countries.elementAt(2 * i + 1) + ";"
+ countries.elementAt(2 * i) + ";2000", "OK"));
}
ids.clear();
Vector<String> sports = new Vector<>();
for (int i = 0; i < nSports; i++) {
String country = new String();
do {
country = randomString("abcdefghijklmnobqrstuvwxyz", 6);
} while (sports.contains(country));
sports.add(country);
do {
country = randomString("abcdefghijklmnobqrstuvwxyz", 6);
} while (sports.contains(country));
sports.add(country);
pairs.add(new TestPair("add-olympic-sport " + sports.elementAt(2 * i) + ";"
+ sports.elementAt(2 * i + 1), "OK"));
}
Vector<Vector<String>> athletes = new Vector<>();
for (int s = 0; s < nSports; s++) {
athletes.add(new Vector<>());
for (int a = 0; a < nAthletes; a++) {
String id = new String();
do {
id = randomString("0123456789", 4);
} while (ids.contains(id) || id.equals("0000"));
ids.add(id);
String country = countries.elementAt(2 * random.nextInt(nCountries));
athletes.elementAt(s).add(id);
athletes.elementAt(s).add(country);
pairs.add(new TestPair("add-athlete " + id + ";" + randomString("abcdefghijklmnobqrstuvwxyz ", 10) + ";" + randomString("abcdefghijklmnobqrstuvwxyz ", 10) + ";" + country + ";"
+ sports.elementAt(2 * s) + ";" + sports.elementAt(2 * s + 1), "OK"));
}
}
for (int s = 0; s < nSports; s++) {
for (int c = 0; c < nCompetitions; c++) {
int indexAthlete = 2 * random.nextInt(nAthletes);
int medal = random.nextInt(3);
String medalString = new String();
if (medal == 0) medalString = "0;1;0";
if (medal == 1) medalString = "1;0;0";
if (medal == 2) medalString = "0;0;1";
pairs.add(new TestPair("add-competition " + athletes.elementAt(s).elementAt(indexAthlete) + ";" + (1926 + random.nextInt(24) * 4) + ";"
+ athletes.elementAt(s).elementAt(indexAthlete + 1) + ";"
+ sports.elementAt(2 * s) + ";" + sports.elementAt(2 * s + 1) + ";" + medalString, "OK"));
}
}
pairs.add(new TestPair("list-olympic-sports", "OK"));
for (int s = 0; s < nSports; s++) {
pairs.add(new TestPair("summary-athletes " + sports.elementAt(2 * s + 1), ""));
}
pairs.add(new TestPair("olympic-medal-table", ""));
System.out.println("Creating output...");
testUsingPairs(pairs.toArray(new TestPair[pairs.size()]), () -> DummyMain.main(null));
System.out.println("Saving...");
saveInputOutputPairs();
}
private static void testUsingPairs(TestPair[] testPairs, Runnable testedMethod) {
for (TestPair testPair : testPairs) {
Terminal.IN_TEST.add(testPair.getInput());
}
Terminal.IN_TEST.add("quit");
testedMethod.run();
for (TestPair testPair : testPairs) {
testPairfile.append("> " + testPair.getInput() + "\n");
String partOutput;
StringBuilder stringBuilder = new StringBuilder();
do {
partOutput = Terminal.OUT_TEST.pollFirst();
if (partOutput == null)
break;
stringBuilder.append(partOutput);
stringBuilder.append("\n");
} while (stringBuilder.length() < testPair.getOutput().length());
if (stringBuilder.length() != 0) {
stringBuilder.deleteCharAt(stringBuilder.length() - 1);
}
String output = stringBuilder.toString();
testPairfile.append(output + "\n");
}
}
public static void saveInputOutputPairs() {
String path = "testPairs_" + new java.util.Date().getTime() + ".io";
try (PrintWriter out = new PrintWriter(path)) {
out.print("Automatically created test with seed " + rgenseed + "\n" + testPairfile.toString());
} catch (FileNotFoundException e) {
System.out.println("Unable to open file " + path + " for saving test pairs.");
}
}
public static String randomString(String chars, int length) {
StringBuilder strb = new StringBuilder();
int range = chars.length();
for (int i = 0; i < length; i++) {
strb.append(chars.charAt(random.nextInt(range)));
}
return strb.toString();
}
}
\ No newline at end of file
package final_assignment.task_2.tests;
import final_assignment.task_2.Assignment2TestBase;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
class IOTestsWithError extends Assignment2TestBase {
/**
* Tests the creation of venues
*/
@Test
@DisplayName("venue-test")
void venueTest() {
testWithIOFile(getDataFolderDirectory() + "venue_tests.io");
}
/**
* Tests the creation of ioc codes
*/
@Test
@DisplayName("ioc-code-tests")
void iocCodeTest() {
testWithIOFile(getDataFolderDirectory() + "ioc_codes_tests.io");
}
/**
* Tests the creation of sports
*/
@Test
@DisplayName("sport-tests")
void sportTests() {
testWithIOFile(getDataFolderDirectory() + "sport_tests.io");
}
/**
* Tests the creation of athletes
*/
@Test
@DisplayName("athlete-tests")
void athleteTests() {
testWithIOFile(getDataFolderDirectory() + "athlete_tests.io");
}
}
......@@ -15,6 +15,7 @@ public class IOTestsWithNoError extends Assignment2TestBase {
@Test
@DisplayName("assignment-example")
void assignmentExample() {
enableShowAllProgramOutput();
testWithIOFile(getDataFolderDirectory() + "assignment_example.io");
}
}
......@@ -13,7 +13,7 @@ public class PermissionTests extends Assignment2TestBase {
* Tests the examples from the assignment
*/
@Test
@DisplayName("permission tests no error")
@DisplayName("permission tests")
void assignmentExample() {
testWithIOFile(getDataFolderDirectory() + "permission_tests.io");
}
......
Tests creation of athletes
> add-admin Vorname;Nachname;tester;123123123
OK
> login-admin tester;123123123
OK
> add-olympic-sport eishockey;eishockey
OK
> add-olympic-sport biathlon;biathlon
OK
> add-olympic-sport bobsport;bob
OK
> add-olympic-sport bobsport;skeleton
OK
> add-olympic-sport curling;curling
OK
> add-olympic-sport eislauf;eiskunstlauf
OK
> add-olympic-sport eislauf;eisschnelllauf
OK
> add-ioc-code 111;arg;argentinien;1920
OK
> add-ioc-code 112;bhu;bhutan;1984
OK
> add-ioc-code 113;bul;bulgarien;1896
OK
> add-ioc-code 114;chi;chile;1896
OK
> add-ioc-code 115;cze;tschechien;1992
OK
> add-ioc-code 116;ecu;ecuador;1924
OK
> add-ioc-code 117;esp;spanien;1900
OK
> add-ioc-code 118;ger;deutschland;1992
OK
> add-ioc-code 119;can;kanada;1900
OK
> add-athlete 0001;max;mustermann;deutschland;bobsport;bob
OK
> add-athlete 0001;max;mustermann;deutschland;eislauf;eisschnelllauf
OK
> add-athlete 0002;jane;doe;kanada;eislauf;eiskunstlauf
OK
> add-athlete 0002;jane;doe;kanada;eislauf;eisschnelllauf
OK
> add-athlete 0002;jane;doe;kanada;eislauf;eisschnelllauf
Error, ...
> add-athlete 0002;jane;doe;deutschland;eislauf;eisschnelllauf
Error, ...
> add-athlete 0003;james;doe;frankreich;eislauf;eisschnelllauf
Error, ...
> add-athlete 0003;james;doe;deutschland;curling;eisschnelllauf
Error, ...
> add-athlete 0003;james;doe;deutschland;eislauf;curling
Error, ...
> add-athlete 0003;james;doe;deutschland;sdfsdf;sdfsdffff
Error, ...
> summary-athletes eisschnelllauf
0001 max mustermann 0
0002 jane doe 0
\ No newline at end of file
Tests the creation of ioc codes
> add-admin Vorname;Nachname;tester;123123123
OK
> login-admin tester;123123123
OK
> add-ioc-code 111;arg;argentinien;1920
OK
> add-ioc-code 112;bhu;bhutan;1984
OK
> add-ioc-code 113;bul;bulgarien;1896
OK
> add-ioc-code 114;chi;chile;1896
OK
> add-ioc-code 115;cze;tschechien;1992
OK
> add-ioc-code 116;ecu;ecuador;1924
OK
> add-ioc-code 117;esp;spanien;1900
OK
> add-ioc-code 118;ger;deutschland;1992
OK
> add-ioc-code 119;can;kanada;1900
OK
> add-ioc-code 119;fra;frankreich;1900
Error, ...
> add-ioc-code 200;can;canbotscha;1900
Error, ...
> add-ioc-code 201;ca;canada;2000
Error, ...
> list-ioc-codes
1896 113 bul bulgarien
1896 114 chi chile
1900 117 esp spanien
1900 119 can kanada
1920 111 arg argentinien
1924 116 ecu ecuador
1984 112 bhu bhutan
1992 115 cze tschechien
1992 118 ger deutschland
\ No newline at end of file
......@@ -45,3 +45,15 @@ Error, ...
OK
> add-athlete 0001;max;mustermann;argentinien;eishockey;eishockey
OK
> reset
OK
> logout
Error, ...
> login-admin tester;123123123
Error, ...
> add-admin Vorname;Nachname;tester;123123123
OK
> login-admin tester;123123123
OK
> list-ioc-codes
Tests the creation of sports
> add-admin Vorname;Nachname;tester;123123123
OK
> login-admin tester;123123123
OK
> add-olympic-sport eishockey;eishockey
OK
> add-olympic-sport biathlon;biathlon
OK
> add-olympic-sport bobsport;bob
OK
> add-olympic-sport bobsport;skeleton
OK
> add-olympic-sport curling;curling
OK
> add-olympic-sport eislauf;eiskunstlauf
OK
> add-olympic-sport eislauf;eisschnelllauf
OK
> add-olympic-sport eislauf;eisschnelllauf
Error, ...
> list-olympic-sports
biathlon biathlon
bobsport bob
bobsport skeleton
curling curling
eishockey eishockey
eislauf eiskunstlauf
eislauf eisschnelllauf
\ No newline at end of file
Tests the creation of venues
> add-admin Vorname;Nachname;tester;123123123
OK
> login-admin tester;123123123
OK
> add-ioc-code 111;arg;argentinien;1920
OK
> add-ioc-code 112;bhu;bhutan;1984
OK
> add-ioc-code 113;bul;bulgarien;1896
OK
> add-ioc-code 114;chi;chile;1896
OK
> add-ioc-code 115;cze;tschechien;1992
OK
> add-ioc-code 116;ecu;ecuador;1924
OK
> add-ioc-code 117;esp;spanien;1900
OK
> add-ioc-code 118;ger;deutschland;1992
OK
> add-ioc-code 119;can;kanada;1900
OK
> add-sports-venue 000;spanien;Madrid;Stadion;2000;100000
Error, ...
> add-sports-venue 010;spanien;Madrid;Stadion;2000;100000
OK
> add-sports-venue 020;spanien;Barcelona;Halle;2002;1000
OK
> add-sports-venue 001;spanien;Madrid;Stadion 2;2000;100000
OK
> add-sports-venue 003;frankreich;Paris;Stadion3;1800;3444
Error, ...
> add-sports-venue 003;ecuador;Paris;Stadion4;1903;34344
OK
> add-sports-venue 003;spanien;Paris;Stadion3;1800;3444;
Error, ...
> add-sports-venue 02;spanien;Paris;Stadion 3;-1800;3444
Error, ...
> add-sports-venue 003;spanien;Paris;Stadion3;ef;3444
Error, ...
> add-sports-venue 003;spanien;Paris;Stadion3;1800;def;
Error, ...
> add-sports-venue 003;ecuador;Paris;Stadion4;1903;34344
Error, ...
> add-sports-venue 004;ecuador;Paris;Stadion4;903;34344
Error, ...
> list-sports-venues spanien
(1 020 Barcelona 1000)
(2 001 Madrid 100000)
(3 010 Madrid 100000)
\ No newline at end of file
......@@ -35,9 +35,11 @@ import static org.junit.jupiter.api.Assertions.fail;
* @since 23.01.2018
*/
public abstract class TestBase {
public static final String ERROR_PREFIX = "Error, ";
private String testName;
protected Logger log;
private List<LogRecord> logData = new ArrayList<>(100);
protected boolean testPassed = false;
private boolean alwaysShowLog;
private boolean showAllProgramOutput = false;
......@@ -104,6 +106,7 @@ public abstract class TestBase {
protected void initTest(TestInfo testInfo) {
alwaysShowLog = false;
isPerformanceTest = false;
testPassed = false;
testName = testInfo.getDisplayName();
log = Logger.getLogger(testInfo.getClass().getName());
log.setUseParentHandlers(false);
......@@ -130,16 +133,41 @@ public abstract class TestBase {
return testInfo.getDisplayName() + " @ " + testInfo.getTestClass().toString().substring(15).replace("]", "");
}
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;
}