Skip to content

Commit

Permalink
chore: add tests + doc (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasDevApps authored May 2, 2024
1 parent 49bb9e5 commit f71c181
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 10 deletions.
4 changes: 2 additions & 2 deletions assets/data_test.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
10;13;14;25;1;35;5;15/04/2024
1;16;10;6;39;37;2;18/04/2024
1;6;25;10;33;39;2;22/04/2024
1;16;10;6;39;37;2;18/04/2024
10;13;14;25;1;35;5;15/04/2024
Binary file modified example/assets/preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.0.16"
version: "0.0.17"
matcher:
dependency: transitive
description:
Expand Down
9 changes: 9 additions & 0 deletions lib/lottery.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,13 @@ class Lottery {
void dispose() {
_instance = null;
}

/// Function to get the length of [gridsFromCsv].
int getNumberOfGrids() => gridsFromCsv.length;

/// Function to get when the more recent grid has been drawn.
String? lastGridDrawnAt() => gridsFromCsv.firstOrNull?.drawnAt;

/// Function to get when the first grid (chronologically) has been drawn
String? firstGridDrawnAt() => gridsFromCsv.lastOrNull?.drawnAt;
}
6 changes: 3 additions & 3 deletions lib/src/view/widgets/lottery_statistics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ class LotteryStatistics extends StatelessWidget {
_StatisticItem(
title: 'Grids from data',
cardColor: cardColor,
content: Lottery().gridsFromCsv.length.toString(),
content: Lottery().getNumberOfGrids().toString(),
),
const SizedBox(height: 16),
_StatisticItem(
title: 'Last grid drawn',
cardColor: cardColor,
content: Lottery().gridsFromCsv.firstOrNull?.drawnAt ?? '?',
content: Lottery().lastGridDrawnAt() ?? '?',
),
const SizedBox(height: 16),
_StatisticItem(
title: 'First grid drawn',
cardColor: cardColor,
content: Lottery().gridsFromCsv.lastOrNull?.drawnAt ?? '?',
content: Lottery().firstGridDrawnAt() ?? '?',
),
],
),
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: lottery
description: "A new Flutter project."
version: 0.0.16
version: 0.0.17

environment:
sdk: '>=3.3.3 <4.0.0'
Expand Down
21 changes: 18 additions & 3 deletions test/lottery_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ void main() {

test('Test initialize drawnAt for each grid', () async {
await _initializeLottery();
expect(Lottery().gridsFromCsv[0].drawnAt, '15/04/2024');
expect(Lottery().gridsFromCsv[0].drawnAt, '22/04/2024');
expect(Lottery().gridsFromCsv[1].drawnAt, '18/04/2024');
expect(Lottery().gridsFromCsv[2].drawnAt, '22/04/2024');
expect(Lottery().gridsFromCsv[2].drawnAt, '15/04/2024');
});
});

Expand All @@ -68,7 +68,7 @@ void main() {
specialNumbers: {1, 35, 5},
);
expect(
Lottery().wasWinningGrid(gridModel) == Lottery().gridsFromCsv.first,
Lottery().wasWinningGrid(gridModel) == Lottery().gridsFromCsv.last,
true,
);
});
Expand All @@ -82,4 +82,19 @@ void main() {
expect(Lottery().wasWinningGrid(gridModel), null);
});
});

test('Test getNumberOfGrids', () async {
await _initializeLottery();
expect(Lottery().getNumberOfGrids(), 3);
});

test('Test lastGridDrawnAt', () async {
await _initializeLottery();
expect(Lottery().lastGridDrawnAt(), '22/04/2024');
});

test('Test firstGridDrawnAt', () async {
await _initializeLottery();
expect(Lottery().firstGridDrawnAt(), '15/04/2024');
});
}

0 comments on commit f71c181

Please sign in to comment.