PKHeX/Tests/PKHeX.Core.Tests/Util/DateUtilTests.cs

76 lines
2.7 KiB
C#
Raw Normal View History

2021-05-18 23:58:53 +00:00
using System;
using FluentAssertions;
2021-05-14 23:46:48 +00:00
using PKHeX.Core;
2020-12-06 00:15:32 +00:00
using Xunit;
namespace PKHeX.Tests.Util
{
public class DateUtilTests
{
[Theory]
[InlineData(2000, 1, 1)]
[InlineData(2001, 1, 31)]
public void RecognizesCorrectDates(int year, int month, int day)
{
2021-05-14 23:46:48 +00:00
Assert.True(DateUtil.IsDateValid(year, month, day), $"Failed to recognize {year}/{month}/{day}");
}
[Theory]
[InlineData(2016, 1, 31)]
[InlineData(2016, 2, 28)]
[InlineData(2016, 3, 31)]
[InlineData(2016, 4, 30)]
[InlineData(2016, 5, 31)]
[InlineData(2016, 6, 30)]
[InlineData(2016, 7, 31)]
[InlineData(2016, 8, 31)]
[InlineData(2016, 9, 30)]
[InlineData(2016, 10, 31)]
[InlineData(2016, 11, 30)]
[InlineData(2016, 12, 31)]
public void RecognizesValidMonthBoundaries(int year, int month, int day)
{
2021-05-14 23:46:48 +00:00
Assert.True(DateUtil.IsDateValid(year, month, day), $"Incorrect month boundary for {year}/{month}/{day}");
}
[Fact]
public void RecognizeCorrectLeapYear()
{
2021-05-14 23:46:48 +00:00
Assert.True(DateUtil.IsDateValid(2004, 2, 29));
}
2020-12-06 00:15:32 +00:00
[Theory]
[InlineData(0, 0, 0, false, "Zero date")]
[InlineData(2005, 2, 29, false, "Bad leap year")]
[InlineData(0, 1, 1, false, "Zero year")]
[InlineData(2000, 0, 1, false, "Zero month")]
[InlineData(2000, 1, 0, false, "Zero day")]
[InlineData(10000, 1, 0, false, "Big year")]
[InlineData(2000, 13, 0, false, "Big month")]
[InlineData(2000, 1, 32, false, "Big day")]
[InlineData(2019, 11, 31, false, "Bad date, November doesn't have a 31st")]
[InlineData(uint.MaxValue, uint.MaxValue, uint.MaxValue, false, "Failed with uint.MaxValue, negative")]
public void CheckDate(uint year, uint month, uint day, bool cmp, string because)
{
2021-05-14 23:46:48 +00:00
var result = DateUtil.IsDateValid(year, month, day);
2020-12-06 00:15:32 +00:00
result.Should().Be(cmp, because);
}
2021-05-18 23:58:53 +00:00
[Theory]
[InlineData(2000, 12, 1, 2000, 12, 31, 1337)] // +6
[InlineData(2000, 12, 1, 2000, 12, 31, 35)] // rand->+0
[InlineData(2000, 12, 1, 2000, 12, 31, 12)] // rand->+30
public void CheckRandomDate(int y1, int m1, int d1, int y2, int m2, int d2, int seed)
{
var start = new DateTime(y1, m1, d1);
var end = new DateTime(y2, m2, d2);
(start <= end).Should().BeTrue();
var r = new Random(seed);
var rand = DateUtil.GetRandomDateWithin(start, end, r);
(start <= rand).Should().BeTrue();
(rand <= end).Should().BeTrue();
}
}
}