feat: tested and improved GameEvent

pull/3/head
alestiago 4 years ago
parent 0e75c4a3b8
commit 7ed1a6e33d

@ -5,12 +5,16 @@ abstract class GameEvent {
const GameEvent(); const GameEvent();
} }
/// Event added when a user drops a ball off the screen.
class BallLost extends GameEvent { class BallLost extends GameEvent {
const BallLost(); const BallLost();
} }
/// Event added when a user increases it's score.
class Scored extends GameEvent { class Scored extends GameEvent {
const Scored(this.points); const Scored({
required this.points,
}) : assert(points > 0, 'Points must be greater than 0');
final int points; final int points;
} }

@ -0,0 +1,24 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pinball/game/game.dart';
void main() {
group('GameEvent', () {
group('BallLost', () {
test('BallLost can be instantiated', () {
expect(const BallLost(), isNotNull);
});
});
group('Scored', () {
test('Scored can be instantiated', () {
expect(const Scored(points: 1), isNotNull);
});
test(
'throws AssertionError '
'when score is smaller than 1', () {
expect(() => Scored(points: 0), throwsAssertionError);
});
});
});
}
Loading…
Cancel
Save