Skip to content

Commit

Permalink
grader: allow percentage output to be floating point (#647)
Browse files Browse the repository at this point in the history
  • Loading branch information
fushar authored Aug 14, 2024
1 parent cf872d0 commit 70f75a2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
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

0 comments on commit 70f75a2

Please sign in to comment.