using System;
using MileageTraker.Web.Utility;
using NUnit.Framework;

namespace Web.Tests.Utility
{
	[TestFixture]
	public class AlgorithmsTests
	{
		private const int ExistingNumber = 2;
		private readonly DateTime _existingDate = DateTime.Today.AddDays(-1);

		[Test]
		public void IsChronological_True_If_Greater_And_After()
		{
			var date = _existingDate.AddDays(1);
			const int number = ExistingNumber + 1; 
			var result = Algorithms.IsChronological(_existingDate, ExistingNumber, date, number);

			Assert.That(result);
		}

		[Test]
		public void IsChronological_False_If_LessThan_And_After()
		{
			var date = _existingDate.AddDays(1);
			const int number = ExistingNumber - 1;
			var result = Algorithms.IsChronological(_existingDate, ExistingNumber, date, number);

			Assert.That(result, Is.False);
		}

		[Test]
		public void IsChronological_True_If_LessThan_And_Before()
		{
			var date = _existingDate.AddDays(-1);
			const int number = ExistingNumber - 1;
			var result = Algorithms.IsChronological(_existingDate, ExistingNumber, date, number);

			Assert.That(result, Is.True);
		}

		[Test]
		public void IsChronological_False_If_GreaterThan_And_Before()
		{
			var date = _existingDate.AddDays(-1);
			const int number = ExistingNumber + 1;
			var result = Algorithms.IsChronological(_existingDate, ExistingNumber, date, number);

			Assert.That(result, Is.False);
		}

		[Test]
		public void IsChronological_True_If_Same_And_Before()
		{
			var date = _existingDate.AddDays(-1);
			const int number = ExistingNumber;
			var result = Algorithms.IsChronological(_existingDate, ExistingNumber, date, number);

			Assert.That(result, Is.True);
		}


		[Test]
		public void IsChronological_True_If_Greater_And_SameTime()
		{
			var date = _existingDate;
			const int number = ExistingNumber + 1;
			var result = Algorithms.IsChronological(_existingDate, ExistingNumber, date, number);

			Assert.That(result, Is.True);
		}
	}
}