diff --git a/lib/game/bloc/game_event.dart b/lib/game/bloc/game_event.dart index 7d3e3c91..0edc91ab 100644 --- a/lib/game/bloc/game_event.dart +++ b/lib/game/bloc/game_event.dart @@ -34,7 +34,11 @@ class Scored extends GameEvent { } class BonusLetterActivated extends GameEvent { - const BonusLetterActivated(this.letterIndex); + const BonusLetterActivated(this.letterIndex) + : assert( + letterIndex < GameBloc.bonusWord.length, + 'Index must be smaller than the length of the word', + ); final int letterIndex; diff --git a/test/game/bloc/game_event_test.dart b/test/game/bloc/game_event_test.dart index c21ecfba..d6d2278b 100644 --- a/test/game/bloc/game_event_test.dart +++ b/test/game/bloc/game_event_test.dart @@ -56,6 +56,16 @@ void main() { isNot(equals(BonusLetterActivated(1))), ); }); + + test( + 'throws assertion error if index is bigger than the word length', + () { + expect( + () => BonusLetterActivated(8), + throwsAssertionError, + ); + }, + ); }); }); }