/project/src/evaluator/CorrectnessTest.java
Java | 124 lines | 76 code | 21 blank | 27 comment | 15 complexity | 29e1f1d96a3bf62bb20779aa9e4ae947 MD5 | raw file
- /*
- * Copyright (c) 2011 Alexey Sergushichev <alsergbox@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;
- /**
- * Created by IntelliJ IDEA.
- * User: alserg
- * Date: 25.10.11
- * Time: 16:00
- */
- public class CorrectnessTest extends Test implements Comparable<CorrectnessTest> {
- private static Config cfg = Config.getInstance();
- private String inputFile;
- private Submission submission;
- public Submission getSubmission() {
- return submission;
- }
- public CorrectnessTest(Submission submission) throws IOException, SystemError, CheckError {
- this.submission = submission;
- Map<String, Object> props = new ConstructableMap<String, Object>(submission.toProps());
- String path = cfg.getPath("fs.submission", props);
- String binPath = cfg.getPath("fs.submission.bin", props);
- props.put("test", path);
- System.err.println("testPath: " + path);
- File okGeneratedFile = new File(cfg.getPath("fs.test.generated", props));
- inputFile = cfg.getPath("fs.test.in", props);
- System.err.println("inputFile: " + inputFile);
- props.put("inputFile", inputFile);
- if (!okGeneratedFile.exists()) {
- CheckResult checkResult = Executor.executeTarget(
- submission.getRequest().getTargetId(),
- binPath,
- cfg.getPath("fs.null"),
- inputFile,
- 0,
- 256 << 20 );
- if (checkResult.getStatus() != CheckResult.Status.OK) {
- throw new CheckError(checkResult);
- }
- ByteArrayOutputStream log = new ByteArrayOutputStream();
- if (Executor.trustedExecute(
- cfg.getList("run.check.test", props),
- 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) {
- 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.getRequest().toString();
- }
- @Override
- public String getDescription() {
- return "Contestant's test from " + submission.getRequest().getDate();
- }
- @Override
- public String getInputFile() {
- return inputFile;
- }
- }