Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/zjhzxhz/voj
Browse files Browse the repository at this point in the history
  • Loading branch information
Haozhe Xie committed Apr 9, 2016
2 parents 0047c7d + af7affd commit 0db028b
Show file tree
Hide file tree
Showing 43 changed files with 3,360 additions and 2,872 deletions.
210 changes: 105 additions & 105 deletions judger/src/test/java/org/verwandlung/voj/judger/core/ComparatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,115 +25,115 @@
@Transactional
@ContextConfiguration({ "classpath:test-spring-context.xml" })
public class ComparatorTest {
/**
* 构建测试用例.
*/
@BeforeClass
public static void setUp() throws IOException {
FileOutputStream stdOutputStream = null;
FileOutputStream outputStream = null;
// Make Directory for TestCases
File checkpointsDirFile = new File("/tmp/voj-matcher-tests");
if (!checkpointsDirFile.exists()) {
checkpointsDirFile.mkdirs();
}
// TestCase: MatchExactly
stdOutputStream = new FileOutputStream(new File(
"/tmp/voj-matcher-tests/match-exactly-std.txt"));
outputStream = new FileOutputStream(new File(
"/tmp/voj-matcher-tests/match-exactly.txt"));
String matchExactlyString = "32768";
IOUtils.write(matchExactlyString, stdOutputStream);
IOUtils.write(matchExactlyString, outputStream);
// TestCase: MatchWithSpaces
stdOutputStream = new FileOutputStream(new File(
"/tmp/voj-matcher-tests/match-with-spaces-std.txt"));
outputStream = new FileOutputStream(new File(
"/tmp/voj-matcher-tests/match-with-spaces.txt"));
String matchWithSpacesString = "Output Test with Spaces";
IOUtils.write(matchWithSpacesString, stdOutputStream);
IOUtils.write(matchWithSpacesString + " \n \n", outputStream);
// TestCase: Mismatch
stdOutputStream = new FileOutputStream(new File(
"/tmp/voj-matcher-tests/mimatch-std.txt"));
outputStream = new FileOutputStream(new File(
"/tmp/voj-matcher-tests/mimatch.txt"));
String mismatchString1 = "45652 \n\n";
String mismatchString2 = "24334";
IOUtils.write(mismatchString1, stdOutputStream);
IOUtils.write(mismatchString2, outputStream);
// TestCase: OutOfMemoryException
File outOfMemoryOutFile = new File(
"/tmp/voj-matcher-tests/match-out-of-memory.txt");
String outOfMemoryString = "A line of output causes out of memory exception. ";
for ( int i = 0; i < 10000000; ++ i ) {
FileUtils.writeStringToFile(outOfMemoryOutFile, outOfMemoryString, true);
}
}
/**
* 构建测试用例.
*/
@BeforeClass
public static void setUp() throws IOException {
FileOutputStream stdOutputStream = null;
FileOutputStream outputStream = null;
// Make Directory for TestCases
File checkpointsDirFile = new File("/tmp/voj-matcher-tests");
if (!checkpointsDirFile.exists()) {
checkpointsDirFile.mkdirs();
}
// TestCase: MatchExactly
stdOutputStream = new FileOutputStream(new File(
"/tmp/voj-matcher-tests/match-exactly-std.txt"));
outputStream = new FileOutputStream(new File(
"/tmp/voj-matcher-tests/match-exactly.txt"));
String matchExactlyString = "32768";
IOUtils.write(matchExactlyString, stdOutputStream);
IOUtils.write(matchExactlyString, outputStream);
// TestCase: MatchWithSpaces
stdOutputStream = new FileOutputStream(new File(
"/tmp/voj-matcher-tests/match-with-spaces-std.txt"));
outputStream = new FileOutputStream(new File(
"/tmp/voj-matcher-tests/match-with-spaces.txt"));
String matchWithSpacesString = "Output Test with Spaces";
IOUtils.write(matchWithSpacesString, stdOutputStream);
IOUtils.write(matchWithSpacesString + " \n \n", outputStream);
// TestCase: Mismatch
stdOutputStream = new FileOutputStream(new File(
"/tmp/voj-matcher-tests/mimatch-std.txt"));
outputStream = new FileOutputStream(new File(
"/tmp/voj-matcher-tests/mimatch.txt"));
String mismatchString1 = "45652 \n\n";
String mismatchString2 = "24334";
IOUtils.write(mismatchString1, stdOutputStream);
IOUtils.write(mismatchString2, outputStream);
// TestCase: OutOfMemoryException
File outOfMemoryOutFile = new File(
"/tmp/voj-matcher-tests/match-out-of-memory.txt");
String outOfMemoryString = "A line of output causes out of memory exception. ";
for ( int i = 0; i < 10000000; ++ i ) {
FileUtils.writeStringToFile(outOfMemoryOutFile, outOfMemoryString, true);
}
}

/**
* 清除测试用例.
*/
@AfterClass
public static void tearDown() {
File checkpointsDirFile = new File("/tmp/voj-matcher-tests");
if (checkpointsDirFile.exists()) {
checkpointsDirFile.delete();
}
}
/**
* 清除测试用例.
*/
@AfterClass
public static void tearDown() {
File checkpointsDirFile = new File("/tmp/voj-matcher-tests");
if (checkpointsDirFile.exists()) {
checkpointsDirFile.delete();
}
}

/**
* 测试用例: 测试isOutputTheSame(String, String)方法
* 测试数据: 输入和输出完全相同
* 测试结果: 返回true, 表示输出结果正确
*/
@Test
public void testMatchExactly() throws IOException {
String standardOutputFilePath = "/tmp/voj-matcher-tests/match-exactly-std.txt";
String outputFilePath = "/tmp/voj-matcher-tests/match-exactly.txt";
Assert.assertTrue(comparator.isOutputTheSame(standardOutputFilePath, outputFilePath));
}
/**
* 测试用例: 测试isOutputTheSame(String, String)方法
* 测试数据: 输入和输出完全相同
* 测试结果: 返回true, 表示输出结果正确
*/
@Test
public void testMatchExactly() throws IOException {
String standardOutputFilePath = "/tmp/voj-matcher-tests/match-exactly-std.txt";
String outputFilePath = "/tmp/voj-matcher-tests/match-exactly.txt";
Assert.assertTrue(comparator.isOutputTheSame(standardOutputFilePath, outputFilePath));
}

/**
* 测试用例: 测试isOutputTheSame(String, String)方法
* 测试数据: 输入和输出基本相同, 在行尾存在多余的空白字符
* 测试结果: 返回true, 表示输出结果正确
*/
@Test
public void testMatchWithSpaces() throws IOException {
String standardOutputFilePath = "/tmp/voj-matcher-tests/match-with-spaces-std.txt";
String outputFilePath = "/tmp/voj-matcher-tests/match-with-spaces.txt";
Assert.assertTrue(comparator.isOutputTheSame(standardOutputFilePath,
outputFilePath));
Assert.assertTrue(comparator.isOutputTheSame(outputFilePath, standardOutputFilePath));
}
/**
* 测试用例: 测试isOutputTheSame(String, String)方法
* 测试数据: 输入和输出基本相同, 在行尾存在多余的空白字符
* 测试结果: 返回true, 表示输出结果正确
*/
@Test
public void testMatchWithSpaces() throws IOException {
String standardOutputFilePath = "/tmp/voj-matcher-tests/match-with-spaces-std.txt";
String outputFilePath = "/tmp/voj-matcher-tests/match-with-spaces.txt";
Assert.assertTrue(comparator.isOutputTheSame(standardOutputFilePath,
outputFilePath));
Assert.assertTrue(comparator.isOutputTheSame(outputFilePath, standardOutputFilePath));
}

/**
* 测试用例: 测试isOutputTheSame(String, String)方法
* 测试数据: 输入和输出不完全相同
* 测试结果: 返回false, 表示输出结果不正确
*/
@Test
public void testMismatch() throws IOException {
String standardOutputFilePath = "/tmp/voj-matcher-tests/mimatch-std.txt";
String outputFilePath = "/tmp/voj-matcher-tests/mimatch.txt";
Assert.assertFalse(comparator.isOutputTheSame(standardOutputFilePath, outputFilePath));
}
/**
* 测试用例: 测试isOutputTheSame(String, String)方法
* 测试数据: 输入和输出不完全相同
* 测试结果: 返回false, 表示输出结果不正确
*/
@Test
public void testMismatch() throws IOException {
String standardOutputFilePath = "/tmp/voj-matcher-tests/mimatch-std.txt";
String outputFilePath = "/tmp/voj-matcher-tests/mimatch.txt";
Assert.assertFalse(comparator.isOutputTheSame(standardOutputFilePath, outputFilePath));
}

/**
* 测试用例: 测试isOutputTheSame(String, String)方法
* 测试数据: 过长的输出文件流
* 测试结果: 返回false, 表示输出结果不正确
*/
@Test
public void testMatchWithOutOfMemory() throws IOException {
String outputFilePath = "/tmp/voj-matcher-tests/match-out-of-memory.txt";
Assert.assertFalse(comparator.isOutputTheSame(outputFilePath, outputFilePath));
}
/**
* 测试用例: 测试isOutputTheSame(String, String)方法
* 测试数据: 过长的输出文件流
* 测试结果: 返回false, 表示输出结果不正确
*/
@Test
public void testMatchWithOutOfMemory() throws IOException {
String outputFilePath = "/tmp/voj-matcher-tests/match-out-of-memory.txt";
Assert.assertFalse(comparator.isOutputTheSame(outputFilePath, outputFilePath));
}

/**
* 待测试的Matcher对象.
*/
@Autowired
private Comparator comparator;
/**
* 待测试的Matcher对象.
*/
@Autowired
private Comparator comparator;
}
148 changes: 74 additions & 74 deletions judger/src/test/java/org/verwandlung/voj/judger/core/CompilerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,78 +23,78 @@
@Transactional
@ContextConfiguration({"classpath:test-spring-context.xml"})
public class CompilerTest {
/**
* 测试用例: 测试getCompileResult()方法
* 测试数据: 使用可以编译通过的C++代码
* 预期结果: 编译通过
*/
@Test
public void testGetCompileResultCppWithSuccess() throws Exception {
String workDirectory = workBaseDirectory + "/voj-1000";
String baseFileName = "random-name";
Submission submission = submissionMapper.getSubmission(1000);
preprocessor.createTestCode(submission, workDirectory, baseFileName);
Map<String, Object> result = compiler.getCompileResult(submission, workDirectory, baseFileName);
Assert.assertEquals(true, result.get("isSuccessful"));
}
/**
* 测试用例: 测试getCompileResult()方法
* 测试数据: 使用可以编译通过的Java代码
* 预期结果: 编译通过
*/
@Test
public void testGetCompileResultJavaWithSuccess() throws Exception {
String workDirectory = workBaseDirectory + "/voj-1001";
String baseFileName = "RandomName";
Submission submission = submissionMapper.getSubmission(1001);
preprocessor.createTestCode(submission, workDirectory, baseFileName);
Map<String, Object> result = compiler.getCompileResult(submission, workDirectory, baseFileName);
Assert.assertEquals(true, result.get("isSuccessful"));
}
/**
* 测试用例: 测试getCompileResult()方法
* 测试数据: 使用可以无法编译通过的C++代码
* 预期结果: 编译失败
*/
@Test
public void testGetCompileResultCppWithError() throws Exception {
String workDirectory = workBaseDirectory + "/voj-1002";
String baseFileName = "random-name";
Submission submission = submissionMapper.getSubmission(1002);
preprocessor.createTestCode(submission, workDirectory, baseFileName);
Map<String, Object> result = compiler.getCompileResult(submission, workDirectory, baseFileName);
Assert.assertEquals(false, result.get("isSuccessful"));
}
/**
* 待测试的Compiler对象.
*/
@Autowired
private Compiler compiler;
/**
* 自动注入的Preprocessor对象.
* 用于构建测试用例.
*/
@Autowired
private Preprocessor preprocessor;
/**
* 自动注入的SubmissionMapper对象.
* 用于构建测试用例.
*/
@Autowired
private SubmissionMapper submissionMapper;
/**
* 评测机的工作目录.
* 用于存储编译结果以及程序输出结果.
*/
@Value("${judger.workDir}")
private String workBaseDirectory;
/**
* 测试用例: 测试getCompileResult()方法
* 测试数据: 使用可以编译通过的C++代码
* 预期结果: 编译通过
*/
@Test
public void testGetCompileResultCppWithSuccess() throws Exception {
String workDirectory = workBaseDirectory + "/voj-1000";
String baseFileName = "random-name";
Submission submission = submissionMapper.getSubmission(1000);
preprocessor.createTestCode(submission, workDirectory, baseFileName);
Map<String, Object> result = compiler.getCompileResult(submission, workDirectory, baseFileName);
Assert.assertEquals(true, result.get("isSuccessful"));
}
/**
* 测试用例: 测试getCompileResult()方法
* 测试数据: 使用可以编译通过的Java代码
* 预期结果: 编译通过
*/
@Test
public void testGetCompileResultJavaWithSuccess() throws Exception {
String workDirectory = workBaseDirectory + "/voj-1001";
String baseFileName = "RandomName";
Submission submission = submissionMapper.getSubmission(1001);
preprocessor.createTestCode(submission, workDirectory, baseFileName);
Map<String, Object> result = compiler.getCompileResult(submission, workDirectory, baseFileName);
Assert.assertEquals(true, result.get("isSuccessful"));
}
/**
* 测试用例: 测试getCompileResult()方法
* 测试数据: 使用可以无法编译通过的C++代码
* 预期结果: 编译失败
*/
@Test
public void testGetCompileResultCppWithError() throws Exception {
String workDirectory = workBaseDirectory + "/voj-1002";
String baseFileName = "random-name";
Submission submission = submissionMapper.getSubmission(1002);
preprocessor.createTestCode(submission, workDirectory, baseFileName);
Map<String, Object> result = compiler.getCompileResult(submission, workDirectory, baseFileName);
Assert.assertEquals(false, result.get("isSuccessful"));
}
/**
* 待测试的Compiler对象.
*/
@Autowired
private Compiler compiler;
/**
* 自动注入的Preprocessor对象.
* 用于构建测试用例.
*/
@Autowired
private Preprocessor preprocessor;
/**
* 自动注入的SubmissionMapper对象.
* 用于构建测试用例.
*/
@Autowired
private SubmissionMapper submissionMapper;
/**
* 评测机的工作目录.
* 用于存储编译结果以及程序输出结果.
*/
@Value("${judger.workDir}")
private String workBaseDirectory;
}
Loading

0 comments on commit 0db028b

Please sign in to comment.