/project/src/evaluator/CorrectnessTest.java
Java | 148 lines | 94 code | 24 blank | 30 comment | 28 complexity | 0bbcc61335bb29f869c96442e923288f MD5 | raw file
- /*
- * Copyright (c) 2011 Alexey Sergushichev <alsergbox@gmail.com>
- * 2012 Dmitry Gerasimov <karlicoss@gmail.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
- package evaluator;
- import java.io.ByteArrayOutputStream;
- import java.io.File;
- import java.io.IOException;
- import java.util.Map;
- import static java.util.Arrays.asList;
- /**
- * Created by IntelliJ IDEA.
- * User: alserg
- * Date: 25.10.11
- * Time: 16:00
- */
- public class CorrectnessTest extends Test implements Comparable<CorrectnessTest> {
- private static final Config globalConfig = Config.getInstance();
- private final String inputFile;
- private final Submission submission;
- public TestRequest getRequest() {
- if (submission == null)
- return null;
- return submission.getRequest();
- }
- public CorrectnessTest(String inputFile) {
- assert new File(inputFile).exists();
- this.inputFile = inputFile;
- submission = null;
- }
- public CorrectnessTest(Submission submission) throws IOException, SystemError, CheckError {
- this.submission = submission;
- Map<String, Object> props = new ConstructableMap<String, Object>(submission.toProps());
- String path = globalConfig.getPath("fs.submission", props);
- String binPath = globalConfig.getPath("fs.submission.bin", props);
- props.put("test", path);
- System.err.println("testPath: " + path);
- File okGeneratedFile = new File(globalConfig.getPath("fs.test.generated", props));
- inputFile = globalConfig.getPath("fs.test.in", props);
- System.err.println("inputFile: " + inputFile);
- props.put("inputFile", inputFile);
- if (!okGeneratedFile.exists()) {
- // Генерируем входные данные целью-тестом.в inputFile
- CheckResult checkResult = Executor.executeTarget(
- submission.getRequest().getTargetId(),
- binPath,
- globalConfig.getPath("fs.null"),
- inputFile,
- submission.getTask().getTestgenTimeLimit(),
- submission.getTask().getTestgenMemoryLimit());
- if (checkResult.getStatus() != CheckResult.Status.OK) {
- throw new CheckError(checkResult);
- }
- // Видимо, проверяем, что они корректны.
- ByteArrayOutputStream log = new ByteArrayOutputStream();
- if (Executor.trustedExecute(
- asList(submission.getTask().getInputValidatorPath(), inputFile),
- null,
- log) != 0) {
- System.err.println("checking test failed");
- System.err.println("reason: " + log.toString());
- throw new CheckError(
- new CheckResult(checkResult.getTime(), CheckResult.Status.PE, "Bad test format: " + log.toString()));
- }
- okGeneratedFile.createNewFile();
- }
- }
- @Override
- public int compareTo(CorrectnessTest o) {
- if ((submission == null) && (o.submission == null)) {
- return inputFile.compareTo(o.inputFile);
- }
-
- if (submission == null) {
- return -1;
- } else if (o.submission == null) {
- return 1;
- }
- return submission.compareTo(o.submission);
- }
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- CorrectnessTest test = (CorrectnessTest) o;
- if (submission != null ? !submission.equals(test.submission) : test.submission != null) return false;
- return true;
- }
- @Override
- public int hashCode() {
- return submission != null ? submission.hashCode() : 0;
- }
- @Override
- public String getHandle() {
- return "CT:" + (submission == null ? inputFile : submission.getRequest().toString());
- }
- @Override
- public String getDescription() {
- return submission == null ?
- "Test #" + new File(inputFile).getName() :
- "Contestant's test from " + submission.getRequest().getDate();
- }
- @Override
- public String getInputFile() {
- return inputFile;
- }
- }