Commit b3377a9e authored by uhflp's avatar uhflp Committed by ungpk
Browse files

Daily release 02.03.2018

parent b9b380fe
......@@ -45,7 +45,7 @@ public final class Terminal {
/**
* this boolean determines whether the user already outputted something for that readLine call
*/
private static boolean concatOutput = false;
public static boolean concatOutput = true;
/**
* Private constructor to avoid object generation.
......@@ -157,7 +157,12 @@ public final class Terminal {
throw new RuntimeException(e);
}
else {
concatOutput = false;
if (!concatOutput) {
//The program outputted nothing. To support this in tests, we append 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"
......
......@@ -47,6 +47,7 @@ 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++) {
......@@ -59,12 +60,12 @@ public class Assignment1TestBase extends TestBase {
}
log.info("args[]: '" + strb.toString() + "'");
DummyMain.main(args);
String output = Terminal.OUT_TEST.poll();
if (acceptable) {
if (Terminal.OUT_TEST.poll() != null) {
if (output != null && !output.equals("")) {
failAndLog("test should have succeeded");
}
} else {
String output = Terminal.OUT_TEST.poll();
if (output == null || !output.startsWith("Error")) {
failAndLog("test should have failed");
}
......
package final_assignment.task_1.tests;
import final_assignment.task_1.Assignment1TestBase;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
......@@ -16,6 +15,7 @@ public class MassiveCornerCases extends Assignment1TestBase {
for (final File fileEntry : folder.listFiles()) {
log.info("\nFile: " + fileEntry.getPath());
testWithIOFile(fileEntry.getPath());
clearData();
}
}
}
......@@ -15,6 +15,7 @@ public class PerformanceTests extends Assignment1TestBase {
String args[] = {"torus", "20", "2"};
for (int i = 0; i < 20; i++) {
testUsingPairs(pairs, args);
clearData();
}
}
}
......@@ -3,62 +3,57 @@ package final_assignment.task_2;
import edu.kit.informatik.Terminal;
import test.TestPair;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.io.*;
import java.util.Random;
import java.util.Vector;
public class CaseCreator {
private static StringBuilder testPairfile;
private StringBuilder testPairFile;
private static final Random random = new Random();
private static long rgenseed = System.currentTimeMillis();
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 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();
CaseCreator caseCreator = new CaseCreator();
caseCreator.rgenseed = System.currentTimeMillis();
caseCreator.random.setSeed(caseCreator.rgenseed);
caseCreator.createTest();
}
}
private static void createTest() {
System.out.println("Creating input...");
testPairfile = new StringBuilder();
private void createTest() {
final RandomPicker randomPicker = new RandomPicker(random);
System.out.printf("Creating input for seed %d...%n", rgenseed);
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("add-admin vorname;nachname;tester;123123123", "OK"));
pairs.add(new TestPair("login-admin tester;123123123", "OK"));
Vector<String> ids = new Vector<>();
int idCounter = 0;
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);
String country = randomPicker.pickCountry();
do {
country = randomString("abcdefghijklmnobqrstuvwxyz", 3);
} while (countries.contains(country));
countries.add(country);
countries.add(country.split(" ", 2)[1].toLowerCase());
String id = new String();
do {
id = randomString("123456789", 3);
} while (ids.contains(id));
countries.add(country.split(" ", 2)[0].toLowerCase());
String id = String.format("%03d", ++idCounter);
ids.add(id);
pairs.add(new TestPair("add-ioc-code " + id + ";" + countries.elementAt(2 * i + 1) + ";"
......@@ -70,52 +65,64 @@ public class CaseCreator {
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);
sports.add(randomPicker.pickSport());
pairs.add(new TestPair("add-olympic-sport " + sports.elementAt(2 * i) + ";"
+ sports.elementAt(2 * i + 1), "OK"));
pairs.add(new TestPair("add-olympic-sport " + sports.elementAt(i) + ";"
+ sports.elementAt(i), "OK"));
}
Vector<Vector<String>> athletes = new Vector<>();
idCounter = 0;
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"));
String id = String.format("%04d", ++idCounter);
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"));
pairs.add(new TestPair("add-athlete "
+ id + ";" + randomPicker.pickName()
+ ";" + randomPicker.pickName() + ";" + country + ";"
+ sports.elementAt(s) + ";" + sports.elementAt(s), "OK"));
}
}
for (int s = 0; s < nSports; s++) {
for (int c = 0; c < nCompetitions; c++) {
for (int c = 0; c < nAthletes; c++) {
for (int y = 1926; y <= 2018; y += 4) {
int indexAthlete = 2 * c;
int medal = random.nextInt(3);
String medalString = "";
if (medal == 0) medalString = "0;1;0";
if (medal == 1) medalString = "1;0;0";
if (medal == 2) medalString = "0;0;1";
if (medal == 3) medalString = "0;0;0";
pairs.add(new TestPair("add-competition " + athletes.elementAt(s).elementAt(indexAthlete) + ";" + y + ";"
+ athletes.elementAt(s).elementAt(indexAthlete + 1) + ";"
+ sports.elementAt(s) + ";" + sports.elementAt(s) + ";" + medalString, "OK"));
}
}
}
for (int s = 0; s < nSports; s++) {
for (int f = 0; f < nErrors; f++) {
int indexAthlete = 2 * random.nextInt(nAthletes);
int medal = random.nextInt(3);
String medalString = new String();
String medalString = "";
if (medal == 0) medalString = "0;1;0";
if (medal == 1) medalString = "1;0;0";
if (medal == 2) medalString = "0;0;1";
if (medal == 3) medalString = "0;0;0";
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"));
+ sports.elementAt(s) + ";" + sports.elementAt(s) + ";" + medalString, "OK"));
}
}
......@@ -123,28 +130,38 @@ public class CaseCreator {
for (int s = 0; s < nSports; s++) {
pairs.add(new TestPair("summary-athletes " + sports.elementAt(2 * s + 1), ""));
pairs.add(new TestPair("summary-athletes " + sports.elementAt(s), ""));
}
pairs.add(new TestPair("olympic-medal-table", ""));
System.out.println("Creating output...");
ids.clear();
sports.clear();
countries.clear();
athletes.clear();
System.out.println(String.format("Creating output for %d pairs...", pairs.size()));
testUsingPairs(pairs.toArray(new TestPair[pairs.size()]), () -> DummyMain.main(null));
System.out.println("Saving...");
saveInputOutputPairs();
}
private static void testUsingPairs(TestPair[] testPairs, Runnable testedMethod) {
private void testUsingPairs(TestPair[] testPairs, Runnable testedMethod) {
for (TestPair testPair : testPairs) {
Terminal.IN_TEST.add(testPair.getInput());
}
Terminal.IN_TEST.add("quit");
long startTime = System.nanoTime();
testedMethod.run();
long endTime = System.nanoTime();
System.out.println(String.format("Program run in %f ms.", (endTime - startTime) / 1000000.0));
for (TestPair testPair : testPairs) {
testPairfile.append("> " + testPair.getInput() + "\n");
testPairFile.append("> ");
testPairFile.append(testPair.getInput());
testPairFile.append("\n");
String partOutput;
StringBuilder stringBuilder = new StringBuilder();
......@@ -161,26 +178,18 @@ public class CaseCreator {
}
String output = stringBuilder.toString();
testPairfile.append(output + "\n");
testPairFile.append(output);
testPairFile.append("\n");
}
}
public static void saveInputOutputPairs() {
public 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());
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;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
/**
* @author Alexander Sommer
* @since 01.03.2018
*/
public class RandomPicker {
private static final String COUNTRY_FILE = "src/final_assignment/task_2/sample_data/countries.txt";
private static final String NAME_FILE = "src/final_assignment/task_2/sample_data/names.txt";
private static final String SPORTS_FILE = "src/final_assignment/task_2/sample_data/sports.txt";
private final List<String> countries = new LinkedList<>();
private final List<String> names = new LinkedList<>();
private final List<String> sports = new LinkedList<>();
private final Random random;
public RandomPicker(Random random) {
this.random = random;
loadFileIntoList(COUNTRY_FILE, countries);
loadFileIntoList(NAME_FILE, names);
loadFileIntoList(SPORTS_FILE,sports);
}
private void loadFileIntoList(String file, List<String> list) {
assert Files.exists(Paths.get(file)) : "Missing File: " + file;
try {
BufferedReader reader = new BufferedReader(new FileReader(file));
String line;
while ((line = reader.readLine()) != null) {
if (line.startsWith("#"))
continue;
list.add(line);
}
} catch (IOException e) {
assert false : e.getMessage();
}
}
public String pickCountry() {
assert !countries.isEmpty() : "Not enough countries";
return countries.remove(random.nextInt(countries.size()));
}
public String pickName() {
return names.get(random.nextInt(names.size()));
}
public String pickSport() {
assert !sports.isEmpty() : "Not enough sports";
return sports.remove(random.nextInt(sports.size()));
}
}
# Taken from wikipedia and formatted
AFG Afghanistan
ALB Albania
ALG Algeria
AND Andorra
ANG Angola
ANT Antigua and Barbuda
ARG Argentina
ARM Armenia
ARU Aruba
ASA American Samoa
AUS Australia
AUT Austria
AZE Azerbaijan
BAH Bahamas
BAN Bangladesh
BAR Barbados
BDI Burundi
BEL Belgium
BEN Benin
BER Bermuda
BHU Bhutan
BIH Bosnia and Herzegovina
BIZ Belize
BLR Belarus
BOL Bolivia
BOT Botswana
BRA Brazil
BRN Bahrain
BRU Brunei
BUL Bulgaria
BUR Burkina Faso
CAF Central African Republic
CAM Cambodia
CAN Canada
CAY Cayman Islands
CGO Congo
CHA Chad
CHI Chile
CHN China
CIV Ivory Coast
CMR Cameroon
COD Democratic Republic of the Congo
COK Cook Islands
COL Colombia
COM Comoros
CPV Cape Verde
CRC Costa Rica
CRO Croatia
CUB Cuba
CYP Cyprus
CZE Czech Republic
DEN Denmark
DJI Djibouti
DMA Dominica
DOM Dominican Republic
ECU Ecuador
EGY Egypt
ERI Eritrea
ESA El Salvador
ESP Spain
EST Estonia
ETH Ethiopia
FIJ Fiji
FIN Finland
FRA France
FSM Federated States of Micronesia
GAB Gabon
GAM The Gambia
GBR Great Britain
GBS GuineaBissau
GEO Georgia
GEQ Equatorial Guinea
GER Germany
GHA Ghana
GRE Greece
GRN Grenada
GUA Guatemala
GUI Guinea
GUM Guam
GUY Guyana
HAI Haiti
HKG Hong Kong
HON Honduras
HUN Hungary
INA Indonesia
IND India
IRI Iran
IRL Ireland
IRQ Iraq
ISL Iceland
ISR Israel
ISV Virgin Islands
ITA Italy
IVB British Virgin Islands
JAM Jamaica
JOR Jordan
JPN Japan
KAZ Kazakhstan
KEN Kenya
KGZ Kyrgyzstan
KIR Kiribati
KOR South Korea
KOS Kosovo
KSA Saudi Arabia
KUW Kuwait
LAO Laos
LAT Latvia
LBA Libya
LBN Lebanon
LBR Liberia
LCA Saint Lucia
LES Lesotho
LIE Liechtenstein
LTU Lithuania
LUX Luxembourg
MAD Madagascar
MAR Morocco
MAS Malaysia
MAW Malawi
MDA Moldova
MDV Maldives
MEX Mexico
MGL Mongolia
MHL Marshall Islands
MKD Macedonia
MLI Mali
MLT Malta
MNE Montenegro
MON Monaco
MOZ Mozambique
MRI Mauritius
MTN Mauritania
MYA Myanmar
NAM Namibia
NCA Nicaragua
NED Netherlands
NEP Nepal
NGR Nigeria
NIG Niger
NOR Norway
NRU Nauru
NZL New Zealand
OMA Oman
PAK Pakistan
PAN Panama
PAR Paraguay
PER Peru
PHI Philippines
PLE Palestine
PLW Palau
PNG Papua New Guinea
POL Poland
POR Portugal
PRK North Korea
PUR Puerto Rico
QAT Qatar
ROU Romania
RSA South Africa
RUS Russia
RWA Rwanda
SAM Samoa
SEN Senegal
SEY Seychelles
SGP Singapore
SKN Saint Kitts and Nevis
SLE Sierra Leone
SLO Slovenia
SMR San Marino
SOL Solomon Islands
SOM Somalia
SRB Serbia
SRI Sri Lanka
SSD South Sudan
STP São Tomé and Príncipe
SUD Sudan
SUI Switzerland
SUR Suriname
SVK Slovakia
SWE Sweden
SWZ Swaziland
SYR Syria
TAN Tanzania
TGA Tonga
THA Thailand
TJK Tajikistan
TKM Turkmenistan
TLS East Timor
TOG Togo
TPE Chinese Taipei
TTO Trinidad and Tobago
TUN Tunisia
TUR Turkey
TUV Tuvalu
UAE United Arab Emirates
UGA Uganda
UKR Ukraine
URU Uruguay
USA United States
UZB Uzbekistan
VAN Vanuatu
VEN Venezuela
VIE Vietnam
VIN Saint Vincent and the Grenadines
YEM Yemen
ZAM Zambia
ZIM Zimbabwe
\ No newline at end of file
This diff is collapsed.
acrobatics
aerobics
aikido
archery
arts and crafts
auto cross