private boolean parseOddLineOfMetaInfo( List<String> errorMessages, String line, int lineNumber, TestGroup group) { String[] firstLine = line.split(" "); if (firstLine.length != 2) { addMessageOnLine( errorMessages, lineNumber - 1, "Line has incorrect format. " + "Should consist of the number of points for the test case and " + "yes/no if feedback is enabled separated by space" + " e.g. '10 yes'."); return false; } try { group.setPoints(new BigDecimal(firstLine[0])); } catch (NumberFormatException e) { addMessageOnLine( errorMessages, lineNumber - 1, "The line does not start with an integer/double"); return false; } if ("yes".equalsIgnoreCase(firstLine[1])) { group.setFeedbackEnabled(true); } else if ("no".equalsIgnoreCase(firstLine[1])) { group.setFeedbackEnabled(false); } else { addMessageOnLine( errorMessages, lineNumber - 1, "The string for feedback is neither 'yes' nor 'no'."); return false; } return true; }
private void setUpDefaultMetaInfo(Task task, ContestManager contestManager, String contestId) { task.setTestGroups(new LinkedList<TestGroup>()); for (int i = 1; i <= task.getNumberOfTests(); ++i) { TestGroup group = new TestGroup(); group.setFeedbackEnabled(i * 5 <= task.getNumberOfTests()); group.setTestCases(Arrays.asList(i)); group.setPoints(new BigDecimal(100 / task.getNumberOfTests())); task.addTestGroup(group); } contestManager.updateTask(contestId, task); }
private boolean parseEvenLineOfMetaInfo( String line, Task task, List<String> errorMessages, int lineNumber, TestGroup group) { String[] testIndexes = line.split(" "); List<Integer> testsCases = new LinkedList<Integer>(); for (String index : testIndexes) { try { int test = Integer.parseInt(index); if (test <= 0 || test > task.getNumberOfTests()) { addMessageOnLine( errorMessages, lineNumber, "Incorrect index " + index + " must be between 1 and " + task.getNumberOfTests()); return false; } testsCases.add(test); } catch (NumberFormatException e) { addMessageOnLine(errorMessages, lineNumber, "Index " + index + " is not a number."); return false; } } if (testsCases.isEmpty()) { addMessageOnLine(errorMessages, lineNumber, "Cannot create a test group with no test cases."); return false; } group.setTestCases(testsCases); return true; }