2023-08-26 18:11:29 +01:00
|
|
|
using NUnit.Framework;
|
2022-04-21 21:37:20 +01:00
|
|
|
using X10D.Time;
|
|
|
|
|
|
|
|
namespace X10D.Tests.Time;
|
|
|
|
|
2023-04-05 22:26:31 +01:00
|
|
|
[TestFixture]
|
2023-08-22 17:32:47 +01:00
|
|
|
internal class Int64Tests
|
2022-04-21 21:37:20 +01:00
|
|
|
{
|
2023-04-05 22:26:31 +01:00
|
|
|
[Test]
|
2022-04-25 17:09:49 +01:00
|
|
|
public void FromUnixTimeMilliseconds_ShouldBeEpoch_GivenZero()
|
2022-04-21 21:37:20 +01:00
|
|
|
{
|
2023-04-05 22:26:31 +01:00
|
|
|
DateTimeOffset expected = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
|
|
|
Assert.That(0L.FromUnixTimeMilliseconds(), Is.EqualTo(expected));
|
2022-04-21 21:37:20 +01:00
|
|
|
}
|
|
|
|
|
2023-04-05 22:26:31 +01:00
|
|
|
[Test]
|
2022-04-25 17:09:49 +01:00
|
|
|
public void FromUnixTimeSeconds_ShouldBeEpoch_GivenZero()
|
2022-04-21 21:37:20 +01:00
|
|
|
{
|
2023-04-05 22:26:31 +01:00
|
|
|
DateTimeOffset expected = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
|
|
|
Assert.That(0L.FromUnixTimeSeconds(), Is.EqualTo(expected));
|
2022-04-21 21:37:20 +01:00
|
|
|
}
|
|
|
|
|
2023-04-05 22:26:31 +01:00
|
|
|
[Test]
|
2022-04-28 10:27:32 +01:00
|
|
|
public void IsLeapYear_ShouldBeFalse_GivenMultipleOf100()
|
|
|
|
{
|
2023-04-05 22:26:31 +01:00
|
|
|
Assert.Multiple(() =>
|
|
|
|
{
|
|
|
|
Assert.That(100L.IsLeapYear(), Is.False);
|
|
|
|
Assert.That((-100L).IsLeapYear(), Is.False);
|
|
|
|
Assert.That(1900L.IsLeapYear(), Is.False);
|
|
|
|
Assert.That(2100L.IsLeapYear(), Is.False);
|
|
|
|
});
|
2022-04-28 10:27:32 +01:00
|
|
|
}
|
|
|
|
|
2023-04-05 22:26:31 +01:00
|
|
|
[Test]
|
2022-04-28 10:27:32 +01:00
|
|
|
public void IsLeapYear_ShouldBeFalse_GivenOddNumber()
|
|
|
|
{
|
2023-04-05 22:26:31 +01:00
|
|
|
Assert.Multiple(() =>
|
|
|
|
{
|
|
|
|
Assert.That(1L.IsLeapYear(), Is.False);
|
|
|
|
Assert.That(101L.IsLeapYear(), Is.False);
|
|
|
|
Assert.That((-101L).IsLeapYear(), Is.False);
|
|
|
|
});
|
2022-04-28 10:27:32 +01:00
|
|
|
}
|
|
|
|
|
2023-04-05 22:26:31 +01:00
|
|
|
[Test]
|
2022-04-28 10:27:32 +01:00
|
|
|
public void IsLeapYear_ShouldBeTrue_GivenMultipleOf4Or400()
|
|
|
|
{
|
2023-04-05 22:26:31 +01:00
|
|
|
Assert.Multiple(() =>
|
|
|
|
{
|
|
|
|
Assert.That((-401L).IsLeapYear());
|
|
|
|
Assert.That((-105L).IsLeapYear());
|
|
|
|
Assert.That(4L.IsLeapYear());
|
|
|
|
Assert.That(104L.IsLeapYear());
|
|
|
|
Assert.That(400L.IsLeapYear());
|
|
|
|
Assert.That(2000L.IsLeapYear());
|
|
|
|
});
|
2022-04-28 10:27:32 +01:00
|
|
|
}
|
|
|
|
|
2023-04-05 22:26:31 +01:00
|
|
|
[Test]
|
2022-04-28 10:27:32 +01:00
|
|
|
public void IsLeapYear_ShouldThrow_GivenZero()
|
|
|
|
{
|
2023-04-05 22:26:31 +01:00
|
|
|
Assert.Throws<ArgumentOutOfRangeException>(() => _ = 0L.IsLeapYear());
|
2022-04-28 10:27:32 +01:00
|
|
|
}
|
|
|
|
|
2023-04-05 22:26:31 +01:00
|
|
|
[Test]
|
2022-04-25 17:09:49 +01:00
|
|
|
public void TicksMillisecondsSecondsMinutesDaysHoursWeeks_ShouldBeNegative_GivenMinusOne()
|
2022-04-21 21:37:20 +01:00
|
|
|
{
|
2023-04-05 22:26:31 +01:00
|
|
|
Assert.Multiple(() =>
|
|
|
|
{
|
|
|
|
Assert.That((-1L).Ticks(), Is.LessThan(TimeSpan.Zero));
|
|
|
|
Assert.That((-1L).Milliseconds(), Is.LessThan(TimeSpan.Zero));
|
|
|
|
Assert.That((-1L).Seconds(), Is.LessThan(TimeSpan.Zero));
|
|
|
|
Assert.That((-1L).Minutes(), Is.LessThan(TimeSpan.Zero));
|
|
|
|
Assert.That((-1L).Days(), Is.LessThan(TimeSpan.Zero));
|
|
|
|
Assert.That((-1L).Hours(), Is.LessThan(TimeSpan.Zero));
|
|
|
|
Assert.That((-1L).Weeks(), Is.LessThan(TimeSpan.Zero));
|
|
|
|
});
|
2022-04-21 21:37:20 +01:00
|
|
|
}
|
2022-04-25 17:09:49 +01:00
|
|
|
|
2023-04-05 22:26:31 +01:00
|
|
|
[Test]
|
2022-04-25 17:09:49 +01:00
|
|
|
public void TicksMillisecondsSecondsMinutesDaysHoursWeeks_ShouldBePositive_GivenOne()
|
|
|
|
{
|
2023-04-05 22:26:31 +01:00
|
|
|
Assert.Multiple(() =>
|
|
|
|
{
|
|
|
|
Assert.That(1L.Ticks(), Is.GreaterThan(TimeSpan.Zero));
|
|
|
|
Assert.That(1L.Milliseconds(), Is.GreaterThan(TimeSpan.Zero));
|
|
|
|
Assert.That(1L.Seconds(), Is.GreaterThan(TimeSpan.Zero));
|
|
|
|
Assert.That(1L.Minutes(), Is.GreaterThan(TimeSpan.Zero));
|
|
|
|
Assert.That(1L.Days(), Is.GreaterThan(TimeSpan.Zero));
|
|
|
|
Assert.That(1L.Hours(), Is.GreaterThan(TimeSpan.Zero));
|
|
|
|
Assert.That(1L.Weeks(), Is.GreaterThan(TimeSpan.Zero));
|
|
|
|
});
|
2022-04-25 17:09:49 +01:00
|
|
|
}
|
|
|
|
|
2023-04-05 22:26:31 +01:00
|
|
|
[Test]
|
2022-04-25 17:09:49 +01:00
|
|
|
public void TicksMillisecondsSecondsMinutesDaysHoursWeeks_ShouldBeZero_GivenZero()
|
|
|
|
{
|
2023-04-05 22:26:31 +01:00
|
|
|
Assert.Multiple(() =>
|
|
|
|
{
|
|
|
|
Assert.That(0L.Ticks(), Is.EqualTo(TimeSpan.Zero));
|
|
|
|
Assert.That(0L.Milliseconds(), Is.EqualTo(TimeSpan.Zero));
|
|
|
|
Assert.That(0L.Seconds(), Is.EqualTo(TimeSpan.Zero));
|
|
|
|
Assert.That(0L.Minutes(), Is.EqualTo(TimeSpan.Zero));
|
|
|
|
Assert.That(0L.Days(), Is.EqualTo(TimeSpan.Zero));
|
|
|
|
Assert.That(0L.Hours(), Is.EqualTo(TimeSpan.Zero));
|
|
|
|
Assert.That(0L.Weeks(), Is.EqualTo(TimeSpan.Zero));
|
|
|
|
});
|
2022-04-25 17:09:49 +01:00
|
|
|
}
|
2022-04-21 21:37:20 +01:00
|
|
|
}
|