test: tests for RoundLost

pull/213/head
RuiAlonso 3 years ago
parent f5495a2d52
commit 3495c6dbf1

@ -4,70 +4,24 @@ import 'package:pinball/game/game.dart';
void main() {
group('GameBloc', () {
test('initial state has 3 rounds, 0 ball and empty score', () {
test('initial state has 3 rounds and empty score', () {
final gameBloc = GameBloc();
expect(gameBloc.state.score, equals(0));
expect(gameBloc.state.balls, equals(0));
expect(gameBloc.state.rounds, equals(3));
});
group('BallAdded', () {
blocTest<GameBloc, GameState>(
'increases number of balls',
build: GameBloc.new,
act: (bloc) {
bloc.add(const BallAdded());
},
expect: () => [
const GameState(
score: 0,
multiplier: 1,
balls: 1,
rounds: 3,
bonusHistory: [],
),
],
);
});
group('BallLost', () {
blocTest<GameBloc, GameState>(
'decreases only number of balls '
'when there are more than 1',
build: GameBloc.new,
seed: () => const GameState(
score: 0,
multiplier: 1,
balls: 3,
rounds: 3,
bonusHistory: [],
),
act: (bloc) {
bloc.add(const BallLost());
},
expect: () => [
const GameState(
score: 0,
multiplier: 1,
balls: 2,
rounds: 3,
bonusHistory: [],
),
],
);
group('RoundLost', () {
blocTest<GameBloc, GameState>(
'decreases number of rounds '
'when there are no more balls in current round',
'when there are already available rounds',
build: GameBloc.new,
act: (bloc) {
bloc.add(const BallLost());
bloc.add(const RoundLost());
},
expect: () => [
const GameState(
score: 0,
multiplier: 1,
balls: 0,
rounds: 2,
bonusHistory: [],
),
@ -81,12 +35,11 @@ void main() {
seed: () => const GameState(
score: 5,
multiplier: 3,
balls: 1,
rounds: 2,
bonusHistory: [],
),
act: (bloc) {
bloc.add(const BallLost());
bloc.add(const RoundLost());
},
expect: () => [
isA<GameState>()
@ -102,12 +55,11 @@ void main() {
seed: () => const GameState(
score: 5,
multiplier: 3,
balls: 1,
rounds: 2,
bonusHistory: [],
),
act: (bloc) {
bloc.add(const BallLost());
bloc.add(const RoundLost());
},
expect: () => [
isA<GameState>()
@ -141,7 +93,7 @@ void main() {
build: GameBloc.new,
act: (bloc) {
for (var i = 0; i < bloc.state.rounds; i++) {
bloc.add(const BallLost());
bloc.add(const RoundLost());
}
bloc.add(const Scored(points: 2));
},
@ -189,7 +141,6 @@ void main() {
seed: () => const GameState(
score: 0,
multiplier: 6,
balls: 1,
rounds: 3,
bonusHistory: [],
),
@ -203,7 +154,7 @@ void main() {
build: GameBloc.new,
act: (bloc) {
for (var i = 0; i < bloc.state.rounds; i++) {
bloc.add(const BallLost());
bloc.add(const RoundLost());
}
bloc.add(const MultiplierIncreased());
},

@ -5,28 +5,15 @@ import 'package:pinball/game/game.dart';
void main() {
group('GameEvent', () {
group('BallAdded', () {
group('RoundLost', () {
test('can be instantiated', () {
expect(const BallAdded(), isNotNull);
expect(const RoundLost(), isNotNull);
});
test('supports value equality', () {
expect(
BallAdded(),
equals(const BallAdded()),
);
});
});
group('BallLost', () {
test('can be instantiated', () {
expect(const BallLost(), isNotNull);
});
test('supports value equality', () {
expect(
BallLost(),
equals(const BallLost()),
RoundLost(),
equals(const RoundLost()),
);
});
});

@ -10,7 +10,6 @@ void main() {
GameState(
score: 0,
multiplier: 1,
balls: 0,
rounds: 3,
bonusHistory: const [],
),
@ -18,7 +17,6 @@ void main() {
const GameState(
score: 0,
multiplier: 1,
balls: 0,
rounds: 3,
bonusHistory: [],
),
@ -32,7 +30,6 @@ void main() {
const GameState(
score: 0,
multiplier: 1,
balls: 0,
rounds: 3,
bonusHistory: [],
),
@ -41,23 +38,6 @@ void main() {
});
});
test(
'throws AssertionError '
'when balls are negative',
() {
expect(
() => GameState(
score: 0,
multiplier: 1,
balls: -1,
rounds: 3,
bonusHistory: const [],
),
throwsAssertionError,
);
},
);
test(
'throws AssertionError '
'when score is negative',
@ -66,7 +46,6 @@ void main() {
() => GameState(
score: -1,
multiplier: 1,
balls: 0,
rounds: 3,
bonusHistory: const [],
),
@ -83,7 +62,6 @@ void main() {
() => GameState(
score: 1,
multiplier: 0,
balls: 0,
rounds: 3,
bonusHistory: const [],
),
@ -100,7 +78,6 @@ void main() {
() => GameState(
score: 1,
multiplier: 1,
balls: 0,
rounds: -1,
bonusHistory: const [],
),
@ -109,34 +86,6 @@ void main() {
},
);
group('isRoundOver', () {
test(
'is true '
'when no balls are left', () {
const gameState = GameState(
score: 0,
multiplier: 1,
balls: 0,
rounds: 1,
bonusHistory: [],
);
expect(gameState.isRoundOver, isTrue);
});
test(
'is false '
'when one 1 ball left', () {
const gameState = GameState(
score: 0,
multiplier: 1,
balls: 1,
rounds: 0,
bonusHistory: [],
);
expect(gameState.isRoundOver, isFalse);
});
});
group('isGameOver', () {
test(
'is true '
@ -144,7 +93,6 @@ void main() {
const gameState = GameState(
score: 0,
multiplier: 1,
balls: 0,
rounds: 0,
bonusHistory: [],
);
@ -157,7 +105,6 @@ void main() {
const gameState = GameState(
score: 0,
multiplier: 1,
balls: 0,
rounds: 1,
bonusHistory: [],
);
@ -173,7 +120,6 @@ void main() {
const gameState = GameState(
score: 2,
multiplier: 1,
balls: 0,
rounds: 3,
bonusHistory: [],
);
@ -191,7 +137,6 @@ void main() {
const gameState = GameState(
score: 2,
multiplier: 1,
balls: 0,
rounds: 3,
bonusHistory: [],
);
@ -209,14 +154,12 @@ void main() {
const gameState = GameState(
score: 2,
multiplier: 1,
balls: 0,
rounds: 3,
bonusHistory: [],
);
final otherGameState = GameState(
score: gameState.score + 1,
multiplier: gameState.multiplier + 1,
balls: gameState.balls + 1,
rounds: gameState.rounds + 1,
bonusHistory: const [GameBonus.googleWord],
);
@ -226,7 +169,6 @@ void main() {
gameState.copyWith(
score: otherGameState.score,
multiplier: otherGameState.multiplier,
balls: otherGameState.balls,
rounds: otherGameState.rounds,
bonusHistory: otherGameState.bonusHistory,
),

Loading…
Cancel
Save