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 Int32Tests
|
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(0.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(0.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(100.IsLeapYear(), Is.False);
|
|
|
|
Assert.That((-100).IsLeapYear(), Is.False);
|
|
|
|
Assert.That(1900.IsLeapYear(), Is.False);
|
|
|
|
Assert.That(2100.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(1.IsLeapYear(), Is.False);
|
|
|
|
Assert.That(101.IsLeapYear(), Is.False);
|
|
|
|
Assert.That((-101).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((-401).IsLeapYear());
|
|
|
|
Assert.That((-105).IsLeapYear());
|
|
|
|
Assert.That(4.IsLeapYear());
|
|
|
|
Assert.That(104.IsLeapYear());
|
|
|
|
Assert.That(400.IsLeapYear());
|
|
|
|
Assert.That(2000.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>(() => _ = 0.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((-1).Ticks(), Is.LessThan(TimeSpan.Zero));
|
|
|
|
Assert.That((-1).Milliseconds(), Is.LessThan(TimeSpan.Zero));
|
|
|
|
Assert.That((-1).Seconds(), Is.LessThan(TimeSpan.Zero));
|
|
|
|
Assert.That((-1).Minutes(), Is.LessThan(TimeSpan.Zero));
|
|
|
|
Assert.That((-1).Days(), Is.LessThan(TimeSpan.Zero));
|
|
|
|
Assert.That((-1).Hours(), Is.LessThan(TimeSpan.Zero));
|
|
|
|
Assert.That((-1).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(1.Ticks(), Is.GreaterThan(TimeSpan.Zero));
|
|
|
|
Assert.That(1.Milliseconds(), Is.GreaterThan(TimeSpan.Zero));
|
|
|
|
Assert.That(1.Seconds(), Is.GreaterThan(TimeSpan.Zero));
|
|
|
|
Assert.That(1.Minutes(), Is.GreaterThan(TimeSpan.Zero));
|
|
|
|
Assert.That(1.Days(), Is.GreaterThan(TimeSpan.Zero));
|
|
|
|
Assert.That(1.Hours(), Is.GreaterThan(TimeSpan.Zero));
|
|
|
|
Assert.That(1.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(0.Ticks(), Is.EqualTo(TimeSpan.Zero));
|
|
|
|
Assert.That(0.Milliseconds(), Is.EqualTo(TimeSpan.Zero));
|
|
|
|
Assert.That(0.Seconds(), Is.EqualTo(TimeSpan.Zero));
|
|
|
|
Assert.That(0.Minutes(), Is.EqualTo(TimeSpan.Zero));
|
|
|
|
Assert.That(0.Days(), Is.EqualTo(TimeSpan.Zero));
|
|
|
|
Assert.That(0.Hours(), Is.EqualTo(TimeSpan.Zero));
|
|
|
|
Assert.That(0.Weeks(), Is.EqualTo(TimeSpan.Zero));
|
|
|
|
});
|
2022-04-25 17:09:49 +01:00
|
|
|
}
|
2022-04-21 21:37:20 +01:00
|
|
|
}
|