From 2aae3ae695811781cb45d68a0b13b531e6ed4b98 Mon Sep 17 00:00:00 2001 From: alestiago Date: Wed, 16 Mar 2022 10:49:13 +0000 Subject: [PATCH] feat: included tests --- lib/game/components/board.dart | 15 +++++++--- test/game/components/board_test.dart | 45 ++++++++++++++++++---------- test/game/pinball_game_test.dart | 4 +-- 3 files changed, 42 insertions(+), 22 deletions(-) diff --git a/lib/game/components/board.dart b/lib/game/components/board.dart index c1376437..9ab40b3a 100644 --- a/lib/game/components/board.dart +++ b/lib/game/components/board.dart @@ -2,7 +2,8 @@ import 'package:flame/components.dart'; import 'package:pinball/game/game.dart'; /// {@template board} -/// +/// The main flat surface of the [PinballGame], where the [Flipper]s, +/// [RoundBumper]s, [SlingShot]s are arranged. /// {entemplate} class Board extends Component { /// {@macro board} @@ -21,7 +22,7 @@ class Board extends Component { spacing: 2, ); - final dashForest = _DashForest( + final dashForest = _FlutterForest( position: Vector2( _size.x / 1.25, _size.y / 4.25, @@ -35,8 +36,13 @@ class Board extends Component { } } -class _DashForest extends Component { - _DashForest({ +/// {@template dash_forest} +/// 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, }); @@ -45,6 +51,7 @@ class _DashForest extends Component { @override Future onLoad() async { // TODO(alestiago): adjust positioning once sprites are added. + // TODO(alestiago): Use [NestBumper] instead of [RoundBumpet] once provided. final smallLeftNest = RoundBumper( position: position + Vector2(-4.8, 2.8), radius: 1, diff --git a/test/game/components/board_test.dart b/test/game/components/board_test.dart index 34a628a8..b7b0b7ac 100644 --- a/test/game/components/board_test.dart +++ b/test/game/components/board_test.dart @@ -11,15 +11,15 @@ void main() { TestWidgetsFlutterBinding.ensureInitialized(); final flameTester = FlameTester(Forge2DGame.new); - group('BottomGroup', () { + group('Board', () { flameTester.test( 'loads correctly', (game) async { - final bottomGroup = BottomGroup(position: Vector2.zero(), spacing: 0); + final board = Board(size: Vector2.all(500)); 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( 'has one left flipper', (game) async { - final bottomGroup = BottomGroup(position: Vector2.zero(), spacing: 0); + final board = Board(size: Vector2.all(500)); await game.ready(); - await game.ensureAdd(bottomGroup); + await game.ensureAdd(board); - final leftFlippers = bottomGroup.findNestedChildren( + final leftFlippers = board.findNestedChildren( condition: (flipper) => flipper.side.isLeft, ); expect(leftFlippers.length, equals(1)); @@ -41,11 +41,11 @@ void main() { flameTester.test( 'has one right flipper', (game) async { - final bottomGroup = BottomGroup(position: Vector2.zero(), spacing: 0); + final board = Board(size: Vector2.all(500)); await game.ready(); - await game.ensureAdd(bottomGroup); + await game.ensureAdd(board); - final rightFlippers = bottomGroup.findNestedChildren( + final rightFlippers = board.findNestedChildren( condition: (flipper) => flipper.side.isRight, ); expect(rightFlippers.length, equals(1)); @@ -55,11 +55,11 @@ void main() { flameTester.test( 'has two Baseboards', (game) async { - final bottomGroup = BottomGroup(position: Vector2.zero(), spacing: 0); + final board = Board(size: Vector2.all(500)); await game.ready(); - await game.ensureAdd(bottomGroup); + await game.ensureAdd(board); - final baseboards = bottomGroup.findNestedChildren(); + final baseboards = board.findNestedChildren(); expect(baseboards.length, equals(2)); }, ); @@ -67,14 +67,27 @@ void main() { flameTester.test( 'has two SlingShots', (game) async { - final bottomGroup = BottomGroup(position: Vector2.zero(), spacing: 0); + final board = Board(size: Vector2.all(500)); await game.ready(); - await game.ensureAdd(bottomGroup); + await game.ensureAdd(board); - final slingShots = bottomGroup.findNestedChildren(); + final slingShots = board.findNestedChildren(); 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(); + expect(leftFlippers.length, equals(3)); + }, + ); }); }); } diff --git a/test/game/pinball_game_test.dart b/test/game/pinball_game_test.dart index f7d0f7db..6b3d5a5f 100644 --- a/test/game/pinball_game_test.dart +++ b/test/game/pinball_game_test.dart @@ -54,10 +54,10 @@ void main() { }, ); - flameTester.test('has only one BottomGroup', (game) async { + flameTester.test('has one Board', (game) async { await game.ready(); expect( - game.children.whereType().length, + game.children.whereType().length, equals(1), ); });