Exemple #1
0
  private void testOne(ProblemAndTestCaseList problemWithTestCases, String fileName)
      throws IOException, SubmissionException, InterruptedException {
    String programText = readProgram(fileName);

    OOPBuildServiceSubmission future =
        new OOPBuildServiceSubmission(
            new Submission(
                problemWithTestCases.getProblem(),
                Arrays.asList(problemWithTestCases.getTestCaseList()),
                programText));

    serverTask.submit(future);

    SubmissionResult result;
    while (true) {
      result = future.poll();
      if (result != null) {
        break;
      }
      Thread.sleep(200L);
    }

    if (fileName.startsWith("./")) {
      fileName = fileName.substring(2);
    }

    System.out.println("program: " + fileName);
    if (result.getCompilationResult().getOutcome() != CompilationOutcome.SUCCESS) {
      System.out.println("compiled: false");
      return;
    }
    System.out.println("compiled: true");

    for (int i = 0; i < problemWithTestCases.getTestCaseList().length; i++) {
      TestCase testCase = problemWithTestCases.getTestCaseList()[i];
      TestResult testResult = result.getTestResults()[i];

      String outcome;
      switch (testResult.getOutcome()) {
        case PASSED:
          outcome = "passed";
          break;
        case FAILED_WITH_EXCEPTION:
          outcome = "crashed";
          break;
        case FAILED_FROM_TIMEOUT:
          outcome = "timeout";
          break;
        default:
          outcome = "failed";
          break;
      }
      System.out.println("test " + testCase.getTestCaseName() + ":" + outcome);
      if (testResult.getOutcome() != TestOutcome.PASSED) {
        String output = testResult.getStdout();
        if (!output.endsWith("\n")) {
          output = output + "\n";
        }
        System.out.print(output);
      }
    }
  }