diff --git a/Pong/analysis_options.yaml b/Pong/analysis_options.yaml index 0d29021..0439848 100644 --- a/Pong/analysis_options.yaml +++ b/Pong/analysis_options.yaml @@ -23,6 +23,5 @@ linter: rules: # avoid_print: false # Uncomment to disable the `avoid_print` rule # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule - # Additional information about this file can be found at # https://dart.dev/guides/language/analysis-options diff --git a/Pong/lib/main.dart b/Pong/lib/main.dart index de59bdc..80a7b30 100644 --- a/Pong/lib/main.dart +++ b/Pong/lib/main.dart @@ -8,7 +8,7 @@ import 'package:flutter/scheduler.dart'; import 'package:pong/pong_menu.dart'; void main() { - // Run the PongGame + // Run the PongGame app runApp(const PongGame()); } diff --git a/Pong/pubspec.lock b/Pong/pubspec.lock index 32958ff..019d111 100644 --- a/Pong/pubspec.lock +++ b/Pong/pubspec.lock @@ -66,10 +66,10 @@ packages: dependency: "direct dev" description: name: flutter_lints - sha256: a25a15ebbdfc33ab1cd26c63a6ee519df92338a9c10f122adda92938253bef04 + sha256: e2a421b7e59244faef694ba7b30562e489c2b489866e505074eb005cd7060db7 url: "https://pub.dev" source: hosted - version: "2.0.3" + version: "3.0.1" flutter_test: dependency: "direct dev" description: flutter @@ -79,10 +79,10 @@ packages: dependency: transitive description: name: lints - sha256: "0a217c6c989d21039f1498c3ed9f3ed71b354e69873f13a8dfc3c9fe76f1b452" + sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290 url: "https://pub.dev" source: hosted - version: "2.1.1" + version: "3.0.0" matcher: dependency: transitive description: diff --git a/Pong/pubspec.yaml b/Pong/pubspec.yaml index a058bd5..113e09a 100644 --- a/Pong/pubspec.yaml +++ b/Pong/pubspec.yaml @@ -44,7 +44,7 @@ dev_dependencies: # activated in the `analysis_options.yaml` file located at the root of your # package. See that file for information about deactivating specific lint # rules and activating additional ones. - flutter_lints: ^2.0.0 + flutter_lints: ^3.0.1 # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec diff --git a/Pong/test/unit_test.dart b/Pong/test/unit_test.dart index 7416990..d88cb02 100644 --- a/Pong/test/unit_test.dart +++ b/Pong/test/unit_test.dart @@ -1,7 +1,35 @@ import 'package:flutter_test/flutter_test.dart'; - import 'package:pong/main.dart'; +import 'package:mockito/mockito.dart' + + +class MockGameScreen extends Mock implements GameScreen {} void main() { test('moveRacket', () {}); + + test('moveBall updates ball position and handles collisions', () { + final gameScreenState = GameScreenState(); + + // Setze den Ball in eine Ausgangsposition + gameScreenState.ballPositionX = 50; + gameScreenState.ballPositionY = 50; + + // Bewege den Ball nach rechts und überprüfe die Position + gameScreenState.moveBall(1.0); + expect(gameScreenState.ballPositionX, greaterThan(50)); + + // Bewege den Ball nach unten und überprüfe die Position + gameScreenState.moveBall(1.0); + expect(gameScreenState.ballPositionY, greaterThan(50)); + + // Teste die Kollision mit den Wänden + gameScreenState.ballPositionX = 0; + gameScreenState.ballSpeedX = -1.0; + gameScreenState.moveBall(1.0); + expect(gameScreenState.ballSpeedX, + greaterThan(0)); // Die Richtung des Balls sollte sich ändern + + // Füge weitere Tests für Kollisionen hinzu + }); } diff --git a/Pong/test/widget_test.dart b/Pong/test/widget_test.dart index 2e1619d..b2b11d4 100644 --- a/Pong/test/widget_test.dart +++ b/Pong/test/widget_test.dart @@ -1,16 +1,40 @@ import 'package:flutter/material.dart'; +import 'package:flutter/scheduler.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pong/main.dart'; void main() { testWidgets('Tests "Berühren um zu beginnen!"', (WidgetTester tester) async { - final tapToStart = find.byKey(const ValueKey("tapToStart")); + final tapToStart = find.text("Berühren um zu beginnen!"); await tester.pumpWidget(const MaterialApp(home: StartScreen())); - await tester.tap(tapToStart); + + expect(tapToStart, findsOneWidget); + }); + + testWidgets('Tests "Punkte:"', (WidgetTester tester) async { + final points = find.text("Punkte: 0"); + + await tester.pumpWidget(const MaterialApp(home: GameScreen())); + + expect(points, findsOneWidget); + }); + + testWidgets('StartScreen UI Test', (WidgetTester tester) async { + // Build our app and trigger a frame. + await tester.pumpWidget(const MaterialApp( + home: StartScreen(), + )); + + // Verify that the "Berühren um zu beginnen!" Text angezeigt wird. + expect(find.text('Berühren um zu beginnen!'), findsOneWidget); + + // Tap auf das GestureDetector, um zur GameScreen zu wechseln. + await tester.tap(find.byType(GestureDetector)); await tester.pump(); - expect(find.text("Berühren um zu beginnen!"), findsOneWidget); + // Verify, dass der Übergang zur GameScreen erfolgt ist. + expect(find.byType(GameScreen), findsOneWidget); }); }