From d6fe78df28e797aa7dfe544f40f1383da5a9a6fb Mon Sep 17 00:00:00 2001 From: alestiago Date: Mon, 28 Feb 2022 21:29:26 +0000 Subject: [PATCH] feat: made GameEvent support value equality --- lib/game/bloc/game_event.dart | 8 +++++++- test/game/bloc/game_event_test.dart | 8 ++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/game/bloc/game_event.dart b/lib/game/bloc/game_event.dart index 03d0984d..88ef265b 100644 --- a/lib/game/bloc/game_event.dart +++ b/lib/game/bloc/game_event.dart @@ -1,13 +1,16 @@ part of 'game_bloc.dart'; @immutable -abstract class GameEvent { +abstract class GameEvent extends Equatable { const GameEvent(); } /// Event added when a user drops a ball off the screen. class BallLost extends GameEvent { const BallLost(); + + @override + List get props => []; } /// Event added when a user increases their score. @@ -17,4 +20,7 @@ class Scored extends GameEvent { }) : assert(points > 0, 'Points must be greater than 0'); final int points; + + @override + List get props => [points]; } diff --git a/test/game/bloc/game_event_test.dart b/test/game/bloc/game_event_test.dart index 3e2ef74f..ae84aeff 100644 --- a/test/game/bloc/game_event_test.dart +++ b/test/game/bloc/game_event_test.dart @@ -7,6 +7,10 @@ void main() { test('can be instantiated', () { expect(const BallLost(), isNotNull); }); + + test('supports value equality', () { + expect(const BallLost(), equals(const BallLost())); + }); }); group('Scored', () { @@ -14,6 +18,10 @@ void main() { expect(const Scored(points: 1), isNotNull); }); + test('supports value equality', () { + expect(const Scored(points: 1), equals(const Scored(points: 1))); + }); + test( 'throws AssertionError ' 'when score is smaller than 1', () {