Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grader: allow percentage output to be floating point #647

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public interface TestCaseVerdict {
Verdict getVerdict();
Optional<Double> getPoints();
Optional<Integer> getPercentage();
Optional<Double> getPercentage();
Optional<String> getFeedback();

class Builder extends ImmutableTestCaseVerdict.Builder {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public TestCaseVerdict parseOutput(String output) throws ScoringException {

Verdict verdict;
Optional<Double> points = Optional.empty();
Optional<Integer> percentage = Optional.empty();
Optional<Double> percentage = Optional.empty();
Optional<String> feedback = Optional.empty();

switch (lines[0]) {
Expand Down Expand Up @@ -44,7 +44,7 @@ public TestCaseVerdict parseOutput(String output) throws ScoringException {
if (!result.isEmpty() && result.charAt(result.length() - 1) == '%') {
String percentageString = result.substring(0, result.length() - 1);
try {
percentage = Optional.of(Integer.parseInt(percentageString));
percentage = Optional.of(Double.parseDouble(percentageString));
} catch (NumberFormatException e) {
throw new ScoringException("Invalid <percentage> for OK: " + result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ void aggregate_min_ok_points() {
void aggregate_min_ok_percentage() {
List<TestCaseVerdict> testCaseVerdicts = ImmutableList.of(
new TestCaseVerdict.Builder().verdict(Verdict.ACCEPTED).build(),
new TestCaseVerdict.Builder().verdict(Verdict.OK).percentage(25).build(),
new TestCaseVerdict.Builder().verdict(Verdict.OK).percentage(12.5).build(),
new TestCaseVerdict.Builder().verdict(Verdict.OK).percentage(50).build());

AggregationResult result = aggregator.aggregate(testCaseVerdicts, 70.0);
assertThat(result.getSubtaskVerdict()).isEqualTo(SubtaskVerdict.of(Verdict.OK, 17.5));
assertThat(result.getTestCasePoints()).containsExactly("*", "25%", "50%");
assertThat(result.getSubtaskVerdict()).isEqualTo(SubtaskVerdict.of(Verdict.OK, 8.75));
assertThat(result.getTestCasePoints()).containsExactly("*", "12.5%", "50.0%");
}

@Test
Expand Down