@@ -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