35 lines
1.1 KiB
Dart
35 lines
1.1 KiB
Dart
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 for the 'moveRacket' function
|
|
test('moveRacket', () {});
|
|
|
|
// Test for the 'moveBall' function, checking ball position updates and collision handling
|
|
test('moveBall updates ball position and handles collisions', () {
|
|
final gameScreenState = GameScreenState();
|
|
|
|
// Set the ball to an initial position
|
|
gameScreenState.ballPositionX = 50;
|
|
gameScreenState.ballPositionY = 50;
|
|
|
|
// Move the ball to the right and check the position
|
|
gameScreenState.moveBall(1.0);
|
|
expect(gameScreenState.ballPositionX, greaterThan(50));
|
|
|
|
// Move the ball down and check the position
|
|
gameScreenState.moveBall(1.0);
|
|
expect(gameScreenState.ballPositionY, greaterThan(50));
|
|
|
|
// Test collision with the walls
|
|
gameScreenState.ballPositionX = 0;
|
|
gameScreenState.ballSpeedX = -1.0;
|
|
gameScreenState.moveBall(1.0);
|
|
expect(gameScreenState.ballSpeedX, greaterThan(0));
|
|
});
|
|
}
|