Skip to content
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 @@ -63,15 +63,24 @@ boolean everyConsoleContains(String marker) {
int countOf(String marker) {
int total = 0;
for (String console : consoles) {
int from = 0;
while (true) {
int at = console.indexOf(marker, from);
if (at < 0) {
break;
}
total++;
from = at + marker.length();
}
total += countIn(console, marker);
}
return total;
}

/** How many times the marker appears in each participant's console. */
List<Integer> countsOf(String marker) {
List<Integer> counts = new ArrayList<>(consoles.size());
for (String console : consoles) {
counts.add(countIn(console, marker));
}
return counts;
}

private static int countIn(String text, String marker) {
int total = 0;
for (int from = 0; (from = text.indexOf(marker, from)) >= 0; from += marker.length()) {
total++;
}
return total;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,17 @@ void testEVT014_IntegrationPositive_SurvivorReceivesAnotherRobotsDeath() {
() -> "no survivor reported another robot's death on " + engine + " ("
+ outcome.summary() + ")"));
}

@Test
@DisplayName("EVT-014 negative: a survivor does not receive duplicate death notifications per round")
void testEVT014_IntegrationNegative_SurvivorDoesNotReceiveDuplicateDeathNotifications() {
assertOnBothEngines(ROBOT, SOURCE, (outcome, engine) -> {
for (int deaths : outcome.countsOf(OTHER_DEATH)) {
assertTrue(deaths <= configuredRounds(),
() -> "a participant received " + deaths + " other-robot death notifications on "
+ engine + ", more than once per configured round ("
+ outcome.summary() + ")");
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@ void testEVT004_IntegrationPositive_OwnDeathReachesTheDeathHandler() {
}

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

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

@Test
@DisplayName("EVT-012 negative: a participant's win handler is not reported more than once per round")
void testEVT012_IntegrationNegative_WinHandlerDoesNotRepeatWithinRounds() {
assertOnBothEngines(ROBOT, (outcome, engine) -> {
for (int wins : outcome.countsOf("Win!")) {
assertTrue(wins <= configuredRounds(),
() -> "a participant reported onWin " + wins + " times on " + engine
+ ", more than once per configured round (" + outcome.summary() + ")");
}
});
}

@Test
@DisplayName("EVT-011: round and battle completion reach their handlers on both engines")
void testEVT011_IntegrationPositive_RoundAndBattleCompletionReachTheirHandlers() {
Expand All @@ -77,9 +92,11 @@ void testEVT011_IntegrationNegative_RoundCompletionIsNotReportedMoreThanOncePerR
// the event once per participant to every participant would satisfy the positive
// test above and fail here, because it would double (or worse) the count below
// rather than merely clear a lower bound.
for (String console : outcome.consoles()) {
int rounds = countIn(console, "RoundEnded!");
int battles = countIn(console, "BattleEnded!");
var roundCounts = outcome.countsOf("RoundEnded!");
var battleCounts = outcome.countsOf("BattleEnded!");
for (int participant = 0; participant < outcome.consoles().size(); participant++) {
int rounds = roundCounts.get(participant);
int battles = battleCounts.get(participant);
assertTrue(battles == 1,
() -> "a participant reported the battle ending " + battles
+ " times on " + engine);
Expand All @@ -89,12 +106,4 @@ void testEVT011_IntegrationNegative_RoundCompletionIsNotReportedMoreThanOncePerR
}
});
}

private static int countIn(String text, String marker) {
int total = 0;
for (int from = 0; (from = text.indexOf(marker, from)) >= 0; from += marker.length()) {
total++;
}
return total;
}
}
Loading