test: test for multiplier at game bloc

pull/213/head
RuiAlonso 3 years ago
parent 6ae228b4e2
commit c7a766d0ca

@ -20,6 +20,7 @@ void main() {
expect: () => [
const GameState(
score: 0,
multiplier: 1,
balls: 2,
bonusHistory: [],
),
@ -38,11 +39,13 @@ void main() {
expect: () => [
const GameState(
score: 2,
multiplier: 1,
balls: 3,
bonusHistory: [],
),
const GameState(
score: 5,
multiplier: 1,
balls: 3,
bonusHistory: [],
),
@ -62,16 +65,19 @@ void main() {
expect: () => [
const GameState(
score: 0,
multiplier: 1,
balls: 2,
bonusHistory: [],
),
const GameState(
score: 0,
multiplier: 1,
balls: 1,
bonusHistory: [],
),
const GameState(
score: 0,
multiplier: 1,
balls: 0,
bonusHistory: [],
),
@ -79,6 +85,110 @@ void main() {
);
});
group('IncreasedMultiplier', () {
blocTest<GameBloc, GameState>(
'increases multiplier '
'when game is not over',
build: GameBloc.new,
act: (bloc) => bloc
..add(const IncreasedMultiplier(increase: 1))
..add(const IncreasedMultiplier(increase: 1)),
expect: () => [
const GameState(
score: 0,
multiplier: 2,
balls: 3,
bonusHistory: [],
),
const GameState(
score: 0,
multiplier: 3,
balls: 3,
bonusHistory: [],
),
],
);
blocTest<GameBloc, GameState>(
"doesn't increase multiplier "
'when game is over',
build: GameBloc.new,
act: (bloc) {
for (var i = 0; i < bloc.state.balls; i++) {
bloc.add(const BallLost());
}
bloc.add(const IncreasedMultiplier(increase: 1));
},
expect: () => [
const GameState(
score: 0,
multiplier: 1,
balls: 2,
bonusHistory: [],
),
const GameState(
score: 0,
multiplier: 1,
balls: 1,
bonusHistory: [],
),
const GameState(
score: 0,
multiplier: 1,
balls: 0,
bonusHistory: [],
),
],
);
});
group('AppliedMultiplier', () {
blocTest<GameBloc, GameState>(
'apply multiplier to score',
build: GameBloc.new,
seed: () => const GameState(
score: 5,
multiplier: 3,
balls: 2,
bonusHistory: [],
),
act: (bloc) {
bloc.add(const AppliedMultiplier());
},
expect: () => [
const GameState(
score: 15,
multiplier: 3,
balls: 2,
bonusHistory: [],
),
],
);
});
group('ResetMultiplier', () {
blocTest<GameBloc, GameState>(
'resets multiplier',
build: GameBloc.new,
seed: () => const GameState(
score: 0,
multiplier: 3,
balls: 2,
bonusHistory: [],
),
act: (bloc) {
bloc.add(const ResetMultiplier());
},
expect: () => [
const GameState(
score: 0,
multiplier: 1,
balls: 2,
bonusHistory: [],
),
],
);
});
group(
'BonusActivated',
() {
@ -91,11 +201,13 @@ void main() {
expect: () => const [
GameState(
score: 0,
multiplier: 1,
balls: 3,
bonusHistory: [GameBonus.googleWord],
),
GameState(
score: 0,
multiplier: 1,
balls: 3,
bonusHistory: [GameBonus.googleWord, GameBonus.dashNest],
),
@ -112,6 +224,7 @@ void main() {
expect: () => const [
GameState(
score: 0,
multiplier: 1,
balls: 3,
bonusHistory: [GameBonus.sparkyTurboCharge],
),

@ -41,6 +41,55 @@ void main() {
});
});
group('IncreasedMultiplier', () {
test('can be instantiated', () {
expect(const IncreasedMultiplier(increase: 1), isNotNull);
});
test('supports value equality', () {
expect(
IncreasedMultiplier(increase: 1),
equals(const IncreasedMultiplier(increase: 1)),
);
expect(
const IncreasedMultiplier(increase: 1),
isNot(equals(const IncreasedMultiplier(increase: 2))),
);
});
test(
'throws AssertionError '
'when increase is smaller than 1', () {
expect(() => IncreasedMultiplier(increase: 0), throwsAssertionError);
});
});
group('AppliedMultiplier', () {
test('can be instantiated', () {
expect(const AppliedMultiplier(), isNotNull);
});
test('supports value equality', () {
expect(
AppliedMultiplier(),
equals(const AppliedMultiplier()),
);
});
});
group('ResetMultiplier', () {
test('can be instantiated', () {
expect(const ResetMultiplier(), isNotNull);
});
test('supports value equality', () {
expect(
ResetMultiplier(),
equals(const ResetMultiplier()),
);
});
});
group('BonusActivated', () {
test('can be instantiated', () {
expect(const BonusActivated(GameBonus.dashNest), isNotNull);

@ -9,12 +9,14 @@ void main() {
expect(
GameState(
score: 0,
multiplier: 1,
balls: 0,
bonusHistory: const [],
),
equals(
const GameState(
score: 0,
multiplier: 1,
balls: 0,
bonusHistory: [],
),
@ -27,6 +29,7 @@ void main() {
expect(
const GameState(
score: 0,
multiplier: 1,
balls: 0,
bonusHistory: [],
),
@ -43,6 +46,7 @@ void main() {
() => GameState(
balls: -1,
score: 0,
multiplier: 1,
bonusHistory: const [],
),
throwsAssertionError,
@ -58,6 +62,23 @@ void main() {
() => GameState(
balls: 0,
score: -1,
multiplier: 1,
bonusHistory: const [],
),
throwsAssertionError,
);
},
);
test(
'throws AssertionError '
'when multiplier is less than 1',
() {
expect(
() => GameState(
balls: 0,
score: 1,
multiplier: 0,
bonusHistory: const [],
),
throwsAssertionError,
@ -72,6 +93,7 @@ void main() {
const gameState = GameState(
balls: 0,
score: 0,
multiplier: 1,
bonusHistory: [],
);
expect(gameState.isGameOver, isTrue);
@ -83,6 +105,7 @@ void main() {
const gameState = GameState(
balls: 1,
score: 0,
multiplier: 1,
bonusHistory: [],
);
expect(gameState.isGameOver, isFalse);
@ -97,6 +120,7 @@ void main() {
const gameState = GameState(
balls: 0,
score: 2,
multiplier: 1,
bonusHistory: [],
);
expect(
@ -113,6 +137,7 @@ void main() {
const gameState = GameState(
balls: 0,
score: 2,
multiplier: 1,
bonusHistory: [],
);
expect(
@ -128,11 +153,13 @@ void main() {
() {
const gameState = GameState(
score: 2,
multiplier: 1,
balls: 0,
bonusHistory: [],
);
final otherGameState = GameState(
score: gameState.score + 1,
multiplier: gameState.multiplier + 1,
balls: gameState.balls + 1,
bonusHistory: const [GameBonus.googleWord],
);
@ -141,6 +168,7 @@ void main() {
expect(
gameState.copyWith(
score: otherGameState.score,
multiplier: otherGameState.multiplier,
balls: otherGameState.balls,
bonusHistory: otherGameState.bonusHistory,
),

Loading…
Cancel
Save