1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-22 19:28:48 +00:00

test: use fixed point of reference for Age tests

This commit is contained in:
Oliver Booth 2023-03-31 20:15:59 +01:00
parent 3734965757
commit 708207305c
No known key found for this signature in database
GPG Key ID: 20BEB9DC87961025
2 changed files with 58 additions and 10 deletions

View File

@ -1,4 +1,4 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using X10D.Time;
namespace X10D.Tests.Time;
@ -7,12 +7,36 @@ namespace X10D.Tests.Time;
public class DateTimeOffsetTests
{
[TestMethod]
public void Age_ShouldBeDifference_Given1Jan2000()
public void Age_ShouldBe17_Given31December1991Birthday_And30December2017Date()
{
DateTimeOffset birthday = new DateTime(2000, 1, 1);
DateTimeOffset today = DateTime.Now.Date;
var reference = new DateTime(2017, 12, 30);
DateTimeOffset birthday = new DateTime(1999, 12, 31);
Assert.AreEqual(today.Year - birthday.Year, birthday.Age());
int age = birthday.Age(reference);
Assert.AreEqual(17, age);
}
[TestMethod]
public void Age_ShouldBe18_Given31December1991Birthday_And1January2018Date()
{
var reference = new DateTime(2018, 1, 1);
DateTimeOffset birthday = new DateTime(1999, 12, 31);
int age = birthday.Age(reference);
Assert.AreEqual(18, age);
}
[TestMethod]
public void Age_ShouldBe18_Given31December1991Birthday_And31December2017Date()
{
var reference = new DateTime(2017, 12, 31);
DateTimeOffset birthday = new DateTime(1999, 12, 31);
int age = birthday.Age(reference);
Assert.AreEqual(18, age);
}
[TestMethod]

View File

@ -1,4 +1,4 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using X10D.Time;
namespace X10D.Tests.Time;
@ -7,12 +7,36 @@ namespace X10D.Tests.Time;
public class DateTimeTests
{
[TestMethod]
public void Age_ShouldBeDifference_Given1Jan2000()
public void Age_ShouldBe17_Given31December1991Birthday_And30December2017Date()
{
var birthday = new DateTime(2000, 1, 1);
DateTime today = DateTime.Now.Date;
var reference = new DateTime(2017, 12, 30);
var birthday = new DateTime(1999, 12, 31);
Assert.AreEqual(today.Year - birthday.Year, birthday.Age());
int age = birthday.Age(reference);
Assert.AreEqual(17, age);
}
[TestMethod]
public void Age_ShouldBe18_Given31December1991Birthday_And1January2018Date()
{
var reference = new DateTime(2018, 1, 1);
var birthday = new DateTime(1999, 12, 31);
int age = birthday.Age(reference);
Assert.AreEqual(18, age);
}
[TestMethod]
public void Age_ShouldBe18_Given31December1991Birthday_And31December2017Date()
{
var reference = new DateTime(2017, 12, 31);
var birthday = new DateTime(1999, 12, 31);
int age = birthday.Age(reference);
Assert.AreEqual(18, age);
}
[TestMethod]