Update Pong/test/unit_test.dart

main
Benjamin Löffler 2024-01-11 02:35:21 +01:00
parent 8306c01d1d
commit dc065306a7
1 changed files with 7 additions and 8 deletions

View File

@ -6,30 +6,29 @@ import 'package:mockito/mockito.dart'
class MockGameScreen extends Mock implements GameScreen {} class MockGameScreen extends Mock implements GameScreen {}
void main() { void main() {
// Test for the 'moveRacket' function
test('moveRacket', () {}); test('moveRacket', () {});
// Test for the 'moveBall' function, checking ball position updates and collision handling
test('moveBall updates ball position and handles collisions', () { test('moveBall updates ball position and handles collisions', () {
final gameScreenState = GameScreenState(); final gameScreenState = GameScreenState();
// Setze den Ball in eine Ausgangsposition // Set the ball to an initial position
gameScreenState.ballPositionX = 50; gameScreenState.ballPositionX = 50;
gameScreenState.ballPositionY = 50; gameScreenState.ballPositionY = 50;
// Bewege den Ball nach rechts und überprüfe die Position // Move the ball to the right and check the position
gameScreenState.moveBall(1.0); gameScreenState.moveBall(1.0);
expect(gameScreenState.ballPositionX, greaterThan(50)); expect(gameScreenState.ballPositionX, greaterThan(50));
// Bewege den Ball nach unten und überprüfe die Position // Move the ball down and check the position
gameScreenState.moveBall(1.0); gameScreenState.moveBall(1.0);
expect(gameScreenState.ballPositionY, greaterThan(50)); expect(gameScreenState.ballPositionY, greaterThan(50));
// Teste die Kollision mit den Wänden // Test collision with the walls
gameScreenState.ballPositionX = 0; gameScreenState.ballPositionX = 0;
gameScreenState.ballSpeedX = -1.0; gameScreenState.ballSpeedX = -1.0;
gameScreenState.moveBall(1.0); gameScreenState.moveBall(1.0);
expect(gameScreenState.ballSpeedX, expect(gameScreenState.ballSpeedX, greaterThan(0));
greaterThan(0)); // Die Richtung des Balls sollte sich ändern
// Füge weitere Tests für Kollisionen hinzu
}); });
} }