feat: tested and improved GameState

pull/3/head
alestiago 4 years ago
parent 7beff5287a
commit 0e75c4a3b8

@ -26,6 +26,11 @@ class GameState extends Equatable {
int? score, int? score,
int? balls, int? balls,
}) { }) {
assert(
score == null || score >= this.score,
"Score can't be decreased",
);
return GameState( return GameState(
score: score ?? this.score, score: score ?? this.score,
balls: balls ?? this.balls, balls: balls ?? this.balls,

@ -37,27 +37,83 @@ void main() {
); );
}, },
); );
});
group('isGameOver', () { group('isGameOver', () {
test( test(
'is true ' 'is true '
'when no balls are left', () { 'when no balls are left', () {
const gameState = GameState( const gameState = GameState(
balls: 0, balls: 0,
score: 0, score: 0,
); );
expect(gameState.isGameOver, isTrue); expect(gameState.isGameOver, isTrue);
});
test(
'is false '
'when one 1 ball left', () {
const gameState = GameState(
balls: 1,
score: 0,
);
expect(gameState.isGameOver, isFalse);
});
}); });
test( group('copyWith', () {
'is false ' test(
'when one 1 ball left', () { 'throws AssertionError '
const gameState = GameState( 'when scored is decreased',
balls: 1, () {
score: 0, const gameState = GameState(
balls: 0,
score: 2,
);
expect(
() => gameState.copyWith(score: gameState.score - 1),
throwsAssertionError,
);
},
);
test(
'copies correctly '
'when no arguement specified',
() {
const gameState = GameState(
balls: 0,
score: 2,
);
expect(
gameState.copyWith(),
equals(gameState),
);
},
);
test(
'copies correctly '
'when all arguements specified',
() {
const gameState = GameState(
score: 2,
balls: 0,
);
final otherGameState = GameState(
score: gameState.score + 1,
balls: gameState.balls + 1,
);
expect(gameState, isNot(otherGameState));
expect(
gameState.copyWith(
score: otherGameState.score,
balls: otherGameState.balls,
),
equals(otherGameState),
);
},
); );
expect(gameState.isGameOver, isFalse);
}); });
}); });
} }

Loading…
Cancel
Save