Commit 5213d08d authored by uhflp's avatar uhflp Committed by uglke
Browse files

Add Progressbar for showing progress of big tests

parent 3e611918
...@@ -26,6 +26,13 @@ public final class Terminal { ...@@ -26,6 +26,13 @@ public final class Terminal {
public static boolean useMyErrorMessagesInTestCreation = true; public static boolean useMyErrorMessagesInTestCreation = true;
private static StringBuilder testPairFile = new StringBuilder(); private static StringBuilder testPairFile = new StringBuilder();
/**
* Progressbar stuff
*/
private static boolean showTestProgress = false;
private static int inputCount = 1;
private static int numInput = 0;
private static long time = 0;
/** /**
* This field represents the input from a test to a tested program * This field represents the input from a test to a tested program
*/ */
...@@ -148,6 +155,18 @@ public final class Terminal { ...@@ -148,6 +155,18 @@ public final class Terminal {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
else { else {
if (showTestProgress) {
numInput++;
if (numInput % (inputCount / 100) == 0) {
long t = System.nanoTime();
System.out.printf("%03d%% +%.2f ms%n", Math.round((double) numInput / inputCount * 100.0)
, (t - time) / 1000000.0);
time = t;
if (numInput == inputCount) {
System.out.println();
}
}
}
//If the program outputted nothing we still have null which means "no output" //If the program outputted nothing we still have null which means "no output"
OUT_TEST.add(null); OUT_TEST.add(null);
...@@ -239,4 +258,11 @@ public final class Terminal { ...@@ -239,4 +258,11 @@ public final class Terminal {
useMyErrorMessagesInTestCreation = !doNotUseMyErrorMessages; useMyErrorMessagesInTestCreation = !doNotUseMyErrorMessages;
startTestCreation(args); startTestCreation(args);
} }
public static void setupShowProgress(boolean showTestProgress, int inputCount) {
Terminal.showTestProgress = showTestProgress;
Terminal.inputCount = inputCount;
Terminal.numInput = 0;
time = System.nanoTime();
}
} }
...@@ -29,6 +29,7 @@ public class PerformanceTest extends Assignment2TestBase { ...@@ -29,6 +29,7 @@ public class PerformanceTest extends Assignment2TestBase {
@Test @Test
@DisplayName("PerformanceTest2") @DisplayName("PerformanceTest2")
void performanceTest2() { void performanceTest2() {
enableShowTestProgress();
String path = getDataFolderDirectory() + "performance/performance_test_2.io"; String path = getDataFolderDirectory() + "performance/performance_test_2.io";
TestPair[] pairs = loadTestPairsFromIOFile(path); TestPair[] pairs = loadTestPairsFromIOFile(path);
enablePerformanceTest(); enablePerformanceTest();
...@@ -39,6 +40,7 @@ public class PerformanceTest extends Assignment2TestBase { ...@@ -39,6 +40,7 @@ public class PerformanceTest extends Assignment2TestBase {
@Test @Test
@DisplayName("PerformanceTest3") @DisplayName("PerformanceTest3")
void performanceTest3() { void performanceTest3() {
enableShowTestProgress();
String path = getDataFolderDirectory() + "performance/performance_test_3.io"; String path = getDataFolderDirectory() + "performance/performance_test_3.io";
TestPair[] pairs = loadTestPairsFromIOFile(path); TestPair[] pairs = loadTestPairsFromIOFile(path);
enablePerformanceTest(); enablePerformanceTest();
......
...@@ -38,6 +38,7 @@ public abstract class TestBase { ...@@ -38,6 +38,7 @@ public abstract class TestBase {
private String testName; private String testName;
private boolean alwaysShowLog; private boolean alwaysShowLog;
private boolean showAllProgramOutput = false; private boolean showAllProgramOutput = false;
private boolean showTestProgress;
/** /**
* Initializes testing * Initializes testing
...@@ -57,6 +58,7 @@ public abstract class TestBase { ...@@ -57,6 +58,7 @@ public abstract class TestBase {
protected void initTest(TestInfo testInfo) { protected void initTest(TestInfo testInfo) {
alwaysShowLog = false; alwaysShowLog = false;
testPassed = false; testPassed = false;
showTestProgress = false;
testName = testInfo.getDisplayName(); testName = testInfo.getDisplayName();
log = Logger.getLogger(testInfo.getClass().getName()); log = Logger.getLogger(testInfo.getClass().getName());
log.setUseParentHandlers(false); log.setUseParentHandlers(false);
...@@ -199,6 +201,7 @@ public abstract class TestBase { ...@@ -199,6 +201,7 @@ public abstract class TestBase {
} }
pushProgramInput("quit"); pushProgramInput("quit");
Terminal.setupShowProgress(showTestProgress, Terminal.IN_TEST.size());
testedMethod.run(); testedMethod.run();
for (TestPair testPair : testPairs) { for (TestPair testPair : testPairs) {
...@@ -366,4 +369,11 @@ public abstract class TestBase { ...@@ -366,4 +369,11 @@ public abstract class TestBase {
protected void enableShowAllProgramOutput() { protected void enableShowAllProgramOutput() {
this.showAllProgramOutput = true; this.showAllProgramOutput = true;
} }
/**
* Shows a progress-bar for this test
*/
protected void enableShowTestProgress() {
showTestProgress = true;
}
} }
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