diff --git a/wrestling_scoreboard_client/test/data/person_test.dart b/wrestling_scoreboard_client/test/data/person_test.dart deleted file mode 100644 index aa02a333..00000000 --- a/wrestling_scoreboard_client/test/data/person_test.dart +++ /dev/null @@ -1,22 +0,0 @@ -// This is a basic Flutter widget test. -// -// To perform an interaction with a widget in your test, use the WidgetTester -// utility that Flutter provides. 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:wrestling_scoreboard_common/common.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - test('Check functionality of person', () { - MockableDateTime.isMocked = true; - MockableDateTime.mockedDateTime = DateTime(2021, 8, 1); - - final personA = Person(prename: 'John', surname: 'Doe', birthDate: DateTime(2015, 8, 1)); - final personB = Person(prename: 'Max', surname: 'Muster', birthDate: DateTime(2015, 7, 31)); - - expect(personA.age, 6); - expect(personB.age, 5); - }); -} diff --git a/wrestling_scoreboard_common/lib/src/data/person.dart b/wrestling_scoreboard_common/lib/src/data/person.dart index d3d07b3c..33116a71 100644 --- a/wrestling_scoreboard_common/lib/src/data/person.dart +++ b/wrestling_scoreboard_common/lib/src/data/person.dart @@ -72,7 +72,7 @@ class Person with _$Person implements DataObject, Organizational { final monthDiff = today.month - birthDate!.month; final dayDiff = today.day - birthDate!.day; - return monthDiff >= 0 && dayDiff >= 0 ? yearDiff : yearDiff - 1; + return monthDiff > 0 || (monthDiff == 0 && dayDiff >= 0) ? yearDiff : yearDiff - 1; } return null; } diff --git a/wrestling_scoreboard_common/test/data/person_test.dart b/wrestling_scoreboard_common/test/data/person_test.dart new file mode 100644 index 00000000..d9101573 --- /dev/null +++ b/wrestling_scoreboard_common/test/data/person_test.dart @@ -0,0 +1,43 @@ +import 'package:test/test.dart'; +import 'package:wrestling_scoreboard_common/common.dart'; + +void main() { + test('Persons age', () { + MockableDateTime.isMocked = true; + + final personA = Person(prename: 'John', surname: 'Doe', birthDate: DateTime(2015, 8, 1)); + final personB = Person(prename: 'Max', surname: 'Muster', birthDate: DateTime(2015, 7, 31)); + final personC = Person(prename: 'Ashok', surname: 'Kumar', birthDate: DateTime(2015, 1, 1)); + final personD = Person(prename: 'Fred', surname: 'Nurk', birthDate: DateTime(2014, 12, 31)); + + MockableDateTime.mockedDateTime = DateTime(2020, 12, 30); + expect(personA.age, 5); + expect(personB.age, 5); + expect(personC.age, 5); + expect(personD.age, 5); + + MockableDateTime.mockedDateTime = DateTime(2020, 12, 31); + expect(personA.age, 5); + expect(personB.age, 5); + expect(personC.age, 5); + expect(personD.age, 6); + + MockableDateTime.mockedDateTime = DateTime(2021, 1, 1); + expect(personA.age, 5); + expect(personB.age, 5); + expect(personC.age, 6); + expect(personD.age, 6); + + MockableDateTime.mockedDateTime = DateTime(2021, 7, 31); + expect(personA.age, 5); + expect(personB.age, 6); + expect(personC.age, 6); + expect(personD.age, 6); + + MockableDateTime.mockedDateTime = DateTime(2021, 8, 1); + expect(personA.age, 6); + expect(personB.age, 6); + expect(personC.age, 6); + expect(personD.age, 6); + }); +}