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() { void main() {
group('GameBloc', () { 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(); final gameBloc = GameBloc();
expect(gameBloc.state.score, equals(0)); expect(gameBloc.state.score, equals(0));
expect(gameBloc.state.balls, equals(0));
expect(gameBloc.state.rounds, equals(3)); expect(gameBloc.state.rounds, equals(3));
}); });
group('BallAdded', () { group('RoundLost', () {
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: [],
),
],
);
blocTest<GameBloc, GameState>( blocTest<GameBloc, GameState>(
'decreases number of rounds ' 'decreases number of rounds '
'when there are no more balls in current round', 'when there are already available rounds',
build: GameBloc.new, build: GameBloc.new,
act: (bloc) { act: (bloc) {
bloc.add(const BallLost()); bloc.add(const RoundLost());
}, },
expect: () => [ expect: () => [
const GameState( const GameState(
score: 0, score: 0,
multiplier: 1, multiplier: 1,
balls: 0,
rounds: 2, rounds: 2,
bonusHistory: [], bonusHistory: [],
), ),
@ -81,12 +35,11 @@ void main() {
seed: () => const GameState( seed: () => const GameState(
score: 5, score: 5,
multiplier: 3, multiplier: 3,
balls: 1,
rounds: 2, rounds: 2,
bonusHistory: [], bonusHistory: [],
), ),
act: (bloc) { act: (bloc) {
bloc.add(const BallLost()); bloc.add(const RoundLost());
}, },
expect: () => [ expect: () => [
isA<GameState>() isA<GameState>()
@ -102,12 +55,11 @@ void main() {
seed: () => const GameState( seed: () => const GameState(
score: 5, score: 5,
multiplier: 3, multiplier: 3,
balls: 1,
rounds: 2, rounds: 2,
bonusHistory: [], bonusHistory: [],
), ),
act: (bloc) { act: (bloc) {
bloc.add(const BallLost()); bloc.add(const RoundLost());
}, },
expect: () => [ expect: () => [
isA<GameState>() isA<GameState>()
@ -141,7 +93,7 @@ void main() {
build: GameBloc.new, build: GameBloc.new,
act: (bloc) { act: (bloc) {
for (var i = 0; i < bloc.state.rounds; i++) { for (var i = 0; i < bloc.state.rounds; i++) {
bloc.add(const BallLost()); bloc.add(const RoundLost());
} }
bloc.add(const Scored(points: 2)); bloc.add(const Scored(points: 2));
}, },
@ -189,7 +141,6 @@ void main() {
seed: () => const GameState( seed: () => const GameState(
score: 0, score: 0,
multiplier: 6, multiplier: 6,
balls: 1,
rounds: 3, rounds: 3,
bonusHistory: [], bonusHistory: [],
), ),
@ -203,7 +154,7 @@ void main() {
build: GameBloc.new, build: GameBloc.new,
act: (bloc) { act: (bloc) {
for (var i = 0; i < bloc.state.rounds; i++) { for (var i = 0; i < bloc.state.rounds; i++) {
bloc.add(const BallLost()); bloc.add(const RoundLost());
} }
bloc.add(const MultiplierIncreased()); bloc.add(const MultiplierIncreased());
}, },

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

@ -10,7 +10,6 @@ void main() {
GameState( GameState(
score: 0, score: 0,
multiplier: 1, multiplier: 1,
balls: 0,
rounds: 3, rounds: 3,
bonusHistory: const [], bonusHistory: const [],
), ),
@ -18,7 +17,6 @@ void main() {
const GameState( const GameState(
score: 0, score: 0,
multiplier: 1, multiplier: 1,
balls: 0,
rounds: 3, rounds: 3,
bonusHistory: [], bonusHistory: [],
), ),
@ -32,7 +30,6 @@ void main() {
const GameState( const GameState(
score: 0, score: 0,
multiplier: 1, multiplier: 1,
balls: 0,
rounds: 3, rounds: 3,
bonusHistory: [], 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( test(
'throws AssertionError ' 'throws AssertionError '
'when score is negative', 'when score is negative',
@ -66,7 +46,6 @@ void main() {
() => GameState( () => GameState(
score: -1, score: -1,
multiplier: 1, multiplier: 1,
balls: 0,
rounds: 3, rounds: 3,
bonusHistory: const [], bonusHistory: const [],
), ),
@ -83,7 +62,6 @@ void main() {
() => GameState( () => GameState(
score: 1, score: 1,
multiplier: 0, multiplier: 0,
balls: 0,
rounds: 3, rounds: 3,
bonusHistory: const [], bonusHistory: const [],
), ),
@ -100,7 +78,6 @@ void main() {
() => GameState( () => GameState(
score: 1, score: 1,
multiplier: 1, multiplier: 1,
balls: 0,
rounds: -1, rounds: -1,
bonusHistory: const [], 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', () { group('isGameOver', () {
test( test(
'is true ' 'is true '
@ -144,7 +93,6 @@ void main() {
const gameState = GameState( const gameState = GameState(
score: 0, score: 0,
multiplier: 1, multiplier: 1,
balls: 0,
rounds: 0, rounds: 0,
bonusHistory: [], bonusHistory: [],
); );
@ -157,7 +105,6 @@ void main() {
const gameState = GameState( const gameState = GameState(
score: 0, score: 0,
multiplier: 1, multiplier: 1,
balls: 0,
rounds: 1, rounds: 1,
bonusHistory: [], bonusHistory: [],
); );
@ -173,7 +120,6 @@ void main() {
const gameState = GameState( const gameState = GameState(
score: 2, score: 2,
multiplier: 1, multiplier: 1,
balls: 0,
rounds: 3, rounds: 3,
bonusHistory: [], bonusHistory: [],
); );
@ -191,7 +137,6 @@ void main() {
const gameState = GameState( const gameState = GameState(
score: 2, score: 2,
multiplier: 1, multiplier: 1,
balls: 0,
rounds: 3, rounds: 3,
bonusHistory: [], bonusHistory: [],
); );
@ -209,14 +154,12 @@ void main() {
const gameState = GameState( const gameState = GameState(
score: 2, score: 2,
multiplier: 1, multiplier: 1,
balls: 0,
rounds: 3, rounds: 3,
bonusHistory: [], bonusHistory: [],
); );
final otherGameState = GameState( final otherGameState = GameState(
score: gameState.score + 1, score: gameState.score + 1,
multiplier: gameState.multiplier + 1, multiplier: gameState.multiplier + 1,
balls: gameState.balls + 1,
rounds: gameState.rounds + 1, rounds: gameState.rounds + 1,
bonusHistory: const [GameBonus.googleWord], bonusHistory: const [GameBonus.googleWord],
); );
@ -226,7 +169,6 @@ void main() {
gameState.copyWith( gameState.copyWith(
score: otherGameState.score, score: otherGameState.score,
multiplier: otherGameState.multiplier, multiplier: otherGameState.multiplier,
balls: otherGameState.balls,
rounds: otherGameState.rounds, rounds: otherGameState.rounds,
bonusHistory: otherGameState.bonusHistory, bonusHistory: otherGameState.bonusHistory,
), ),

Loading…
Cancel
Save