You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pinball/test/game/bloc/game_state_test.dart

208 lines
5.0 KiB

// ignore_for_file: prefer_const_constructors
import 'package:flutter_test/flutter_test.dart';
import 'package:pinball/game/game.dart';
void main() {
group('GameState', () {
test('supports value equality', () {
expect(
GameState(
score: 0,
balls: 0,
activatedBonusLetters: const [],
activatedDashNests: const {},
bonusHistory: const [],
),
equals(
const GameState(
score: 0,
balls: 0,
activatedBonusLetters: [],
activatedDashNests: {},
bonusHistory: [],
),
),
);
});
group('constructor', () {
test('can be instantiated', () {
expect(
const GameState(
score: 0,
balls: 0,
activatedBonusLetters: [],
activatedDashNests: {},
bonusHistory: [],
),
isNotNull,
);
});
});
test(
'throws AssertionError '
'when balls are negative',
() {
expect(
() => GameState(
balls: -1,
score: 0,
activatedBonusLetters: const [],
activatedDashNests: const {},
bonusHistory: const [],
),
throwsAssertionError,
);
},
);
test(
'throws AssertionError '
'when score is negative',
() {
expect(
() => GameState(
balls: 0,
score: -1,
activatedBonusLetters: const [],
activatedDashNests: const {},
bonusHistory: const [],
),
throwsAssertionError,
);
},
);
group('isGameOver', () {
test(
'is true '
'when no balls are left', () {
const gameState = GameState(
balls: 0,
score: 0,
activatedBonusLetters: [],
activatedDashNests: {},
bonusHistory: [],
);
expect(gameState.isGameOver, isTrue);
});
test(
'is false '
'when one 1 ball left', () {
const gameState = GameState(
balls: 1,
score: 0,
activatedBonusLetters: [],
activatedDashNests: {},
bonusHistory: [],
);
expect(gameState.isGameOver, isFalse);
});
});
group('isLetterActivated', () {
test(
'is true when the letter is activated',
() {
const gameState = GameState(
balls: 3,
score: 0,
activatedBonusLetters: [1],
activatedDashNests: {},
bonusHistory: [],
);
expect(gameState.isLetterActivated(1), isTrue);
},
);
test(
'is false when the letter is not activated',
() {
const gameState = GameState(
balls: 3,
score: 0,
activatedBonusLetters: [1],
activatedDashNests: {},
bonusHistory: [],
);
expect(gameState.isLetterActivated(0), isFalse);
},
);
});
group('copyWith', () {
test(
'throws AssertionError '
'when scored is decreased',
() {
const gameState = GameState(
balls: 0,
score: 2,
activatedBonusLetters: [],
activatedDashNests: {},
bonusHistory: [],
);
expect(
() => gameState.copyWith(score: gameState.score - 1),
throwsAssertionError,
);
},
);
test(
'copies correctly '
refactor: Pathway to Shapes (#87) * refactor: removed findNested extensions (#77) * refactor: changed Pathway for Shapes * refactor: renamed pathway to shape * refactor: moved shapes to components package * fix: fixed arc radius on shapes * refactor: changed jetpack to shapes * refactor: modified jetpack ramp to use shapes and blueprint * refactor: launcher ramp * test: removed unnecessary tests for ramps * refactor: refactored baseboard with arcshapes * chore: doc refactor * test: coverage tests * refactor: refactored launcher ramp * test: tests for shapes * test: added removed ellipse tests * test: arcshape coverage * test: unnecessary tests removed * chore: params names * chore: modified doc for Layered and added one test for nested * test: changed tests names * test: not layered nested children * refactor: moved static param and made other private on ramps * Update lib/game/components/jetpack_ramp.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/components/jetpack_ramp.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/components/launcher_ramp.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * chore: renamed straight path vars * Update packages/pinball_components/lib/src/components/shapes/arc_shape.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * refactor: constructors with rotation instead of separated method * test: refactored tests * refactor: moved rotate to separate method * refactor: rotation on shapes Co-authored-by: RuiAlonso <rui.alonso@verygood.ventures> Co-authored-by: Rui Miguel Alonso <ruiskas@gmail.com> Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com>
3 years ago
'when no argument specified',
() {
const gameState = GameState(
balls: 0,
score: 2,
activatedBonusLetters: [],
activatedDashNests: {},
bonusHistory: [],
);
expect(
gameState.copyWith(),
equals(gameState),
);
},
);
test(
'copies correctly '
refactor: Pathway to Shapes (#87) * refactor: removed findNested extensions (#77) * refactor: changed Pathway for Shapes * refactor: renamed pathway to shape * refactor: moved shapes to components package * fix: fixed arc radius on shapes * refactor: changed jetpack to shapes * refactor: modified jetpack ramp to use shapes and blueprint * refactor: launcher ramp * test: removed unnecessary tests for ramps * refactor: refactored baseboard with arcshapes * chore: doc refactor * test: coverage tests * refactor: refactored launcher ramp * test: tests for shapes * test: added removed ellipse tests * test: arcshape coverage * test: unnecessary tests removed * chore: params names * chore: modified doc for Layered and added one test for nested * test: changed tests names * test: not layered nested children * refactor: moved static param and made other private on ramps * Update lib/game/components/jetpack_ramp.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/components/jetpack_ramp.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/components/launcher_ramp.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * chore: renamed straight path vars * Update packages/pinball_components/lib/src/components/shapes/arc_shape.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * refactor: constructors with rotation instead of separated method * test: refactored tests * refactor: moved rotate to separate method * refactor: rotation on shapes Co-authored-by: RuiAlonso <rui.alonso@verygood.ventures> Co-authored-by: Rui Miguel Alonso <ruiskas@gmail.com> Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com>
3 years ago
'when all arguments specified',
() {
const gameState = GameState(
score: 2,
balls: 0,
activatedBonusLetters: [],
activatedDashNests: {},
bonusHistory: [],
);
final otherGameState = GameState(
score: gameState.score + 1,
balls: gameState.balls + 1,
activatedBonusLetters: const [0],
activatedDashNests: const {'1'},
bonusHistory: const [GameBonus.word],
);
expect(gameState, isNot(equals(otherGameState)));
expect(
gameState.copyWith(
score: otherGameState.score,
balls: otherGameState.balls,
activatedBonusLetters: otherGameState.activatedBonusLetters,
activatedDashNests: otherGameState.activatedDashNests,
bonusHistory: otherGameState.bonusHistory,
),
equals(otherGameState),
);
},
);
});
});
}