GardenPlanner/garden_planner/test/logic/date.helper_test.dart

83 lines
3.0 KiB
Dart
Raw Normal View History

2023-06-25 10:13:39 +02:00
import 'package:flutter_test/flutter_test.dart';
import 'package:garden_planner/logic/date.helper.dart';
void main() {
test('DateHelper isDateBetween should work in the same year', () {
final dateBetween = DateTime(2023, 6, 15);
final dateOutside = DateTime(2023, 7, 15);
final from = DateTime(2023, 6, 1);
final until = DateTime(2023, 6, 30);
final resultTrue = DateHelper.isDateBetween(dateBetween, from, until);
final resultFalse = DateHelper.isDateBetween(dateOutside, from, until);
expect(resultTrue, true, reason: 'Date is beetween but returns true');
expect(resultFalse, false, reason: 'Date is outside but returns false');
});
test('DateHelper isDateBetween should work with differnet year', () {
final dateBetween = DateTime(2020, 6, 15);
final dateOutside = DateTime(2021, 7, 15);
final from = DateTime(2022, 6, 1);
final until = DateTime(2023, 6, 30);
final resultTrue = DateHelper.isDateBetween(dateBetween, from, until);
final resultFalse = DateHelper.isDateBetween(dateOutside, from, until);
expect(resultTrue, true, reason: 'Date is beetween but returns true');
expect(resultFalse, false, reason: 'Date is outside but returns false');
});
test('DateHelper isDateBetween should work with extremValues', () {
final dateOutside1 = DateTime(2020, 6, 1);
final dateOutside2 = DateTime(2021, 6, 31);
final dateBetween1 = DateTime(2020, 6, 2);
final dateBetween2 = DateTime(2021, 6, 30);
final from = DateTime(2022, 6, 2);
final until = DateTime(2023, 6, 30);
final resultFalse1 = DateHelper.isDateBetween(dateOutside1, from, until);
final resultFalse2 = DateHelper.isDateBetween(dateOutside2, from, until);
final resultTrue1 = DateHelper.isDateBetween(dateBetween1, from, until);
final resultTrue2 = DateHelper.isDateBetween(dateBetween2, from, until);
expect(resultTrue1, true,
reason: 'dateBetween1 is between but returns false');
expect(resultTrue2, true,
reason: 'dateBetween2 is between but returns false');
expect(resultFalse1, false,
reason: 'dateOutside1 is outside but returns true');
expect(resultFalse2, false,
reason: 'dateOutside2 is outside but returns true');
});
test('getDateTimeByDayOfYear returns the correct date', () {
const dayOfYear = 40;
final expectedDate = DateTime(2023, 2, 9);
final result = DateHelper.getDateTimeByDayOfYear(dayOfYear);
expect(result, expectedDate,
reason: "The 40 day should be the 9th february");
});
test('getDayOfYear returns the correct day of the year', () {
final date = DateTime(2000, 2, 9);
const expectedDayOfYear = 40;
final result = DateHelper.getDayOfYear(date);
expect(result, expectedDayOfYear,
reason: "The 9th february should be the 40 day");
});
test('getDateTimeByDate returns the correct date', () {
final date = DateTime(2020, 6, 15);
final expectedDate = DateTime(2023, 6, 15);
final result = DateHelper.transformToCurrentYear(date);
expect(result, expectedDate);
});
}