-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a159bcb
commit 0483244
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,52 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:target_mate/utils/calculator.dart'; | ||
|
||
void main() { | ||
group('calculateDaysRemainingFor tests', () { | ||
// generate tests | ||
List<int> effectiveDays = []; | ||
|
||
void resetEffectiveDays() => | ||
effectiveDays = List.generate(30, (index) => index 1); | ||
|
||
setUp(() { | ||
resetEffectiveDays(); | ||
}); | ||
|
||
int calculateFor(int day, {bool include = true}) => | ||
Calculator.calculateDaysRemainingFor( | ||
getDateForDay(day), | ||
effectiveDays.map((day) => getDateForDay(day)), | ||
includeTargetDate: include, | ||
); | ||
|
||
test('when target is in effective days', () { | ||
expect(calculateFor(15), 16); | ||
expect(calculateFor(15, include: false), 15); | ||
|
||
expect(calculateFor(28), 3); | ||
expect(calculateFor(28, include: false), 2); | ||
}); | ||
|
||
test('when target is not in effective days', () { | ||
effectiveDays.remove(15); | ||
expect(calculateFor(15), 15); | ||
expect(calculateFor(15, include: false), 15); | ||
|
||
resetEffectiveDays(); | ||
effectiveDays.remove(28); | ||
expect(calculateFor(28), 2); | ||
expect(calculateFor(28, include: false), 2); | ||
}); | ||
|
||
test('when effective days do not have some days', () { | ||
effectiveDays.remove(20); | ||
expect(calculateFor(10), 20); | ||
expect(calculateFor(10, include: false), 19); | ||
}); | ||
|
||
tearDown(() => effectiveDays.clear()); | ||
}); | ||
} | ||
|
||
DateTime getDateForDay(int day) => DateTime(2023, 11, day); |