Testing game with only strikes
continuous-integration/drone/push Build is passing Details

code_smells
Arthur VALIN 2 years ago
parent 723808a563
commit af22750cc9

@ -1,3 +1,4 @@
import 'package:bowl_in/model/AbstractRound.dart';
import 'package:bowl_in/model/IManager.dart'; import 'package:bowl_in/model/IManager.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
@ -20,7 +21,14 @@ class GamePlayer {
_game = value; _game = value;
} }
void onNext(bool isRoundFinished, BuildContext context) { AbstractRound? get currentRound {
if (currentRoundIndex < game.rounds.length){
return game.rounds[currentRoundIndex];
}
return null;
}
void onNext(bool isRoundFinished, BuildContext? context) {
if (isRoundFinished) { if (isRoundFinished) {
print("++"); print("++");
currentRoundIndex++; currentRoundIndex++;
@ -32,7 +40,7 @@ class GamePlayer {
_parent.gameMgr.addGame(game); _parent.gameMgr.addGame(game);
game.computeScores(); game.computeScores();
context.go("/scoreboard", extra: game); context?.go("/scoreboard", extra: game);
} else { } else {
print("IN GAME : " + currentRoundIndex.toString()); print("IN GAME : " + currentRoundIndex.toString());
if (game.rounds[currentRoundIndex] is Round) { if (game.rounds[currentRoundIndex] is Round) {
@ -40,7 +48,7 @@ class GamePlayer {
} else { } else {
print("LAST ROUND"); print("LAST ROUND");
} }
context.pushReplacement("/in-game", context?.pushReplacement("/in-game",
extra: game.rounds[currentRoundIndex]); extra: game.rounds[currentRoundIndex]);
} }
} }

@ -0,0 +1,43 @@
import 'package:bowl_in/model/AbstractRound.dart';
import 'package:bowl_in/model/GameDetail.dart';
import 'package:bowl_in/model/Guest.dart';
import 'package:bowl_in/model/IManager.dart';
import 'package:bowl_in/model/Player.dart';
import 'package:bowl_in/model/StubManager/StubData.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
test("Just strikes", (){
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);
AbstractRound? currentRound = mgr.gamePlayer.currentRound;
while (currentRound != null) {
bool isFinished = currentRound.computeNext(10);
if (currentRound.isSpareOrStrike()) {
mgr.gamePlayer.onSpareOrStrike();
}
mgr.gamePlayer.onNext(isFinished, null);
currentRound = mgr.gamePlayer.currentRound;
}
final int score = gd
.getRank()
.values
.first;
expect(score, 300);
});
}
Loading…
Cancel
Save