/
SimpleTester.java
59 lines (55 loc) · 1.44 KB
/
SimpleTester.java
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
import java.util.*;
import java.io.*;
class SimpleTester
{
public static void main(String[] tests)
{
int passed, failed;
System.out.println("Starting...");
passed = failed = 0;
for(String test : tests)
{
System.out.println();
System.out.print(test+".........");
String reference_output = GetFileText("tests" + File.separatorChar + test + "_reference.out");
String user_output = GetFileText("results" + File.separatorChar + test + "_user.out");
if ( (reference_output.length()>0) && (reference_output.equals(user_output)) )
{
System.out.print("OK");
passed++;
}
else
{
System.out.println("\n"+reference_output + "\nversus\n" + user_output+"\n");
System.out.println("FAILED");
failed++;
}
}
System.out.println("Passed " + passed + " of " + (passed+failed) + " tests.");
}
public static String GetFileText(String filename)
{
try
{
FileInputStream fis = new FileInputStream(filename);
int x = fis.available();
byte b[] = new byte[x];
fis.read(b);
String text = new String(b);
text = text.replaceAll(" ","");
text = text.replaceAll("\r","");
text = text.replaceAll("\n","");
return text;
}
catch(FileNotFoundException ex)
{
System.out.print("[FILENOTFOUND:"+filename+"]");
return new String();
}
catch(IOException ex)
{
System.out.print("[IO ERROR]");
return new String();
}
}
}