-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTestJudgeEngine.java
More file actions
87 lines (78 loc) · 3.72 KB
/
Copy pathTestJudgeEngine.java
File metadata and controls
87 lines (78 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import engine.CompileRunner;
import engine.TestCaseRunner;
import exception.CompilationException;
import exception.RuntimeErrorException;
import exception.TimeLimitExceededException;
import java.io.File;
/**
* Quick smoke-test for CompileRunner + TestCaseRunner.
*
* Run from the OODP_Mini_Project root with:
* javac -cp src -d out src/engine/CompileRunner.java src/engine/TestCaseRunner.java
* src/exception/CompilationException.java
* src/exception/TimeLimitExceededException.java
* src/exception/RuntimeErrorException.java
* javac -cp src;out -d out TestJudgeEngine.java
* java -cp out TestJudgeEngine
*/
public class TestJudgeEngine {
/** A correct Java solution for "Sum of Two Numbers" embedded as a String. */
private static final String SUM_SOLUTION =
"import java.util.Scanner;\n" +
"public class SumSolution {\n" +
" public static void main(String[] args) {\n" +
" Scanner sc = new Scanner(System.in);\n" +
" int a = sc.nextInt();\n" +
" int b = sc.nextInt();\n" +
" System.out.println(a + b);\n" +
" }\n" +
"}\n";
public static void main(String[] args) {
System.out.println("=================================================");
System.out.println(" AlgoJudge — CompileRunner + TestCaseRunner test");
System.out.println("=================================================\n");
String workDir = "tmp_test" + File.separator + "S_TEST" + File.separator;
new File(workDir).mkdirs();
// ── STEP 1: Compile ──────────────────────────────────────────────────
System.out.println("[TEST] Compiling SumSolution...");
String className = null;
try {
className = CompileRunner.compile(SUM_SOLUTION, "S_TEST", workDir);
System.out.println("[TEST] Compilation OK. Class name: " + className);
} catch (CompilationException e) {
System.err.println("[TEST] FAILED — CompilationException:");
System.err.println(e.getCompilerOutput());
System.exit(1);
}
// ── STEP 2: Run against test cases ───────────────────────────────────
String[][] cases = {
{"3 5", "8"},
{"0 0", "0"},
{"-1 1", "0"},
{"100 200","300"}
};
int passed = 0;
for (int i = 0; i < cases.length; i++) {
String input = cases[i][0];
String expected = cases[i][1];
System.out.printf("[TEST] TC%d input='%s' expected='%s' ",
i + 1, input, expected);
try {
String actual = TestCaseRunner.run(className, workDir, input, 2000);
String trimActual = actual == null ? "" : actual.trim();
if (trimActual.equals(expected)) {
System.out.println("→ AC ✓");
passed++;
} else {
System.out.println("→ WA (got: '" + trimActual + "')");
}
} catch (TimeLimitExceededException e) {
System.out.println("→ TLE " + e.getMessage());
} catch (RuntimeErrorException e) {
System.out.println("→ RE " + e.getErrorOutput());
}
}
System.out.println("\n[TEST] Result: " + passed + "/" + cases.length + " passed.");
System.out.println(passed == cases.length ? "[TEST] ALL PASSED ✓" : "[TEST] SOME FAILED ✗");
}
}