Add GameDetail UT 🚩
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
fa5caf5d21
commit
7a81067dd7
@ -0,0 +1,69 @@
|
|||||||
|
import 'package:test/test.dart';
|
||||||
|
import '../lib/model/GameDetail.dart';
|
||||||
|
import '../lib/model/Player.dart';
|
||||||
|
import '../lib/model/Round.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
group('GameDetail', () {
|
||||||
|
List<Player> players = [
|
||||||
|
Player(1, "Player 1", "Avatar 1"),
|
||||||
|
Player(2, "Player 2", "Avatar 2"),
|
||||||
|
Player(3, "Player 3", "Avatar 3")
|
||||||
|
];
|
||||||
|
|
||||||
|
List<Round> rounds = [
|
||||||
|
Round(5, 2, 7, players[2]),
|
||||||
|
Round(7, null, 7, players[1]),
|
||||||
|
Round(3, 3, 6, players[0]),
|
||||||
|
Round(2, 1, 3, players[2]),
|
||||||
|
Round(5, 2, 7, players[1]),
|
||||||
|
Round(5, 1, 6, players[0])
|
||||||
|
];
|
||||||
|
|
||||||
|
test('GetPointByPlayerId - Existing player', () {
|
||||||
|
var gameDetail = GameDetail(
|
||||||
|
2,
|
||||||
|
DateTime.now().subtract(Duration(days: 2)),
|
||||||
|
players[1].id,
|
||||||
|
250,
|
||||||
|
true,
|
||||||
|
null,
|
||||||
|
players[1].id,
|
||||||
|
rounds,
|
||||||
|
players);
|
||||||
|
|
||||||
|
expect(gameDetail.getPointByPlayerId(players[0].id), 12);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('GetPointByPlayerId - Non-existing player', () {
|
||||||
|
var gameDetail = GameDetail(
|
||||||
|
2,
|
||||||
|
DateTime.now().subtract(Duration(days: 2)),
|
||||||
|
players[1].id,
|
||||||
|
250,
|
||||||
|
true,
|
||||||
|
null,
|
||||||
|
players[1].id,
|
||||||
|
rounds,
|
||||||
|
players);
|
||||||
|
|
||||||
|
expect(() => gameDetail.getPointByPlayerId(4), throwsException);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('GetRank', () {
|
||||||
|
var gameDetail = GameDetail(
|
||||||
|
2,
|
||||||
|
DateTime.now().subtract(Duration(days: 2)),
|
||||||
|
players[1].id,
|
||||||
|
250,
|
||||||
|
true,
|
||||||
|
null,
|
||||||
|
players[1].id,
|
||||||
|
rounds,
|
||||||
|
players);
|
||||||
|
|
||||||
|
var expectedRank = {2: 14, 1: 12, 3: 10};
|
||||||
|
expect(gameDetail.getRank(), equals(expectedRank));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
@ -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…
Reference in new issue