|
| 1 | +import 'package:flutter_test/flutter_test.dart'; |
| 2 | +import 'package:sj_manager/models/db/event_series/standings/score/basic_score_types.dart'; |
| 3 | +import 'package:sj_manager/models/db/event_series/standings/standings_positions_map_creator/standings_positions_with_ex_aequos_creator.dart'; |
| 4 | +import 'package:sj_manager/models/db/event_series/standings/standings_record.dart'; |
| 5 | +import 'package:sj_manager/models/db/event_series/standings/standings_repo.dart'; |
| 6 | + |
| 7 | +void main() { |
| 8 | + group(StandingsRepo, () { |
| 9 | + late StandingsRepo<String, PointsScore, StandingsRecord<String, PointsScore>> repo; |
| 10 | + |
| 11 | + test('Adding, editing and removing; updating standings', () { |
| 12 | + const stoch = StandingsRecord(entity: 'Kamil Stoch', score: PointsScore(315.5)); |
| 13 | + const kubacki = StandingsRecord(entity: 'Dawid Kubacki', score: PointsScore(333.4)); |
| 14 | + const zyla = StandingsRecord(entity: 'Piotr Żyła', score: PointsScore(315.5)); |
| 15 | + const geiger = StandingsRecord(entity: 'Karl Geiger', score: PointsScore(330.0)); |
| 16 | + const eisenbichler = |
| 17 | + StandingsRecord(entity: 'Markus Eisenbichler', score: PointsScore(350.1)); |
| 18 | + |
| 19 | + repo = StandingsRepo( |
| 20 | + positionsCreator: StandingsPositionsWithExAequosCreator(), |
| 21 | + initialRecords: const [stoch, kubacki, zyla], |
| 22 | + ); |
| 23 | + |
| 24 | + repo.update(newRecord: geiger); |
| 25 | + repo.update(newRecord: eisenbichler); |
| 26 | + expect(repo.leaders.single, eisenbichler); |
| 27 | + expect(repo.last.values.last, [stoch, zyla]); // Records at last position |
| 28 | + expect(repo.length, 5); |
| 29 | + repo.remove(record: eisenbichler); |
| 30 | + expect(repo.leaders.single, kubacki); |
| 31 | + expect(repo.length, 4); |
| 32 | + expect(repo.containsEntity('Markus Eisenbichler'), false); |
| 33 | + repo.update(newRecord: stoch.copyWith(score: const PointsScore(441.4))); |
| 34 | + expect(repo.leaders.single.entity, 'Kamil Stoch'); |
| 35 | + expect(repo.length, 4); |
| 36 | + |
| 37 | + repo.dispose(); |
| 38 | + }); |
| 39 | + |
| 40 | + group('Repo view utilities', () { |
| 41 | + const kot = StandingsRecord(entity: 'Maciej Kot', score: PointsScore(116.4)); |
| 42 | + const hula = StandingsRecord(entity: 'Stefan Hula', score: PointsScore(116.4)); |
| 43 | + const kobayashi = |
| 44 | + StandingsRecord(entity: 'Ryoyu Kobayashi', score: PointsScore(137.8)); |
| 45 | + const danielHuber = |
| 46 | + StandingsRecord(entity: 'Daniel Huber', score: PointsScore(137.8)); |
| 47 | + const stefanHuber = |
| 48 | + StandingsRecord(entity: 'Stefan Huber', score: PointsScore(120.1)); |
| 49 | + const wohlgenannt = |
| 50 | + StandingsRecord(entity: 'Ulrich Wohlgenannt', score: PointsScore(111.5)); |
| 51 | + const kos = StandingsRecord(entity: 'Lovro Kos', score: PointsScore(127.5)); |
| 52 | + const prevc = StandingsRecord(entity: 'Domen Prevc', score: PointsScore(114.9)); |
| 53 | + const peier = StandingsRecord(entity: 'Killian Peier', score: PointsScore(110.8)); |
| 54 | + |
| 55 | + setUpAll(() { |
| 56 | + repo = StandingsRepo( |
| 57 | + positionsCreator: StandingsPositionsWithExAequosCreator(), |
| 58 | + initialRecords: const [ |
| 59 | + kot, |
| 60 | + hula, |
| 61 | + kobayashi, |
| 62 | + danielHuber, |
| 63 | + stefanHuber, |
| 64 | + wohlgenannt, |
| 65 | + kos, |
| 66 | + prevc, |
| 67 | + peier, |
| 68 | + ], |
| 69 | + ); |
| 70 | + }); |
| 71 | + |
| 72 | + test('leaders', () { |
| 73 | + expect(repo.leaders, [kobayashi, danielHuber]); |
| 74 | + expect(() => repo.leaders.single, throwsA(isA<StateError>())); |
| 75 | + }); |
| 76 | + |
| 77 | + test('records by position', () { |
| 78 | + expect(repo.leaders, repo.atPosition(1)); |
| 79 | + expect(repo.atPosition(4), [stefanHuber]); |
| 80 | + expect(() => repo.atPosition(0), throwsA(isA<StateError>())); |
| 81 | + expect(() => repo.atPosition(18), throwsA(isA<StateError>())); |
| 82 | + }); |
| 83 | + |
| 84 | + test('position by entity', () { |
| 85 | + expect(repo.positionOf('Ulrich Wohlgenannt'), 8); |
| 86 | + expect(repo.positionOf('Stefan Huber'), 4); |
| 87 | + expect(() => repo.positionOf('Karol Wojtyła'), throwsA(isA<StateError>())); |
| 88 | + }); |
| 89 | + |
| 90 | + test('score by entity', () { |
| 91 | + expect(repo.scoreOf('Domen Prevc'), const PointsScore(114.9)); |
| 92 | + expect(repo.scoreOf('Daniel Huber'), const PointsScore(137.8)); |
| 93 | + expect(() => repo.scoreOf('Peter Prevc'), throwsA(isA<StateError>())); |
| 94 | + }); |
| 95 | + |
| 96 | + test('length', () { |
| 97 | + expect(repo.length, 9); |
| 98 | + }); |
| 99 | + |
| 100 | + test('whether contains an entity', () { |
| 101 | + expect(repo.containsEntity('Stefan Hula'), true); |
| 102 | + expect(repo.containsEntity('Stefan Huber'), true); |
| 103 | + expect(repo.containsEntity('Junshiro Kobayashi'), false); |
| 104 | + }); |
| 105 | + |
| 106 | + tearDownAll(() { |
| 107 | + repo.dispose(); |
| 108 | + }); |
| 109 | + }); |
| 110 | + }); |
| 111 | +} |
0 commit comments