add new score tests

This commit is contained in:
gelbeinhalb
2026-01-21 11:33:37 +01:00
parent 2e6a2b8e55
commit 748361d04f

View File

@@ -15,7 +15,7 @@ void main() {
late Game testGame; late Game testGame;
late Match testMatch1; late Match testMatch1;
late Match testMatch2; late Match testMatch2;
final fixedDate = DateTime(2025, 19, 11, 00, 11, 23); final fixedDate = DateTime(2025, 11, 19, 00, 11, 23);
final fakeClock = Clock(() => fixedDate); final fakeClock = Clock(() => fixedDate);
setUp(() async { setUp(() async {
@@ -426,5 +426,311 @@ void main() {
expect(score!.score, 99); expect(score!.score, 99);
expect(score.change, 99); expect(score.change, 99);
}); });
// Verifies that getScoresForMatch returns empty list for match with no scores.
test('Getting scores for match with no scores returns empty list', () async {
final scores = await database.scoreDao.getScoresForMatch(
matchId: testMatch1.id,
);
expect(scores.isEmpty, true);
});
// Verifies that getPlayerScoresInMatch returns empty list when player has no scores.
test('Getting player scores with no scores returns empty list', () async {
final playerScores = await database.scoreDao.getPlayerScoresInMatch(
playerId: testPlayer1.id,
matchId: testMatch1.id,
);
expect(playerScores.isEmpty, true);
});
// Verifies that scores can have negative values.
test('Score can have negative values', () async {
await database.scoreDao.addScore(
playerId: testPlayer1.id,
matchId: testMatch1.id,
roundNumber: 1,
score: -10,
change: -10,
);
final score = await database.scoreDao.getScoreForRound(
playerId: testPlayer1.id,
matchId: testMatch1.id,
roundNumber: 1,
);
expect(score, isNotNull);
expect(score!.score, -10);
expect(score.change, -10);
});
// Verifies that scores can have zero values.
test('Score can have zero values', () async {
await database.scoreDao.addScore(
playerId: testPlayer1.id,
matchId: testMatch1.id,
roundNumber: 1,
score: 0,
change: 0,
);
final score = await database.scoreDao.getScoreForRound(
playerId: testPlayer1.id,
matchId: testMatch1.id,
roundNumber: 1,
);
expect(score, isNotNull);
expect(score!.score, 0);
expect(score.change, 0);
});
// Verifies that very large round numbers are supported.
test('Score supports very large round numbers', () async {
await database.scoreDao.addScore(
playerId: testPlayer1.id,
matchId: testMatch1.id,
roundNumber: 999999,
score: 100,
change: 100,
);
final score = await database.scoreDao.getScoreForRound(
playerId: testPlayer1.id,
matchId: testMatch1.id,
roundNumber: 999999,
);
expect(score, isNotNull);
expect(score!.roundNumber, 999999);
});
// Verifies that getLatestRoundNumber returns max correctly for non-consecutive rounds.
test('Getting latest round number with non-consecutive rounds', () async {
await database.scoreDao.addScore(
playerId: testPlayer1.id,
matchId: testMatch1.id,
roundNumber: 1,
score: 10,
change: 10,
);
await database.scoreDao.addScore(
playerId: testPlayer1.id,
matchId: testMatch1.id,
roundNumber: 5,
score: 50,
change: 40,
);
await database.scoreDao.addScore(
playerId: testPlayer1.id,
matchId: testMatch1.id,
roundNumber: 3,
score: 30,
change: 20,
);
final latestRound = await database.scoreDao.getLatestRoundNumber(
matchId: testMatch1.id,
);
expect(latestRound, 5);
});
// Verifies that deleteScoresForMatch returns false when no scores exist.
test('Deleting scores for empty match returns false', () async {
final deleted = await database.scoreDao.deleteScoresForMatch(
matchId: testMatch1.id,
);
expect(deleted, false);
});
// Verifies that deleteScoresForPlayer returns false when player has no scores.
test('Deleting scores for player with no scores returns false', () async {
final deleted = await database.scoreDao.deleteScoresForPlayer(
playerId: testPlayer1.id,
);
expect(deleted, false);
});
// Verifies that multiple players in same match can have independent score updates.
test('Multiple players in same match have independent scores', () async {
await database.scoreDao.addScore(
playerId: testPlayer1.id,
matchId: testMatch1.id,
roundNumber: 1,
score: 10,
change: 10,
);
await database.scoreDao.addScore(
playerId: testPlayer2.id,
matchId: testMatch1.id,
roundNumber: 1,
score: 20,
change: 20,
);
await database.scoreDao.updateScore(
playerId: testPlayer1.id,
matchId: testMatch1.id,
roundNumber: 1,
newScore: 100,
newChange: 90,
);
final player1Score = await database.scoreDao.getScoreForRound(
playerId: testPlayer1.id,
matchId: testMatch1.id,
roundNumber: 1,
);
final player2Score = await database.scoreDao.getScoreForRound(
playerId: testPlayer2.id,
matchId: testMatch1.id,
roundNumber: 1,
);
expect(player1Score!.score, 100);
expect(player2Score!.score, 20);
});
// Verifies that scores are isolated across different matches.
test('Scores are isolated across different matches', () async {
await database.scoreDao.addScore(
playerId: testPlayer1.id,
matchId: testMatch1.id,
roundNumber: 1,
score: 10,
change: 10,
);
await database.scoreDao.addScore(
playerId: testPlayer1.id,
matchId: testMatch2.id,
roundNumber: 1,
score: 50,
change: 50,
);
final match1Scores = await database.scoreDao.getPlayerScoresInMatch(
playerId: testPlayer1.id,
matchId: testMatch1.id,
);
final match2Scores = await database.scoreDao.getPlayerScoresInMatch(
playerId: testPlayer1.id,
matchId: testMatch2.id,
);
expect(match1Scores.length, 1);
expect(match2Scores.length, 1);
expect(match1Scores[0].score, 10);
expect(match2Scores[0].score, 50);
});
// Verifies that getTotalScoreForPlayer returns latest score across multiple rounds.
test('Total score for player returns latest cumulative score', () async {
await database.scoreDao.addScore(
playerId: testPlayer1.id,
matchId: testMatch1.id,
roundNumber: 2,
score: 25,
change: 25,
);
await database.scoreDao.addScore(
playerId: testPlayer1.id,
matchId: testMatch1.id,
roundNumber: 1,
score: 10,
change: 10,
);
await database.scoreDao.addScore(
playerId: testPlayer1.id,
matchId: testMatch1.id,
roundNumber: 3,
score: 50,
change: 25,
);
final totalScore = await database.scoreDao.getTotalScoreForPlayer(
playerId: testPlayer1.id,
matchId: testMatch1.id,
);
// Should return the highest round's score
expect(totalScore, 50);
});
// Verifies that updating one player's score doesn't affect another player's score in same round.
test('Updating one player score does not affect other players in same round', () async {
await database.scoreDao.addScore(
playerId: testPlayer1.id,
matchId: testMatch1.id,
roundNumber: 1,
score: 10,
change: 10,
);
await database.scoreDao.addScore(
playerId: testPlayer2.id,
matchId: testMatch1.id,
roundNumber: 1,
score: 20,
change: 20,
);
await database.scoreDao.addScore(
playerId: testPlayer3.id,
matchId: testMatch1.id,
roundNumber: 1,
score: 30,
change: 30,
);
await database.scoreDao.updateScore(
playerId: testPlayer2.id,
matchId: testMatch1.id,
roundNumber: 1,
newScore: 99,
newChange: 89,
);
final scores = await database.scoreDao.getScoresForMatch(
matchId: testMatch1.id,
);
expect(scores.length, 3);
expect(scores.where((s) => s.playerId == testPlayer1.id).first.score, 10);
expect(scores.where((s) => s.playerId == testPlayer2.id).first.score, 99);
expect(scores.where((s) => s.playerId == testPlayer3.id).first.score, 30);
});
// Verifies that deleting a player's scores only affects that specific player.
test('Deleting player scores only affects target player', () async {
await database.scoreDao.addScore(
playerId: testPlayer1.id,
matchId: testMatch1.id,
roundNumber: 1,
score: 10,
change: 10,
);
await database.scoreDao.addScore(
playerId: testPlayer2.id,
matchId: testMatch1.id,
roundNumber: 1,
score: 20,
change: 20,
);
await database.scoreDao.deleteScoresForPlayer(
playerId: testPlayer1.id,
);
final match1Scores = await database.scoreDao.getScoresForMatch(
matchId: testMatch1.id,
);
expect(match1Scores.length, 1);
expect(match1Scores[0].playerId, testPlayer2.id);
});
}); });
} }