From d2a47944e9501edfe3029bbca28abe56a09b1781 Mon Sep 17 00:00:00 2001 From: Haozhe Xie Date: Sat, 2 Apr 2016 10:11:13 +0800 Subject: [PATCH 1/4] Complete get relationshops of categories and tags of problems in mappers. --- .../voj/judger/core/ComparatorTest.java | 210 ++-- .../voj/judger/core/CompilerTest.java | 148 +-- .../voj/judger/core/PreprocessorTest.java | 100 +- .../voj/judger/core/RunnerTest.java | 154 +-- .../judger/mapper/CheckpointMapperTest.java | 62 +- .../judger/mapper/JudgeResultMapperTest.java | 60 +- .../voj/judger/mapper/LanguageMapperTest.java | 142 +-- .../voj/judger/mapper/ProblemMapperTest.java | 60 +- .../judger/mapper/SubmissionMapperTest.java | 60 +- .../judger/mapper/UserGroupMapperTest.java | 60 +- .../voj/judger/mapper/UserMapperTest.java | 60 +- voj.sql | 6 +- .../voj/web/mapper/ProblemCategoryMapper.java | 6 +- .../voj/web/mapper/ProblemTagMapper.java | 16 +- .../model/ProblemCategoryRelationship.java | 146 +++ .../voj/web/model/ProblemTagRelationship.java | 146 +++ .../voj/web/service/ProblemService.java | 2 +- .../mappers/ProblemCategoryMapper.xml | 9 +- .../resources/mappers/ProblemTagMapper.xml | 19 +- .../voj/web/mapper/CheckpointMapperTest.java | 158 +-- .../web/mapper/EmailValidationMapperTest.java | 170 +-- .../voj/web/mapper/JudgeResultMapperTest.java | 110 +- .../voj/web/mapper/LanguageMapperTest.java | 304 ++--- .../voj/web/mapper/OptionMapperTest.java | 152 +-- .../web/mapper/ProblemCategoryMapperTest.java | 488 ++++---- .../voj/web/mapper/ProblemMapperTest.java | 452 +++---- .../voj/web/mapper/ProblemTagMapperTest.java | 383 +++--- .../voj/web/mapper/SubmissionMapperTest.java | 1042 ++++++++--------- .../voj/web/mapper/UserGroupMapperTest.java | 110 +- .../voj/web/mapper/UserMapperTest.java | 496 ++++---- .../voj/web/mapper/UserMetaMapperTest.java | 406 +++---- .../voj/web/util/DigestUtilsTest.java | 82 +- .../voj/web/util/HtmlTextFilterTest.java | 42 +- .../voj/web/util/MessageReceiverTest.java | 20 +- .../voj/web/util/MessageSenderTest.java | 34 +- .../voj/web/util/OffensiveWordFilterTest.java | 32 +- .../voj/web/util/SlugifyUtilsTest.java | 38 +- .../test/resources/test-spring-context.xml | 2 +- 38 files changed, 3207 insertions(+), 2780 deletions(-) create mode 100644 web/src/main/java/org/verwandlung/voj/web/model/ProblemCategoryRelationship.java create mode 100644 web/src/main/java/org/verwandlung/voj/web/model/ProblemTagRelationship.java diff --git a/judger/src/test/java/org/verwandlung/voj/judger/core/ComparatorTest.java b/judger/src/test/java/org/verwandlung/voj/judger/core/ComparatorTest.java index c6c35b2a..6d019a60 100644 --- a/judger/src/test/java/org/verwandlung/voj/judger/core/ComparatorTest.java +++ b/judger/src/test/java/org/verwandlung/voj/judger/core/ComparatorTest.java @@ -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; } diff --git a/judger/src/test/java/org/verwandlung/voj/judger/core/CompilerTest.java b/judger/src/test/java/org/verwandlung/voj/judger/core/CompilerTest.java index 8bc63b01..694a759f 100644 --- a/judger/src/test/java/org/verwandlung/voj/judger/core/CompilerTest.java +++ b/judger/src/test/java/org/verwandlung/voj/judger/core/CompilerTest.java @@ -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 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 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 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 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 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 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; } diff --git a/judger/src/test/java/org/verwandlung/voj/judger/core/PreprocessorTest.java b/judger/src/test/java/org/verwandlung/voj/judger/core/PreprocessorTest.java index d2d44f26..cb2fe0a6 100644 --- a/judger/src/test/java/org/verwandlung/voj/judger/core/PreprocessorTest.java +++ b/judger/src/test/java/org/verwandlung/voj/judger/core/PreprocessorTest.java @@ -23,54 +23,54 @@ @Transactional @ContextConfiguration({"classpath:test-spring-context.xml"}) public class PreprocessorTest { - /** - * 测试用例: 测试createTestCode(Submission, String, String)方法 - * 测试数据: 使用存在的提交记录(Submission#1000) - * 预期结果: 在指定位置创建源代码文件 - * @throws Exception - */ - @Test - public void testCreateTestCodeCpp() throws Exception { - Submission submission = submissionMapper.getSubmission(1000); - String workDirectory = "/tmp/voj-1000/"; - String baseFileName = "random-name"; - - preprocessor.createTestCode(submission, workDirectory, baseFileName); - FileInputStream inputStream = new FileInputStream("/tmp/voj-1000/random-name.cpp"); - String code = IOUtils.toString(inputStream); - inputStream.close(); - Assert.assertEquals(submission.getCode(), code); - } - - /** - * 测试用例: 测试createTestCode(Submission, String, String)方法 - * 测试数据: 使用存在的提交记录(Submission#1001) - * 预期结果: 在指定位置创建源代码文件 - * @throws Exception - */ - @Test - public void testCreateTestCodeJava() throws Exception { - Submission submission = submissionMapper.getSubmission(1001); - String workDirectory = "/tmp/voj-1001/"; - String baseFileName = "RandomName"; - - preprocessor.createTestCode(submission, workDirectory, baseFileName); - FileInputStream inputStream = new FileInputStream("/tmp/voj-1001/RandomName.java"); - String code = IOUtils.toString(inputStream).replace("RandomName", "Main"); - inputStream.close(); - Assert.assertEquals(submission.getCode(), code); - } - - /** - * 待测试的Preprocessor对象. - */ - @Autowired - private Preprocessor preprocessor; - - /** - * 自动注入的SubmissionMapper对象. - * 用于构造测试用例. - */ - @Autowired - private SubmissionMapper submissionMapper; + /** + * 测试用例: 测试createTestCode(Submission, String, String)方法 + * 测试数据: 使用存在的提交记录(Submission#1000) + * 预期结果: 在指定位置创建源代码文件 + * @throws Exception + */ + @Test + public void testCreateTestCodeCpp() throws Exception { + Submission submission = submissionMapper.getSubmission(1000); + String workDirectory = "/tmp/voj-1000/"; + String baseFileName = "random-name"; + + preprocessor.createTestCode(submission, workDirectory, baseFileName); + FileInputStream inputStream = new FileInputStream("/tmp/voj-1000/random-name.cpp"); + String code = IOUtils.toString(inputStream); + inputStream.close(); + Assert.assertEquals(submission.getCode(), code); + } + + /** + * 测试用例: 测试createTestCode(Submission, String, String)方法 + * 测试数据: 使用存在的提交记录(Submission#1001) + * 预期结果: 在指定位置创建源代码文件 + * @throws Exception + */ + @Test + public void testCreateTestCodeJava() throws Exception { + Submission submission = submissionMapper.getSubmission(1001); + String workDirectory = "/tmp/voj-1001/"; + String baseFileName = "RandomName"; + + preprocessor.createTestCode(submission, workDirectory, baseFileName); + FileInputStream inputStream = new FileInputStream("/tmp/voj-1001/RandomName.java"); + String code = IOUtils.toString(inputStream).replace("RandomName", "Main"); + inputStream.close(); + Assert.assertEquals(submission.getCode(), code); + } + + /** + * 待测试的Preprocessor对象. + */ + @Autowired + private Preprocessor preprocessor; + + /** + * 自动注入的SubmissionMapper对象. + * 用于构造测试用例. + */ + @Autowired + private SubmissionMapper submissionMapper; } diff --git a/judger/src/test/java/org/verwandlung/voj/judger/core/RunnerTest.java b/judger/src/test/java/org/verwandlung/voj/judger/core/RunnerTest.java index 3cc7fc93..b6fb13b1 100644 --- a/judger/src/test/java/org/verwandlung/voj/judger/core/RunnerTest.java +++ b/judger/src/test/java/org/verwandlung/voj/judger/core/RunnerTest.java @@ -23,83 +23,83 @@ @Transactional @ContextConfiguration({"classpath:test-spring-context.xml"}) public class RunnerTest { - /** - * 测试用例: 测试getRuntimeResult(Submission, int, String, String, String, String)方法 - * 测试数据: 使用可以编译通过的C++代码 - * 预期结果: 编译成功并运行产生输出 - */ - @Test - public void testGetRuntimeResultCpp() throws Exception { - String workDirectory = workBaseDirectory + "/voj-1000"; - String baseFileName = "random-name"; - Submission submission = submissionMapper.getSubmission(1000); + /** + * 测试用例: 测试getRuntimeResult(Submission, int, String, String, String, String)方法 + * 测试数据: 使用可以编译通过的C++代码 + * 预期结果: 编译成功并运行产生输出 + */ + @Test + public void testGetRuntimeResultCpp() throws Exception { + String workDirectory = workBaseDirectory + "/voj-1000"; + String baseFileName = "random-name"; + Submission submission = submissionMapper.getSubmission(1000); - String inputFilePath = workBaseDirectory + "/testpoints/1000/input#0.txt"; - String outputFilePath = workBaseDirectory + "/voj-1000/output#0.txt"; - - preprocessor.createTestCode(submission, workDirectory, baseFileName); - preprocessor.fetchTestPoints(submission.getProblem().getProblemId()); - compiler.getCompileResult(submission, workDirectory, baseFileName); - - Map result = - runner.getRuntimeResult(submission, workDirectory, baseFileName, inputFilePath, outputFilePath); - Assert.assertEquals("AC", result.get("runtimeResult")); - } - - /** - * 测试用例: 测试getRuntimeResult(Submission, int, String, String, String, String)方法 - * 测试数据: 使用可以编译通过的Java代码 - * 预期结果: 编译成功并运行产生输出 - */ - @Test - public void testGetRuntimeResultJava() throws Exception { - String workDirectory = workBaseDirectory + "/voj-1001"; - String baseFileName = "RandomName"; - Submission submission = submissionMapper.getSubmission(1001); + String inputFilePath = workBaseDirectory + "/testpoints/1000/input#0.txt"; + String outputFilePath = workBaseDirectory + "/voj-1000/output#0.txt"; + + preprocessor.createTestCode(submission, workDirectory, baseFileName); + preprocessor.fetchTestPoints(submission.getProblem().getProblemId()); + compiler.getCompileResult(submission, workDirectory, baseFileName); + + Map result = + runner.getRuntimeResult(submission, workDirectory, baseFileName, inputFilePath, outputFilePath); + Assert.assertEquals("AC", result.get("runtimeResult")); + } + + /** + * 测试用例: 测试getRuntimeResult(Submission, int, String, String, String, String)方法 + * 测试数据: 使用可以编译通过的Java代码 + * 预期结果: 编译成功并运行产生输出 + */ + @Test + public void testGetRuntimeResultJava() throws Exception { + String workDirectory = workBaseDirectory + "/voj-1001"; + String baseFileName = "RandomName"; + Submission submission = submissionMapper.getSubmission(1001); - String inputFilePath = workBaseDirectory + "/testpoints/1001/input#0.txt"; - String outputFilePath = workBaseDirectory + "/voj-1000/output#0.txt"; - - preprocessor.createTestCode(submission, workDirectory, baseFileName); - preprocessor.fetchTestPoints(submission.getProblem().getProblemId()); - compiler.getCompileResult(submission, workDirectory, baseFileName); - - Map result = - runner.getRuntimeResult(submission, workDirectory, baseFileName, inputFilePath, outputFilePath); - Assert.assertEquals("AC", result.get("runtimeResult")); - } - - /** - * 待测试的Runner对象. - */ - @Autowired - private Runner runner; - - /** - * 自动注入的Compiler对象. - * 用于构建测试用例. - */ - @Autowired - private Compiler compiler; - - /** - * 自动注入的Preprocessor对象. - * 用于构建测试用例. - */ - @Autowired - private Preprocessor preprocessor; - - /** - * 自动注入的SubmissionMapper对象. - * 用于构建测试用例. - */ - @Autowired - private SubmissionMapper submissionMapper; - - /** - * 评测机的工作目录. - * 用于存储编译结果以及程序输出结果. - */ - @Value("${judger.workDir}") - private String workBaseDirectory; + String inputFilePath = workBaseDirectory + "/testpoints/1001/input#0.txt"; + String outputFilePath = workBaseDirectory + "/voj-1000/output#0.txt"; + + preprocessor.createTestCode(submission, workDirectory, baseFileName); + preprocessor.fetchTestPoints(submission.getProblem().getProblemId()); + compiler.getCompileResult(submission, workDirectory, baseFileName); + + Map result = + runner.getRuntimeResult(submission, workDirectory, baseFileName, inputFilePath, outputFilePath); + Assert.assertEquals("AC", result.get("runtimeResult")); + } + + /** + * 待测试的Runner对象. + */ + @Autowired + private Runner runner; + + /** + * 自动注入的Compiler对象. + * 用于构建测试用例. + */ + @Autowired + private Compiler compiler; + + /** + * 自动注入的Preprocessor对象. + * 用于构建测试用例. + */ + @Autowired + private Preprocessor preprocessor; + + /** + * 自动注入的SubmissionMapper对象. + * 用于构建测试用例. + */ + @Autowired + private SubmissionMapper submissionMapper; + + /** + * 评测机的工作目录. + * 用于存储编译结果以及程序输出结果. + */ + @Value("${judger.workDir}") + private String workBaseDirectory; } diff --git a/judger/src/test/java/org/verwandlung/voj/judger/mapper/CheckpointMapperTest.java b/judger/src/test/java/org/verwandlung/voj/judger/mapper/CheckpointMapperTest.java index 10ab901d..b43649f3 100644 --- a/judger/src/test/java/org/verwandlung/voj/judger/mapper/CheckpointMapperTest.java +++ b/judger/src/test/java/org/verwandlung/voj/judger/mapper/CheckpointMapperTest.java @@ -21,35 +21,35 @@ @Transactional @ContextConfiguration({"classpath:test-spring-context.xml"}) public class CheckpointMapperTest { - /** - * 测试用例: 测试getCheckpointsUsingProblemId(long)方法 - * 测试数据: 使用存在的试题唯一标识符(1000) - * 预期结果: 返回对应的测试点列表(10个项目) - */ - @Test - public void testGetCheckpointsUsingProblemIdExists() { - List checkpoints = checkpointMapper.getCheckpointsUsingProblemId(1000); - Assert.assertEquals(10, checkpoints.size()); - - Checkpoint firstCheckpoint = checkpoints.get(0); - String output = firstCheckpoint.getOutput(); - Assert.assertEquals("45652\r\n", output); - } - - /** - * 测试用例: 测试getCheckpointsUsingProblemId(long)方法 - * 测试数据: 使用不存在的试题唯一标识符(0) - * 预期结果: 返回对应的测试点列表(0个项目) - */ - @Test - public void testGetCheckpointsUsingProblemIdNotExists() { - List checkpoints = checkpointMapper.getCheckpointsUsingProblemId(0); - Assert.assertEquals(0, checkpoints.size()); - } - - /** - * 待测试的CheckpointMapper对象. - */ - @Autowired - private CheckpointMapper checkpointMapper; + /** + * 测试用例: 测试getCheckpointsUsingProblemId(long)方法 + * 测试数据: 使用存在的试题唯一标识符(1000) + * 预期结果: 返回对应的测试点列表(10个项目) + */ + @Test + public void testGetCheckpointsUsingProblemIdExists() { + List checkpoints = checkpointMapper.getCheckpointsUsingProblemId(1000); + Assert.assertEquals(10, checkpoints.size()); + + Checkpoint firstCheckpoint = checkpoints.get(0); + String output = firstCheckpoint.getOutput(); + Assert.assertEquals("45652\r\n", output); + } + + /** + * 测试用例: 测试getCheckpointsUsingProblemId(long)方法 + * 测试数据: 使用不存在的试题唯一标识符(0) + * 预期结果: 返回对应的测试点列表(0个项目) + */ + @Test + public void testGetCheckpointsUsingProblemIdNotExists() { + List checkpoints = checkpointMapper.getCheckpointsUsingProblemId(0); + Assert.assertEquals(0, checkpoints.size()); + } + + /** + * 待测试的CheckpointMapper对象. + */ + @Autowired + private CheckpointMapper checkpointMapper; } diff --git a/judger/src/test/java/org/verwandlung/voj/judger/mapper/JudgeResultMapperTest.java b/judger/src/test/java/org/verwandlung/voj/judger/mapper/JudgeResultMapperTest.java index 5d6b0df4..196d873f 100644 --- a/judger/src/test/java/org/verwandlung/voj/judger/mapper/JudgeResultMapperTest.java +++ b/judger/src/test/java/org/verwandlung/voj/judger/mapper/JudgeResultMapperTest.java @@ -18,34 +18,34 @@ @Transactional @ContextConfiguration({"classpath:test-spring-context.xml"}) public class JudgeResultMapperTest { - /** - * 测试用例: 测试getJudgeResultUsingSlug(String)方法 - * 测试数据: 普通评测结果(JudgeResult)的评测结果组唯一英文缩写 - * 预期结果: 返回评测结果(JudgeResult)的评测结果组对象 - */ - @Test - public void testGetJudgeResultUsingSlugExists() { - JudgeResult judgeResult = judgeResultMapper.getJudgeResultUsingSlug("AC"); - Assert.assertNotNull(judgeResult); - - int judgeResultId = judgeResult.getJudgeResultId(); - Assert.assertEquals(2, judgeResultId); - } - - /** - * 测试用例: 测试getJudgeResultUsingSlug(String)方法 - * 测试数据: 不存在的评测结果组唯一英文缩写 - * 预期结果: 返回空引用 - */ - @Test - public void testGetJudgeResultUsingSlugNotExists() { - JudgeResult judgeResult = judgeResultMapper.getJudgeResultUsingSlug("Not-Exists"); - Assert.assertNull(judgeResult); - } - - /** - * 待测试的JudgeResultMapper对象. - */ - @Autowired - private JudgeResultMapper judgeResultMapper; + /** + * 测试用例: 测试getJudgeResultUsingSlug(String)方法 + * 测试数据: 普通评测结果(JudgeResult)的评测结果组唯一英文缩写 + * 预期结果: 返回评测结果(JudgeResult)的评测结果组对象 + */ + @Test + public void testGetJudgeResultUsingSlugExists() { + JudgeResult judgeResult = judgeResultMapper.getJudgeResultUsingSlug("AC"); + Assert.assertNotNull(judgeResult); + + int judgeResultId = judgeResult.getJudgeResultId(); + Assert.assertEquals(2, judgeResultId); + } + + /** + * 测试用例: 测试getJudgeResultUsingSlug(String)方法 + * 测试数据: 不存在的评测结果组唯一英文缩写 + * 预期结果: 返回空引用 + */ + @Test + public void testGetJudgeResultUsingSlugNotExists() { + JudgeResult judgeResult = judgeResultMapper.getJudgeResultUsingSlug("Not-Exists"); + Assert.assertNull(judgeResult); + } + + /** + * 待测试的JudgeResultMapper对象. + */ + @Autowired + private JudgeResultMapper judgeResultMapper; } diff --git a/judger/src/test/java/org/verwandlung/voj/judger/mapper/LanguageMapperTest.java b/judger/src/test/java/org/verwandlung/voj/judger/mapper/LanguageMapperTest.java index f7a42ea2..e4794d91 100644 --- a/judger/src/test/java/org/verwandlung/voj/judger/mapper/LanguageMapperTest.java +++ b/judger/src/test/java/org/verwandlung/voj/judger/mapper/LanguageMapperTest.java @@ -21,76 +21,76 @@ @Transactional @ContextConfiguration({"classpath:test-spring-context.xml"}) public class LanguageMapperTest { - /** - * 测试用例: 测试getLanguageUsingId(int)方法 - * 测试数据: C语言的编程语言唯一标识符 - * 预期结果: 返回C语言的编程语言对象 - */ - @Test - public void testGetLanguageUsingIdExists() { - Language language = languageMapper.getLanguageUsingId(1); - Assert.assertNotNull(language); - - String languageName = language.getLanguageName(); - Assert.assertEquals("C", languageName); - } - - /** - * 测试用例: 测试getLanguageUsingId(int)方法 - * 测试数据: 不存在的编程语言唯一标识符 - * 预期结果: 返回空引用 - */ - @Test - public void testGetLanguageUsingIdNotExists() { - Language language = languageMapper.getLanguageUsingId(0); - Assert.assertNull(language); - } - - /** - * 测试用例: 测试getLanguageUsingSlug(String)方法 - * 测试数据: C语言的编程语言唯一英文缩写 - * 预期结果: 返回C语言的编程语言对象 - */ - @Test - public void testGetLanguageUsingSlugExists() { - Language language = languageMapper.getLanguageUsingSlug("text/x-csrc"); - Assert.assertNotNull(language); - - String languageName = language.getLanguageName(); - Assert.assertEquals("C", languageName); - } - - /** - * 测试用例: 测试getLanguageUsingSlug(String)方法 - * 测试数据: 不存在的编程语言唯一英文缩写 - * 预期结果: 返回空引用 - */ - @Test - public void testGetLanguageUsingSlugNotExists() { - Language language = languageMapper.getLanguageUsingSlug("Not-Exists"); - Assert.assertNull(language); - } + /** + * 测试用例: 测试getLanguageUsingId(int)方法 + * 测试数据: C语言的编程语言唯一标识符 + * 预期结果: 返回C语言的编程语言对象 + */ + @Test + public void testGetLanguageUsingIdExists() { + Language language = languageMapper.getLanguageUsingId(1); + Assert.assertNotNull(language); + + String languageName = language.getLanguageName(); + Assert.assertEquals("C", languageName); + } + + /** + * 测试用例: 测试getLanguageUsingId(int)方法 + * 测试数据: 不存在的编程语言唯一标识符 + * 预期结果: 返回空引用 + */ + @Test + public void testGetLanguageUsingIdNotExists() { + Language language = languageMapper.getLanguageUsingId(0); + Assert.assertNull(language); + } + + /** + * 测试用例: 测试getLanguageUsingSlug(String)方法 + * 测试数据: C语言的编程语言唯一英文缩写 + * 预期结果: 返回C语言的编程语言对象 + */ + @Test + public void testGetLanguageUsingSlugExists() { + Language language = languageMapper.getLanguageUsingSlug("text/x-csrc"); + Assert.assertNotNull(language); + + String languageName = language.getLanguageName(); + Assert.assertEquals("C", languageName); + } + + /** + * 测试用例: 测试getLanguageUsingSlug(String)方法 + * 测试数据: 不存在的编程语言唯一英文缩写 + * 预期结果: 返回空引用 + */ + @Test + public void testGetLanguageUsingSlugNotExists() { + Language language = languageMapper.getLanguageUsingSlug("Not-Exists"); + Assert.assertNull(language); + } - /** - * 测试用例: 测试getAllLanguages()方法 - * 测试数据: N/a - * 预期结果: 返回全部的编程语言列表(共6种语言) - */ - @Test - public void testGetAllLanguages() { - List languages = languageMapper.getAllLanguages(); - Assert.assertNotNull(languages); - Assert.assertEquals(6, languages.size()); - - Language firstLanguage = languages.get(0); - Assert.assertNotNull(firstLanguage); - - String languageName = firstLanguage.getLanguageName(); - Assert.assertEquals("C", languageName); - } - /** - * 待测试的LanguageMapper对象. - */ - @Autowired - private LanguageMapper languageMapper; + /** + * 测试用例: 测试getAllLanguages()方法 + * 测试数据: N/a + * 预期结果: 返回全部的编程语言列表(共6种语言) + */ + @Test + public void testGetAllLanguages() { + List languages = languageMapper.getAllLanguages(); + Assert.assertNotNull(languages); + Assert.assertEquals(6, languages.size()); + + Language firstLanguage = languages.get(0); + Assert.assertNotNull(firstLanguage); + + String languageName = firstLanguage.getLanguageName(); + Assert.assertEquals("C", languageName); + } + /** + * 待测试的LanguageMapper对象. + */ + @Autowired + private LanguageMapper languageMapper; } diff --git a/judger/src/test/java/org/verwandlung/voj/judger/mapper/ProblemMapperTest.java b/judger/src/test/java/org/verwandlung/voj/judger/mapper/ProblemMapperTest.java index a5d3d46e..63a37996 100644 --- a/judger/src/test/java/org/verwandlung/voj/judger/mapper/ProblemMapperTest.java +++ b/judger/src/test/java/org/verwandlung/voj/judger/mapper/ProblemMapperTest.java @@ -18,34 +18,34 @@ @Transactional @ContextConfiguration({"classpath:test-spring-context.xml"}) public class ProblemMapperTest { - /** - * 测试用例: 测试getProblem()方法 - * 测试数据: 使用A+B Problem的试题唯一标识符 - * 预期结果: 返回预期的试题对象 - */ - @Test - public void testGetProblemExists() { - Problem problem = problemMapper.getProblem(1000); - Assert.assertNotNull(problem); - - String problemName = problem.getProblemName(); - Assert.assertEquals("A+B Problem", problemName); - } - - /** - * 测试用例: 测试getProblem()方法 - * 测试数据: 使用不存在的试题唯一标识符 - * 预期结果: 返回空引用 - */ - @Test - public void testGetProblemNotExists() { - Problem problem = problemMapper.getProblem(0); - Assert.assertNull(problem); - } - - /** - * 待测试的ProblemMapper对象. - */ - @Autowired - private ProblemMapper problemMapper; + /** + * 测试用例: 测试getProblem()方法 + * 测试数据: 使用A+B Problem的试题唯一标识符 + * 预期结果: 返回预期的试题对象 + */ + @Test + public void testGetProblemExists() { + Problem problem = problemMapper.getProblem(1000); + Assert.assertNotNull(problem); + + String problemName = problem.getProblemName(); + Assert.assertEquals("A+B Problem", problemName); + } + + /** + * 测试用例: 测试getProblem()方法 + * 测试数据: 使用不存在的试题唯一标识符 + * 预期结果: 返回空引用 + */ + @Test + public void testGetProblemNotExists() { + Problem problem = problemMapper.getProblem(0); + Assert.assertNull(problem); + } + + /** + * 待测试的ProblemMapper对象. + */ + @Autowired + private ProblemMapper problemMapper; } diff --git a/judger/src/test/java/org/verwandlung/voj/judger/mapper/SubmissionMapperTest.java b/judger/src/test/java/org/verwandlung/voj/judger/mapper/SubmissionMapperTest.java index 0200e619..81f47e8b 100644 --- a/judger/src/test/java/org/verwandlung/voj/judger/mapper/SubmissionMapperTest.java +++ b/judger/src/test/java/org/verwandlung/voj/judger/mapper/SubmissionMapperTest.java @@ -18,34 +18,34 @@ @Transactional @ContextConfiguration({"classpath:test-spring-context.xml"}) public class SubmissionMapperTest { - /** - * 测试用例: 测试getSubmission(long)方法 - * 测试数据: Problem#1000的提交记录的唯一标识符 - * 预期结果: 返回预期的Submission对象 - */ - @Test - public void testGetSubmissionExists() { - Submission submission = submissionMapper.getSubmission(1000); - Assert.assertNotNull(submission); - - long problemId = submission.getProblem().getProblemId(); - Assert.assertEquals(1000, problemId); - } - - /** - * 测试用例: 测试getSubmission(long)方法 - * 测试数据: 不存在的的提交记录唯一标识符 - * 预期结果: 返回空引用 - */ - @Test - public void testGetSubmissionNotExists() { - Submission submission = submissionMapper.getSubmission(0); - Assert.assertNull(submission); - } - - /** - * 待测试的SubmissionMapper对象. - */ - @Autowired - private SubmissionMapper submissionMapper; + /** + * 测试用例: 测试getSubmission(long)方法 + * 测试数据: Problem#1000的提交记录的唯一标识符 + * 预期结果: 返回预期的Submission对象 + */ + @Test + public void testGetSubmissionExists() { + Submission submission = submissionMapper.getSubmission(1000); + Assert.assertNotNull(submission); + + long problemId = submission.getProblem().getProblemId(); + Assert.assertEquals(1000, problemId); + } + + /** + * 测试用例: 测试getSubmission(long)方法 + * 测试数据: 不存在的的提交记录唯一标识符 + * 预期结果: 返回空引用 + */ + @Test + public void testGetSubmissionNotExists() { + Submission submission = submissionMapper.getSubmission(0); + Assert.assertNull(submission); + } + + /** + * 待测试的SubmissionMapper对象. + */ + @Autowired + private SubmissionMapper submissionMapper; } diff --git a/judger/src/test/java/org/verwandlung/voj/judger/mapper/UserGroupMapperTest.java b/judger/src/test/java/org/verwandlung/voj/judger/mapper/UserGroupMapperTest.java index e04fb7f2..ada23933 100644 --- a/judger/src/test/java/org/verwandlung/voj/judger/mapper/UserGroupMapperTest.java +++ b/judger/src/test/java/org/verwandlung/voj/judger/mapper/UserGroupMapperTest.java @@ -19,34 +19,34 @@ @Transactional @ContextConfiguration({"classpath:test-spring-context.xml"}) public class UserGroupMapperTest { - /** - * 测试用例: 测试getUserGroupUsingId(int)方法 - * 测试数据: 普通用户(User)的用户组唯一标识符 - * 预期结果: 返回用户(User)的用户组对象 - */ - @Test - public void testGetUserGroupUsingIdExists() { - UserGroup userGroup = userGroupMapper.getUserGroupUsingId(1); - Assert.assertNotNull(userGroup); - - String userGroupSlug = userGroup.getUserGroupSlug(); - Assert.assertEquals("forbidden", userGroupSlug); - } - - /** - * 测试用例: 测试getUserGroupUsingId(int)方法 - * 测试数据: 不存在的用户组唯一标识符 - * 预期结果: 返回空引用 - */ - @Test - public void testGetUserGroupUsingIdNotExists() { - UserGroup userGroup = userGroupMapper.getUserGroupUsingId(0); - Assert.assertNull(userGroup); - } - - /** - * 待测试的UserGroupMapper对象. - */ - @Autowired - private UserGroupMapper userGroupMapper; + /** + * 测试用例: 测试getUserGroupUsingId(int)方法 + * 测试数据: 普通用户(User)的用户组唯一标识符 + * 预期结果: 返回用户(User)的用户组对象 + */ + @Test + public void testGetUserGroupUsingIdExists() { + UserGroup userGroup = userGroupMapper.getUserGroupUsingId(1); + Assert.assertNotNull(userGroup); + + String userGroupSlug = userGroup.getUserGroupSlug(); + Assert.assertEquals("forbidden", userGroupSlug); + } + + /** + * 测试用例: 测试getUserGroupUsingId(int)方法 + * 测试数据: 不存在的用户组唯一标识符 + * 预期结果: 返回空引用 + */ + @Test + public void testGetUserGroupUsingIdNotExists() { + UserGroup userGroup = userGroupMapper.getUserGroupUsingId(0); + Assert.assertNull(userGroup); + } + + /** + * 待测试的UserGroupMapper对象. + */ + @Autowired + private UserGroupMapper userGroupMapper; } diff --git a/judger/src/test/java/org/verwandlung/voj/judger/mapper/UserMapperTest.java b/judger/src/test/java/org/verwandlung/voj/judger/mapper/UserMapperTest.java index d98192de..7b0cbbe1 100644 --- a/judger/src/test/java/org/verwandlung/voj/judger/mapper/UserMapperTest.java +++ b/judger/src/test/java/org/verwandlung/voj/judger/mapper/UserMapperTest.java @@ -19,34 +19,34 @@ @Transactional @ContextConfiguration({"classpath:test-spring-context.xml"}) public class UserMapperTest { - /** - * 测试用例: 测试getUserUsingUsername(String)方法 - * 测试数据: 使用用户名为zjhzxhz的用户 - * 预期结果: 返回预期的用户对象 - */ - @Test - public void testGetUserUsingUsernameExists() { - User user = userMapper.getUserUsingUsername("Zjhzxhz"); - Assert.assertNotNull(user); - - long uid = user.getUid(); - Assert.assertEquals(1000, uid); - } - - /** - * 测试用例: 测试getUserUsingUsername(String)方法 - * 测试数据: 使用不存在的用户名 - * 预期结果: 返回空引用 - */ - @Test - public void testGetUserUsingUsernameNotExists() { - User user = userMapper.getUserUsingUsername("Not-Exists"); - Assert.assertNull(user); - } - - /** - * 待测试的UserMapper对象. - */ - @Autowired - private UserMapper userMapper; + /** + * 测试用例: 测试getUserUsingUsername(String)方法 + * 测试数据: 使用用户名为zjhzxhz的用户 + * 预期结果: 返回预期的用户对象 + */ + @Test + public void testGetUserUsingUsernameExists() { + User user = userMapper.getUserUsingUsername("Zjhzxhz"); + Assert.assertNotNull(user); + + long uid = user.getUid(); + Assert.assertEquals(1000, uid); + } + + /** + * 测试用例: 测试getUserUsingUsername(String)方法 + * 测试数据: 使用不存在的用户名 + * 预期结果: 返回空引用 + */ + @Test + public void testGetUserUsingUsernameNotExists() { + User user = userMapper.getUserUsingUsername("Not-Exists"); + Assert.assertNull(user); + } + + /** + * 待测试的UserMapper对象. + */ + @Autowired + private UserMapper userMapper; } diff --git a/voj.sql b/voj.sql index a142eb34..22c585b7 100644 --- a/voj.sql +++ b/voj.sql @@ -335,7 +335,11 @@ CREATE TABLE IF NOT EXISTS `voj_problem_tag_relationships` ( -- INSERT INTO `voj_problem_tag_relationships` (`problem_id`, `problem_tag_id`) VALUES -(1001, 1); +(1000, 1), +(1001, 1), +(1001, 2), +(1002, 1), +(1003, 2); -- -------------------------------------------------------- diff --git a/web/src/main/java/org/verwandlung/voj/web/mapper/ProblemCategoryMapper.java b/web/src/main/java/org/verwandlung/voj/web/mapper/ProblemCategoryMapper.java index 04a35800..80fe7c76 100644 --- a/web/src/main/java/org/verwandlung/voj/web/mapper/ProblemCategoryMapper.java +++ b/web/src/main/java/org/verwandlung/voj/web/mapper/ProblemCategoryMapper.java @@ -1,10 +1,12 @@ package org.verwandlung.voj.web.mapper; import java.util.List; +import java.util.Map; import org.apache.ibatis.annotations.CacheNamespace; import org.apache.ibatis.annotations.Param; import org.verwandlung.voj.web.model.ProblemCategory; +import org.verwandlung.voj.web.model.ProblemCategoryRelationship; /** * ProblemCategory Data Access Object. @@ -39,7 +41,9 @@ public interface ProblemCategoryMapper { * @param problemIdUpperBound - 试题ID区间的上界 * @return 包含试题分类信息的列表 */ - public List getProblemCategoriesOfProblems(long problemIdLowerBound, long problemIdUpperBound); + public List getProblemCategoriesOfProblems( + @Param(value = "problemIdLowerBound") long problemIdLowerBound, + @Param(value = "problemIdUpperBound") long problemIdUpperBound); /** * 通过试题分类的别名获取试题分类对象. diff --git a/web/src/main/java/org/verwandlung/voj/web/mapper/ProblemTagMapper.java b/web/src/main/java/org/verwandlung/voj/web/mapper/ProblemTagMapper.java index 642884e8..8fd6644a 100644 --- a/web/src/main/java/org/verwandlung/voj/web/mapper/ProblemTagMapper.java +++ b/web/src/main/java/org/verwandlung/voj/web/mapper/ProblemTagMapper.java @@ -5,6 +5,7 @@ import org.apache.ibatis.annotations.CacheNamespace; import org.apache.ibatis.annotations.Param; import org.verwandlung.voj.web.model.ProblemTag; +import org.verwandlung.voj.web.model.ProblemTagRelationship; /** * ProblemTag Data Access Object. @@ -31,8 +32,19 @@ public interface ProblemTagMapper { * @param problemId - 试题的唯一标识符 * @return 预期的试题标签对象列表 */ - public List getProblemTagUsingProblemId(long problemId); - + public List getProblemTagsUsingProblemId(long problemId); + + /** + * 获取某个区间内各试题的标签. + * @param problemIdLowerBound - 试题ID区间的下界 + * @param problemIdUpperBound - 试题ID区间的上界 + * @return 包含试题标签信息的列表 + */ + public List getProblemTagsOfProblems( + @Param(value = "problemIdLowerBound") long problemIdLowerBound, + @Param(value = "problemIdUpperBound") long problemIdUpperBound); + + /** * 通过试题标签的别名获取试题标签对象. * @param problemTagSlug - 试题标签的别名 diff --git a/web/src/main/java/org/verwandlung/voj/web/model/ProblemCategoryRelationship.java b/web/src/main/java/org/verwandlung/voj/web/model/ProblemCategoryRelationship.java new file mode 100644 index 00000000..6f7adfa8 --- /dev/null +++ b/web/src/main/java/org/verwandlung/voj/web/model/ProblemCategoryRelationship.java @@ -0,0 +1,146 @@ +package org.verwandlung.voj.web.model; + +import java.io.Serializable; + +/** + * 试题分类关系的 Model. + * 对应数据库中的voj_problem_category_relationships数据表. + * + * @author Haozhe Xie + */ +public class ProblemCategoryRelationship implements Serializable { + /** + * ProblemCategoryRelationship的默认构造函数. + */ + public ProblemCategoryRelationship() { } + + /** + * ProblemCategoryRelationship的构造函数. + * @param problemId - 试题的唯一标识符 + * @param problemCategoryId - 试题分类的唯一标识符 + * @param problemCategorySlug - 试题分类的别名 + * @param problemCategoryName - 试题分类的名称 + */ + public ProblemCategoryRelationship(long problemId, long problemCategoryId, String problemCategorySlug, String problemCategoryName) { + this.problemId = problemId; + this.problemCategoryId = problemCategoryId; + this.problemCategorySlug = problemCategorySlug; + this.problemCategoryName = problemCategoryName; + } + + /** + * 获取试题的唯一标识符. + * @return 试题的唯一标识符 + */ + public long getProblemId() { + return problemId; + } + + /** + * 设置试题的唯一标识符. + * @param problemId - 试题的唯一标识符 + */ + public void setProblemId(long problemId) { + this.problemId = problemId; + } + + /** + * 获取试题分类的唯一标识符. + * @return 试题分类的唯一标识符 + */ + public long getProblemCategoryId() { + return problemCategoryId; + } + + /** + * 设置试题分类的唯一标识符. + * @param problemCategoryId - 试题分类的唯一标识符 + */ + public void setProblemCategoryId(long problemCategoryId) { + this.problemCategoryId = problemCategoryId; + } + + /** + * 获取试题分类的别名. + * @return 试题分类的别名 + */ + public String getProblemCategorySlug() { + return problemCategorySlug; + } + + /** + * 设置试题分类的别名. + * @param problemCategorySlug - 试题分类的别名 + */ + public void setProblemCategorySlug(String problemCategorySlug) { + this.problemCategorySlug = problemCategorySlug; + } + + /** + * 获取试题分类的名称. + * @return 试题分类的名称 + */ + public String getProblemCategoryName() { + return problemCategoryName; + } + + /** + * 设置试题分类的名称. + * @param problemCategoryName - 试题分类的名称 + */ + public void setProblemCategoryName(String problemCategoryName) { + this.problemCategoryName = problemCategoryName; + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + public int hashCode() { + return (int) problemId + (int) problemCategoryId; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + public boolean equals(Object obj) { + if ( obj instanceof ProblemCategoryRelationship ) { + ProblemCategoryRelationship anotherCategoryRelationship = (ProblemCategoryRelationship)obj; + return anotherCategoryRelationship.getProblemId() == problemId && + anotherCategoryRelationship.getProblemCategoryId() == problemCategoryId; + } + return false; + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + public String toString() { + return String.format("ProblemCategoryRelationship [ProblemID=%d, CategoryID=%d, Slug=%s, Name=%s]", + new Object[] { problemId, problemCategoryId, problemCategorySlug, problemCategoryName }); + } + + /** + * 试题的唯一标识符. + */ + private long problemId; + + /** + * 试题分类的唯一标识符. + */ + private long problemCategoryId; + + /** + * 试题分类的别名. + */ + private String problemCategorySlug; + + /** + * 试题分类的名称. + */ + private String problemCategoryName; + + /** + * 唯一的序列化标识符. + */ + private static final long serialVersionUID = 5108958918621777517L; +} diff --git a/web/src/main/java/org/verwandlung/voj/web/model/ProblemTagRelationship.java b/web/src/main/java/org/verwandlung/voj/web/model/ProblemTagRelationship.java new file mode 100644 index 00000000..17b6bfff --- /dev/null +++ b/web/src/main/java/org/verwandlung/voj/web/model/ProblemTagRelationship.java @@ -0,0 +1,146 @@ +package org.verwandlung.voj.web.model; + +import java.io.Serializable; + +/** + * 试题标签关系的 Model. + * 对应数据库中的voj_problem_tag_relationships数据表. + * + * @author Haozhe Xie + */ +public class ProblemTagRelationship implements Serializable { + /** + * ProblemTagRelationship的默认构造函数. + */ + public ProblemTagRelationship() { } + + /** + * ProblemTagRelationship的构造函数. + * @param problemId - 试题的唯一标识符 + * @param problemTagId - 试题标签的唯一标识符 + * @param problemTagSlug - 试题标签的别名 + * @param problemTagName - 试题标签的名称 + */ + public ProblemTagRelationship(long problemId, long problemTagId, String problemTagSlug, String problemTagName) { + this.problemId = problemId; + this.problemTagId = problemTagId; + this.problemTagSlug = problemTagSlug; + this.problemTagName = problemTagName; + } + + /** + * 获取试题的唯一标识符. + * @return 试题的唯一标识符 + */ + public long getProblemId() { + return problemId; + } + + /** + * 设置试题的唯一标识符. + * @param problemId - 试题的唯一标识符 + */ + public void setProblemId(long problemId) { + this.problemId = problemId; + } + + /** + * 获取试题标签的唯一标识符. + * @return 试题标签的唯一标识符 + */ + public long getProblemTagId() { + return problemTagId; + } + + /** + * 设置试题标签的唯一标识符. + * @param problemTagId - 试题标签的唯一标识符 + */ + public void setProblemTagId(long problemTagId) { + this.problemTagId = problemTagId; + } + + /** + * 获取试题标签的别名. + * @return 试题标签的别名 + */ + public String getProblemTagSlug() { + return problemTagSlug; + } + + /** + * 设置试题标签的别名. + * @param problemTagSlug - 试题标签的别名 + */ + public void setProblemTagSlug(String problemTagSlug) { + this.problemTagSlug = problemTagSlug; + } + + /** + * 获取试题标签的名称. + * @return 试题标签的名称 + */ + public String getProblemTagName() { + return problemTagName; + } + + /** + * 设置试题标签的名称. + * @param problemTagName - 试题标签的名称 + */ + public void setProblemTagName(String problemTagName) { + this.problemTagName = problemTagName; + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + public int hashCode() { + return (int) problemId + (int) problemTagId; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + public boolean equals(Object obj) { + if ( obj instanceof ProblemTagRelationship ) { + ProblemTagRelationship anotherTagRelationship = (ProblemTagRelationship)obj; + return anotherTagRelationship.getProblemId() == problemId && + anotherTagRelationship.getProblemTagId() == problemTagId; + } + return false; + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + public String toString() { + return String.format("ProblemTagRelationship [ProblemID=%d, TagID=%d, Slug=%s, Name=%s]", + new Object[] { problemId, problemTagId, problemTagSlug, problemTagName }); + } + + /** + * 试题的唯一标识符. + */ + private long problemId; + + /** + * 试题标签的唯一标识符. + */ + private long problemTagId; + + /** + * 试题标签的别名. + */ + private String problemTagSlug; + + /** + * 试题标签的名称. + */ + private String problemTagName; + + /** + * 唯一的序列化标识符. + */ + private static final long serialVersionUID = -1636820984815816993L; +} diff --git a/web/src/main/java/org/verwandlung/voj/web/service/ProblemService.java b/web/src/main/java/org/verwandlung/voj/web/service/ProblemService.java index bc5faee3..c9a465b0 100644 --- a/web/src/main/java/org/verwandlung/voj/web/service/ProblemService.java +++ b/web/src/main/java/org/verwandlung/voj/web/service/ProblemService.java @@ -108,7 +108,7 @@ public List getProblemCategoriesUsingProblemId(long problemId) * @return 包含试题标签的列表 */ public List getProblemTagsUsingProblemId(long problemId) { - return problemTagMapper.getProblemTagUsingProblemId(problemId); + return problemTagMapper.getProblemTagsUsingProblemId(problemId); } /** diff --git a/web/src/main/resources/mappers/ProblemCategoryMapper.xml b/web/src/main/resources/mappers/ProblemCategoryMapper.xml index b0961583..c013a72f 100644 --- a/web/src/main/resources/mappers/ProblemCategoryMapper.xml +++ b/web/src/main/resources/mappers/ProblemCategoryMapper.xml @@ -11,6 +11,13 @@ + + + + + + SELECT * FROM voj_problem_category_relationships diff --git a/web/src/main/resources/mappers/ProblemTagMapper.xml b/web/src/main/resources/mappers/ProblemTagMapper.xml index 56581cf0..4020f5c6 100644 --- a/web/src/main/resources/mappers/ProblemTagMapper.xml +++ b/web/src/main/resources/mappers/ProblemTagMapper.xml @@ -10,6 +10,13 @@ + + + + + + @@ -35,6 +42,16 @@ NATURAL JOIN voj_problem_tag_relationships WHERE problem_id = #{problemId} + diff --git a/web/src/main/webapp/WEB-INF/views/administration/all-problems.jsp b/web/src/main/webapp/WEB-INF/views/administration/all-problems.jsp index 0b8ffd29..6e87cab5 100644 --- a/web/src/main/webapp/WEB-INF/views/administration/all-problems.jsp +++ b/web/src/main/webapp/WEB-INF/views/administration/all-problems.jsp @@ -117,8 +117,30 @@ ${problem.problemName} - - + + + + + + "> + ${problemCategory.problemCategoryName} + , + + + + + + + + + + "> + ${problemTag.problemTagName} + , + + + + ${problem.totalSubmission} ${problem.acceptedSubmission} diff --git a/web/src/test/java/org/verwandlung/voj/web/mapper/ProblemMapperTest.java b/web/src/test/java/org/verwandlung/voj/web/mapper/ProblemMapperTest.java index 7527c306..33e91a11 100644 --- a/web/src/test/java/org/verwandlung/voj/web/mapper/ProblemMapperTest.java +++ b/web/src/test/java/org/verwandlung/voj/web/mapper/ProblemMapperTest.java @@ -121,7 +121,7 @@ public void testGetProblemNotExists() { */ @Test public void testGetProblemsFrom1000WithLimit10() { - List problems = problemMapper.getProblemsUsingFilters(null, 0, true, 1000, 10); + List problems = problemMapper.getProblemsUsingFilters(null, 0, 0, true, 1000, 10); Assert.assertEquals(3, problems.size()); Problem firstProblem = problems.get(0); @@ -142,7 +142,7 @@ public void testGetProblemsFrom1000WithLimit10() { */ @Test public void testGetProblemsFrom1001WithLimit1() { - List problems = problemMapper.getProblemsUsingFilters("", 0, true, 1001, 1); + List problems = problemMapper.getProblemsUsingFilters("", 0, 0, true, 1001, 1); Assert.assertEquals(1, problems.size()); Problem firstProblem = problems.get(0); @@ -160,7 +160,7 @@ public void testGetProblemsFrom1001WithLimit1() { */ @Test public void testGetProblemsFrom1010WithLimit10() { - List problems = problemMapper.getProblemsUsingFilters(null, 0, true, 1010, 10); + List problems = problemMapper.getProblemsUsingFilters(null, 0, 0, true, 1010, 10); Assert.assertEquals(0, problems.size()); } From 17b794d55b90351edae929b61b79d974dfc2c816 Mon Sep 17 00:00:00 2001 From: Haozhe Xie Date: Thu, 7 Apr 2016 23:31:19 +0800 Subject: [PATCH 3/4] Complete Tag fitler for problems in administration. --- .../verwandlung/voj/web/service/ProblemService.java | 2 +- web/src/main/resources/mappers/ProblemMapper.xml | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/web/src/main/java/org/verwandlung/voj/web/service/ProblemService.java b/web/src/main/java/org/verwandlung/voj/web/service/ProblemService.java index 87707c7f..5644bf49 100644 --- a/web/src/main/java/org/verwandlung/voj/web/service/ProblemService.java +++ b/web/src/main/java/org/verwandlung/voj/web/service/ProblemService.java @@ -65,7 +65,7 @@ public Problem getProblem(long problemId) { public List getProblemsUsingFilters(long offset, String keyword, String problemCategorySlug, String problemTagSlug, boolean isPublicOnly, int limit) { ProblemCategory problemCategory = problemCategoryMapper.getProblemCategoryUsingCategorySlug(problemCategorySlug); - ProblemTag problemTag = problemTagMapper.getProblemTagUsingTagSlug(problemTagSlug); + ProblemTag problemTag = problemTagMapper.getProblemTagUsingTagSlug(SlugifyUtils.getSlug(problemTagSlug)); int problemCategoryId = 0; long problemTagId = 0; if ( problemCategory != null ) { diff --git a/web/src/main/resources/mappers/ProblemMapper.xml b/web/src/main/resources/mappers/ProblemMapper.xml index 28691054..dd79e658 100644 --- a/web/src/main/resources/mappers/ProblemMapper.xml +++ b/web/src/main/resources/mappers/ProblemMapper.xml @@ -94,7 +94,7 @@ parameterType="map" resultMap="ProblemResultMap" useCache="true"> - SELECT DISTINCT(problem_id), problem_name, problem_is_public, ( + SELECT DISTINCT(p.problem_id), problem_name, problem_is_public, ( SELECT COUNT(*) FROM voj_submissions s WHERE s.problem_id = p.problem_id @@ -105,8 +105,10 @@ ) AS accepted_submission FROM voj_problems p NATURAL JOIN voj_problem_category_relationships pcr - NATURAL JOIN voj_problem_categories pc - WHERE problem_id >= #{problemId} + + NATURAL JOIN voj_problem_tag_relationships ptr + + WHERE p.problem_id >= #{problemId} AND problem_is_public = 1 @@ -116,6 +118,9 @@ AND problem_category_id = #{problemCategoryId} + + AND problem_tag_id = #{problemTagId} + LIMIT #{limit} Date: Thu, 7 Apr 2016 23:36:21 +0800 Subject: [PATCH 4/4] Update the UI for problems list in administration. --- .../WEB-INF/views/administration/all-problems.jsp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/web/src/main/webapp/WEB-INF/views/administration/all-problems.jsp b/web/src/main/webapp/WEB-INF/views/administration/all-problems.jsp index 6e87cab5..3eec1f1d 100644 --- a/web/src/main/webapp/WEB-INF/views/administration/all-problems.jsp +++ b/web/src/main/webapp/WEB-INF/views/administration/all-problems.jsp @@ -57,7 +57,7 @@
- +
@@ -68,17 +68,17 @@ " value="${keyword}" /> -
+
-
-
- -
+
+
+ +