Testing a classic game
continuous-integration/drone/push Build is passing Details

pull/26/head
Arthur VALIN 2 years ago
parent bc0a33d54a
commit 57b1be8767

@ -8,8 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void testManager(IManager mgr){ void testManager(IManager mgr){
test("Just strikes", (){ test("Test manager " + mgr.runtimeType.toString(), (){
expect(mgr.userCurrent, mgr.userMgr.getUsersByName("Dave").first); expect(mgr.userCurrent, mgr.userMgr.getUsersByName("Dave").first);
expect(mgr.userCurrent, mgr.userMgr.getUserById(mgr.userCurrent.id)); expect(mgr.userCurrent, mgr.userMgr.getUserById(mgr.userCurrent.id));

@ -1,5 +1,6 @@
import 'package:bowl_in/model/AbstractRound.dart'; import 'package:bowl_in/model/AbstractRound.dart';
import 'package:bowl_in/model/GameDetail.dart'; import 'package:bowl_in/model/GameDetail.dart';
import 'package:bowl_in/model/GamePlayer.dart';
import 'package:bowl_in/model/Guest.dart'; import 'package:bowl_in/model/Guest.dart';
import 'package:bowl_in/model/IManager.dart'; import 'package:bowl_in/model/IManager.dart';
import 'package:bowl_in/model/Player.dart'; import 'package:bowl_in/model/Player.dart';
@ -39,5 +40,100 @@ void main() {
expect(score, 300); expect(score, 300);
}); });
test("Classic game", (){
final IManager mgr = StubData();
final List<Player> listPlayers = [mgr.userCurrent, Guest("Lucas")];
final GameDetail gd = GameDetail(
-1,
DateTime.now(),
null,
0,
false,
mgr.userCurrent.id,
listPlayers);
mgr.gamePlayer.game = gd;
mgr.gamePlayer.onNext(false, null);
makeThrow(7, mgr.gamePlayer);
makeThrow(2, mgr.gamePlayer);
makeThrow(10, mgr.gamePlayer);
makeThrow(5, mgr.gamePlayer);
makeThrow(5, mgr.gamePlayer);
makeThrow(5, mgr.gamePlayer);
makeThrow(5, mgr.gamePlayer);
makeThrow(3, mgr.gamePlayer);
makeThrow(7, mgr.gamePlayer);
makeThrow(0, mgr.gamePlayer);
makeThrow(7, mgr.gamePlayer);
makeThrow(10, mgr.gamePlayer);
makeThrow(0, mgr.gamePlayer);
makeThrow(0, mgr.gamePlayer);
makeThrow(9, mgr.gamePlayer);
makeThrow(0, mgr.gamePlayer);
makeThrow(0, mgr.gamePlayer);
makeThrow(10, mgr.gamePlayer);
makeThrow(2, mgr.gamePlayer);
makeThrow(2, mgr.gamePlayer);
makeThrow(5, mgr.gamePlayer);
makeThrow(5, mgr.gamePlayer);
makeThrow(10, mgr.gamePlayer);
makeThrow(3, mgr.gamePlayer);
makeThrow(2, mgr.gamePlayer);
makeThrow(1, mgr.gamePlayer);
makeThrow(2, mgr.gamePlayer);
makeThrow(7, mgr.gamePlayer);
makeThrow(1, mgr.gamePlayer);
makeThrow(4, mgr.gamePlayer);
makeThrow(6, mgr.gamePlayer);
makeThrow(1, mgr.gamePlayer);
makeThrow(7, mgr.gamePlayer);
makeThrow(10, mgr.gamePlayer);
makeThrow(6, mgr.gamePlayer);
makeThrow(2, mgr.gamePlayer);
makeThrow(8, mgr.gamePlayer);
makeThrow(1, mgr.gamePlayer);
final Iterable<int> score = gd
.getRank()
.values;
expect(score.first, 128);
expect(score.last, 95);
expect(mgr.userCurrent.games.length, 1);
expect(mgr.userCurrent.games.first.id, mgr.gamePlayer.game.id);
});
}
void makeThrow(int input, GamePlayer gamePlayer){
AbstractRound currentRound = gamePlayer.currentRound!;
bool isFinished = currentRound.computeNext(input);
if (currentRound.isSpareOrStrike()) {
gamePlayer.onSpareOrStrike();
}
gamePlayer.onNext(isFinished, null);
} }

@ -1,30 +0,0 @@
// This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility in the flutter_test package. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:bowl_in/main.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(const MyApp());
// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsNothing);
// Tap the '+' icon and trigger a frame.
await tester.tap(find.byIcon(Icons.add));
await tester.pump();
// Verify that our counter has incremented.
expect(find.text('0'), findsNothing);
expect(find.text('1'), findsOneWidget);
});
}
Loading…
Cancel
Save