Skip to content

Commit 5391790

Browse files
Merge pull request #11 from robocode-dev/fix/evt-004-death-count
Strengthen round outcome conformance evidence
2 parents 7115fc9 + 813895b commit 5391790

3 files changed

Lines changed: 57 additions & 26 deletions

File tree

conformance-test/src/test/java/dev/robocode/tankroyale/bridge/conformance/BattleOutcome.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,24 @@ boolean everyConsoleContains(String marker) {
6363
int countOf(String marker) {
6464
int total = 0;
6565
for (String console : consoles) {
66-
int from = 0;
67-
while (true) {
68-
int at = console.indexOf(marker, from);
69-
if (at < 0) {
70-
break;
71-
}
72-
total++;
73-
from = at + marker.length();
74-
}
66+
total += countIn(console, marker);
67+
}
68+
return total;
69+
}
70+
71+
/** How many times the marker appears in each participant's console. */
72+
List<Integer> countsOf(String marker) {
73+
List<Integer> counts = new ArrayList<>(consoles.size());
74+
for (String console : consoles) {
75+
counts.add(countIn(console, marker));
76+
}
77+
return counts;
78+
}
79+
80+
private static int countIn(String text, String marker) {
81+
int total = 0;
82+
for (int from = 0; (from = text.indexOf(marker, from)) >= 0; from += marker.length()) {
83+
total++;
7584
}
7685
return total;
7786
}

conformance-test/src/test/java/dev/robocode/tankroyale/bridge/conformance/RobotDeathEventsConformanceTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,17 @@ void testEVT014_IntegrationPositive_SurvivorReceivesAnotherRobotsDeath() {
2323
() -> "no survivor reported another robot's death on " + engine + " ("
2424
+ outcome.summary() + ")"));
2525
}
26+
27+
@Test
28+
@DisplayName("EVT-014 negative: a survivor does not receive duplicate death notifications per round")
29+
void testEVT014_IntegrationNegative_SurvivorDoesNotReceiveDuplicateDeathNotifications() {
30+
assertOnBothEngines(ROBOT, SOURCE, (outcome, engine) -> {
31+
for (int deaths : outcome.countsOf(OTHER_DEATH)) {
32+
assertTrue(deaths <= configuredRounds(),
33+
() -> "a participant received " + deaths + " other-robot death notifications on "
34+
+ engine + ", more than once per configured round ("
35+
+ outcome.summary() + ")");
36+
}
37+
});
38+
}
2639
}

conformance-test/src/test/java/dev/robocode/tankroyale/bridge/conformance/RoundOutcomeEventsConformanceTest.java

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,15 @@ void testEVT004_IntegrationPositive_OwnDeathReachesTheDeathHandler() {
4141
}
4242

4343
@Test
44-
@DisplayName("EVT-004 negative: each destruction reaches onDeath once, not repeatedly")
45-
void testEVT004_IntegrationNegative_DeathHandlerDoesNotRepeatForOneDestruction() {
46-
assertOnBothEngines(ROBOT, (outcome, engine) ->
47-
assertTrue(outcome.countOf("Death!") == configuredRounds(),
48-
() -> "onDeath was reported other than once per destroyed robot on " + engine
49-
+ " (" + outcome.summary() + ")"));
44+
@DisplayName("EVT-004 negative: a participant's onDeath is not reported more than once per round")
45+
void testEVT004_IntegrationNegative_DeathHandlerDoesNotRepeatWithinRounds() {
46+
assertOnBothEngines(ROBOT, (outcome, engine) -> {
47+
for (int deaths : outcome.countsOf("Death!")) {
48+
assertTrue(deaths <= configuredRounds(),
49+
() -> "a participant reported onDeath " + deaths + " times on " + engine
50+
+ ", more than once per configured round (" + outcome.summary() + ")");
51+
}
52+
});
5053
}
5154

5255
@Test
@@ -57,6 +60,18 @@ void testEVT012_IntegrationPositive_WinningARoundReachesTheWinHandler() {
5760
() -> "no robot reported winning on " + engine + " (" + outcome.summary() + ")"));
5861
}
5962

63+
@Test
64+
@DisplayName("EVT-012 negative: a participant's win handler is not reported more than once per round")
65+
void testEVT012_IntegrationNegative_WinHandlerDoesNotRepeatWithinRounds() {
66+
assertOnBothEngines(ROBOT, (outcome, engine) -> {
67+
for (int wins : outcome.countsOf("Win!")) {
68+
assertTrue(wins <= configuredRounds(),
69+
() -> "a participant reported onWin " + wins + " times on " + engine
70+
+ ", more than once per configured round (" + outcome.summary() + ")");
71+
}
72+
});
73+
}
74+
6075
@Test
6176
@DisplayName("EVT-011: round and battle completion reach their handlers on both engines")
6277
void testEVT011_IntegrationPositive_RoundAndBattleCompletionReachTheirHandlers() {
@@ -77,9 +92,11 @@ void testEVT011_IntegrationNegative_RoundCompletionIsNotReportedMoreThanOncePerR
7792
// the event once per participant to every participant would satisfy the positive
7893
// test above and fail here, because it would double (or worse) the count below
7994
// rather than merely clear a lower bound.
80-
for (String console : outcome.consoles()) {
81-
int rounds = countIn(console, "RoundEnded!");
82-
int battles = countIn(console, "BattleEnded!");
95+
var roundCounts = outcome.countsOf("RoundEnded!");
96+
var battleCounts = outcome.countsOf("BattleEnded!");
97+
for (int participant = 0; participant < outcome.consoles().size(); participant++) {
98+
int rounds = roundCounts.get(participant);
99+
int battles = battleCounts.get(participant);
83100
assertTrue(battles == 1,
84101
() -> "a participant reported the battle ending " + battles
85102
+ " times on " + engine);
@@ -89,12 +106,4 @@ void testEVT011_IntegrationNegative_RoundCompletionIsNotReportedMoreThanOncePerR
89106
}
90107
});
91108
}
92-
93-
private static int countIn(String text, String marker) {
94-
int total = 0;
95-
for (int from = 0; (from = text.indexOf(marker, from)) >= 0; from += marker.length()) {
96-
total++;
97-
}
98-
return total;
99-
}
100109
}

0 commit comments

Comments
 (0)