Skip to content

Commit

Permalink
grader: Beautify score output
Browse files Browse the repository at this point in the history
  • Loading branch information
fushar committed Aug 16, 2024
1 parent 7e81e98 commit d94fb7a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ public AggregationResult aggregate(List<TestCaseVerdict> testCaseVerdicts, doubl
double okPoints = 0.0;
if (testCaseVerdict.getPercentage().isPresent()) {
okPoints = testCaseVerdict.getPercentage().get() * subtaskPoints / 100.0;
points = testCaseVerdict.getPercentage().get() + "%";
points = PointUtils.formatPoints(testCaseVerdict.getPercentage().get()) + "%";
} else if (testCaseVerdict.getPoints().isPresent()) {
okPoints = testCaseVerdict.getPoints().get();
points = "" + okPoints;
points = PointUtils.formatPoints(okPoints);
}
aggregatedPoints = Math.min(aggregatedPoints, okPoints);
} else if (verdict == Verdict.ACCEPTED) {
points = "*";
points = "";
} else if (verdict == Verdict.SKIPPED) {
aggregatedPoints = 0.0;
points = "?";
} else {
aggregatedPoints = 0.0;
points = "X";
points = "";
}

testCasePoints.add(points);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package judgels.gabriel.aggregators;

public class PointUtils {
private PointUtils() {}

public static String formatPoints(double pts) {
String result = "" + pts;
if (result.contains(".")) {
while (result.charAt(result.length() - 1) == '0') {
result = result.substring(0, result.length() - 1);
}
if (result.charAt(result.length() - 1) == '.') {
result = result.substring(0, result.length() - 1);
}
}
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public AggregationResult aggregate(List<TestCaseVerdict> testCaseVerdicts, doubl
}
aggregatedPoints += points;

testCasePoints.add("" + points);
testCasePoints.add(PointUtils.formatPoints(points));
}
if (aggregatedVerdict == Verdict.SKIPPED) {
aggregatedVerdict = Verdict.OK;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void aggregate_full_points() {

AggregationResult result = aggregator.aggregate(testCaseVerdicts, 70.0);
assertThat(result.getSubtaskVerdict()).isEqualTo(SubtaskVerdict.of(Verdict.ACCEPTED, 70.0));
assertThat(result.getTestCasePoints()).containsExactly("*", "*");
assertThat(result.getTestCasePoints()).containsExactly("", "");
}

@Test
Expand All @@ -39,7 +39,7 @@ void aggregate_zero_points() {

AggregationResult result = aggregator.aggregate(testCaseVerdicts, 70.0);
assertThat(result.getSubtaskVerdict()).isEqualTo(SubtaskVerdict.of(Verdict.RUNTIME_ERROR, 0.0));
assertThat(result.getTestCasePoints()).containsExactly("*", "X", "X");
assertThat(result.getTestCasePoints()).containsExactly("", "", "");
}

@Test
Expand All @@ -51,7 +51,7 @@ void aggregate_zero_points_with_skipped() {

AggregationResult result = aggregator.aggregate(testCaseVerdicts, 70.0);
assertThat(result.getSubtaskVerdict()).isEqualTo(SubtaskVerdict.of(Verdict.RUNTIME_ERROR, 0.0));
assertThat(result.getTestCasePoints()).containsExactly("*", "X", "?");
assertThat(result.getTestCasePoints()).containsExactly("", "", "?");
}

@Test
Expand All @@ -63,19 +63,19 @@ void aggregate_zero_points_with_accepted_and_skipped() {

AggregationResult result = aggregator.aggregate(testCaseVerdicts, 70.0);
assertThat(result.getSubtaskVerdict()).isEqualTo(SubtaskVerdict.of(Verdict.OK, 0.0));
assertThat(result.getTestCasePoints()).containsExactly("*", "*", "?");
assertThat(result.getTestCasePoints()).containsExactly("", "", "?");
}

@Test
void aggregate_min_ok_points() {
List<TestCaseVerdict> testCaseVerdicts = ImmutableList.of(
new TestCaseVerdict.Builder().verdict(Verdict.ACCEPTED).build(),
new TestCaseVerdict.Builder().verdict(Verdict.OK).points(20.0).build(),
new TestCaseVerdict.Builder().verdict(Verdict.OK).points(20.5).build(),
new TestCaseVerdict.Builder().verdict(Verdict.OK).points(30.0).build());

AggregationResult result = aggregator.aggregate(testCaseVerdicts, 70.0);
assertThat(result.getSubtaskVerdict()).isEqualTo(SubtaskVerdict.of(Verdict.OK, 20.0));
assertThat(result.getTestCasePoints()).containsExactly("*", "20.0", "30.0");
assertThat(result.getSubtaskVerdict()).isEqualTo(SubtaskVerdict.of(Verdict.OK, 20.5));
assertThat(result.getTestCasePoints()).containsExactly("", "20.5", "30");
}

@Test
Expand All @@ -87,7 +87,7 @@ void aggregate_min_ok_percentage() {

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

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void aggregate_full_points() {

AggregationResult result = aggregator.aggregate(testCaseVerdicts, 100.0);
assertThat(result.getSubtaskVerdict()).isEqualTo(SubtaskVerdict.of(Verdict.ACCEPTED, 100.0));
assertThat(result.getTestCasePoints()).containsExactly("50.0", "50.0");
assertThat(result.getTestCasePoints()).containsExactly("50", "50");
}

@Test
Expand All @@ -40,7 +40,7 @@ void aggregate_partial_points() {

AggregationResult result = aggregator.aggregate(testCaseVerdicts, 100.0);
assertThat(result.getSubtaskVerdict()).isEqualTo(SubtaskVerdict.of(Verdict.TIME_LIMIT_EXCEEDED, 55.0));
assertThat(result.getTestCasePoints()).containsExactly("25.0", "0.0", "30.0", "0.0");
assertThat(result.getTestCasePoints()).containsExactly("25", "0", "30", "0");
}

@Test
Expand All @@ -53,7 +53,7 @@ void aggregate_partial_points_with_skipped() {

AggregationResult result = aggregator.aggregate(testCaseVerdicts, 100.0);
assertThat(result.getSubtaskVerdict()).isEqualTo(SubtaskVerdict.of(Verdict.TIME_LIMIT_EXCEEDED, 50.0));
assertThat(result.getTestCasePoints()).containsExactly("25.0", "25.0", "0.0", "0.0");
assertThat(result.getTestCasePoints()).containsExactly("25", "25", "0", "0");
}

@Test
Expand All @@ -66,7 +66,7 @@ void aggregate_partial_points_with_accepted_and_skipped() {

AggregationResult result = aggregator.aggregate(testCaseVerdicts, 100.0);
assertThat(result.getSubtaskVerdict()).isEqualTo(SubtaskVerdict.of(Verdict.OK, 50.0));
assertThat(result.getTestCasePoints()).containsExactly("25.0", "25.0", "0.0", "0.0");
assertThat(result.getTestCasePoints()).containsExactly("25", "25", "0", "0");
}

@Test
Expand Down

0 comments on commit d94fb7a

Please sign in to comment.