feat: included tests

pull/49/head
alestiago 4 years ago
parent 56bcfe9f4e
commit 2aae3ae695

@ -2,7 +2,8 @@ import 'package:flame/components.dart';
import 'package:pinball/game/game.dart'; import 'package:pinball/game/game.dart';
/// {@template board} /// {@template board}
/// /// The main flat surface of the [PinballGame], where the [Flipper]s,
/// [RoundBumper]s, [SlingShot]s are arranged.
/// {entemplate} /// {entemplate}
class Board extends Component { class Board extends Component {
/// {@macro board} /// {@macro board}
@ -21,7 +22,7 @@ class Board extends Component {
spacing: 2, spacing: 2,
); );
final dashForest = _DashForest( final dashForest = _FlutterForest(
position: Vector2( position: Vector2(
_size.x / 1.25, _size.x / 1.25,
_size.y / 4.25, _size.y / 4.25,
@ -35,8 +36,13 @@ class Board extends Component {
} }
} }
class _DashForest extends Component { /// {@template dash_forest}
_DashForest({ /// Area positioned at the top right of the [Board] where the [Ball]
/// can bounce off [RoundBumper]s.
/// {@endtemplate}
class _FlutterForest extends Component {
/// {@macro dash_forest}
_FlutterForest({
required this.position, required this.position,
}); });
@ -45,6 +51,7 @@ class _DashForest extends Component {
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
// TODO(alestiago): adjust positioning once sprites are added. // TODO(alestiago): adjust positioning once sprites are added.
// TODO(alestiago): Use [NestBumper] instead of [RoundBumpet] once provided.
final smallLeftNest = RoundBumper( final smallLeftNest = RoundBumper(
position: position + Vector2(-4.8, 2.8), position: position + Vector2(-4.8, 2.8),
radius: 1, radius: 1,

@ -11,15 +11,15 @@ void main() {
TestWidgetsFlutterBinding.ensureInitialized(); TestWidgetsFlutterBinding.ensureInitialized();
final flameTester = FlameTester(Forge2DGame.new); final flameTester = FlameTester(Forge2DGame.new);
group('BottomGroup', () { group('Board', () {
flameTester.test( flameTester.test(
'loads correctly', 'loads correctly',
(game) async { (game) async {
final bottomGroup = BottomGroup(position: Vector2.zero(), spacing: 0); final board = Board(size: Vector2.all(500));
await game.ready(); await game.ready();
await game.ensureAdd(bottomGroup); await game.ensureAdd(board);
expect(game.contains(bottomGroup), isTrue); expect(game.contains(board), isTrue);
}, },
); );
@ -27,11 +27,11 @@ void main() {
flameTester.test( flameTester.test(
'has one left flipper', 'has one left flipper',
(game) async { (game) async {
final bottomGroup = BottomGroup(position: Vector2.zero(), spacing: 0); final board = Board(size: Vector2.all(500));
await game.ready(); await game.ready();
await game.ensureAdd(bottomGroup); await game.ensureAdd(board);
final leftFlippers = bottomGroup.findNestedChildren<Flipper>( final leftFlippers = board.findNestedChildren<Flipper>(
condition: (flipper) => flipper.side.isLeft, condition: (flipper) => flipper.side.isLeft,
); );
expect(leftFlippers.length, equals(1)); expect(leftFlippers.length, equals(1));
@ -41,11 +41,11 @@ void main() {
flameTester.test( flameTester.test(
'has one right flipper', 'has one right flipper',
(game) async { (game) async {
final bottomGroup = BottomGroup(position: Vector2.zero(), spacing: 0); final board = Board(size: Vector2.all(500));
await game.ready(); await game.ready();
await game.ensureAdd(bottomGroup); await game.ensureAdd(board);
final rightFlippers = bottomGroup.findNestedChildren<Flipper>( final rightFlippers = board.findNestedChildren<Flipper>(
condition: (flipper) => flipper.side.isRight, condition: (flipper) => flipper.side.isRight,
); );
expect(rightFlippers.length, equals(1)); expect(rightFlippers.length, equals(1));
@ -55,11 +55,11 @@ void main() {
flameTester.test( flameTester.test(
'has two Baseboards', 'has two Baseboards',
(game) async { (game) async {
final bottomGroup = BottomGroup(position: Vector2.zero(), spacing: 0); final board = Board(size: Vector2.all(500));
await game.ready(); await game.ready();
await game.ensureAdd(bottomGroup); await game.ensureAdd(board);
final baseboards = bottomGroup.findNestedChildren<Baseboard>(); final baseboards = board.findNestedChildren<Baseboard>();
expect(baseboards.length, equals(2)); expect(baseboards.length, equals(2));
}, },
); );
@ -67,14 +67,27 @@ void main() {
flameTester.test( flameTester.test(
'has two SlingShots', 'has two SlingShots',
(game) async { (game) async {
final bottomGroup = BottomGroup(position: Vector2.zero(), spacing: 0); final board = Board(size: Vector2.all(500));
await game.ready(); await game.ready();
await game.ensureAdd(bottomGroup); await game.ensureAdd(board);
final slingShots = bottomGroup.findNestedChildren<SlingShot>(); final slingShots = board.findNestedChildren<SlingShot>();
expect(slingShots.length, equals(2)); expect(slingShots.length, equals(2));
}, },
); );
flameTester.test(
'has three RoundBumpers',
(game) async {
// TODO(alestiago): change to [NestBumpers] once provided.
final board = Board(size: Vector2.all(500));
await game.ready();
await game.ensureAdd(board);
final leftFlippers = board.findNestedChildren<RoundBumper>();
expect(leftFlippers.length, equals(3));
},
);
}); });
}); });
} }

@ -54,10 +54,10 @@ void main() {
}, },
); );
flameTester.test('has only one BottomGroup', (game) async { flameTester.test('has one Board', (game) async {
await game.ready(); await game.ready();
expect( expect(
game.children.whereType<BottomGroup>().length, game.children.whereType<Board>().length,
equals(1), equals(1),
); );
}); });

Loading…
Cancel
Save