From f058c44f93845782b754e4df92eddf1b1174a95b Mon Sep 17 00:00:00 2001 From: Ashar Fuadi Date: Sat, 24 Aug 2024 21:16:03 +0700 Subject: [PATCH] grader: allow percentage scoring for non-subtask problems as well --- .../judgels/gabriel/aggregators/SumAggregator.java | 6 +++++- .../gabriel/aggregators/SumAggregatorTests.java | 13 +++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/judgels-backends/judgels-grader-engines/src/main/java/judgels/gabriel/aggregators/SumAggregator.java b/judgels-backends/judgels-grader-engines/src/main/java/judgels/gabriel/aggregators/SumAggregator.java index 5163a4723..9cb4ef0e7 100644 --- a/judgels-backends/judgels-grader-engines/src/main/java/judgels/gabriel/aggregators/SumAggregator.java +++ b/judgels-backends/judgels-grader-engines/src/main/java/judgels/gabriel/aggregators/SumAggregator.java @@ -33,7 +33,11 @@ public AggregationResult aggregate(List testCaseVerdicts, doubl if (verdict == Verdict.ACCEPTED) { points = testCaseFullPoints; } else if (verdict == Verdict.OK) { - points = testCaseVerdict.getPoints().orElse(0.0); + if (testCaseVerdict.getPoints().isPresent()) { + points = testCaseVerdict.getPoints().get(); + } else if (testCaseVerdict.getPercentage().isPresent()) { + points = testCaseVerdict.getPercentage().get() * testCaseFullPoints / 100.0; + } } aggregatedPoints += points; diff --git a/judgels-backends/judgels-grader-engines/src/test/java/judgels/gabriel/aggregators/SumAggregatorTests.java b/judgels-backends/judgels-grader-engines/src/test/java/judgels/gabriel/aggregators/SumAggregatorTests.java index 0b3c92a22..d3ef833e6 100644 --- a/judgels-backends/judgels-grader-engines/src/test/java/judgels/gabriel/aggregators/SumAggregatorTests.java +++ b/judgels-backends/judgels-grader-engines/src/test/java/judgels/gabriel/aggregators/SumAggregatorTests.java @@ -43,6 +43,19 @@ void aggregate_partial_points() { assertThat(result.getTestCasePoints()).containsExactly("25", "0", "30", "0"); } + @Test + void aggregate_partial_percentage() { + List testCaseVerdicts = ImmutableList.of( + new TestCaseVerdict.Builder().verdict(Verdict.ACCEPTED).build(), + new TestCaseVerdict.Builder().verdict(Verdict.TIME_LIMIT_EXCEEDED).build(), + new TestCaseVerdict.Builder().verdict(Verdict.OK).percentage(50.0).build(), + new TestCaseVerdict.Builder().verdict(Verdict.WRONG_ANSWER).build()); + + AggregationResult result = aggregator.aggregate(testCaseVerdicts, 100.0); + assertThat(result.getSubtaskVerdict()).isEqualTo(SubtaskVerdict.of(Verdict.TIME_LIMIT_EXCEEDED, 37.5)); + assertThat(result.getTestCasePoints()).containsExactly("25", "0", "12.5", "0"); + } + @Test void aggregate_partial_points_with_skipped() { List testCaseVerdicts = ImmutableList.of(