using System;
using MusicMetaTagger.Client.AllMusicGuide.Services;
using MusicMetaTagger.Core.Model;
using MusicMetaTagger.Core.Queries;
using MusicMetaTagger.Core.Services;
using NUnit.Framework;

namespace MusicMetaTagger.Client.AllMusicGuide.Tests.Services
{
	[TestFixture]
	public class TrackSimilarityTests
	{
		[Test]
		public void Similarity_Identical()
		{
			var trackQuery = new TrackQuery { TrackTitle = "track", TrackNumber = 3, TrackLength = new TimeSpan(0, 0, 2, 34) };
			var track = new Track {TrackTitle = "track", TrackNumber = 3, TrackLength = new TimeSpan(0, 0, 2, 34)};

			Assert.AreEqual(1, TrackSimilarity.Similarity(trackQuery, track));
		}

		[Test]
		public void Similarity_TitleSlightlyDifferent()
		{
			var trackQuery = new TrackQuery { TrackTitle = "track", TrackNumber = 3, TrackLength = new TimeSpan(0, 0, 2, 34) };
			var track = new Track {TrackTitle = "tracker", TrackNumber = 3, TrackLength = new TimeSpan(0, 0, 2, 34)};
			
			Assert.That(TrackSimilarity.Similarity(trackQuery, track), Is.InRange(.8, .99));
		}

		[Test]
		public void Similarity_TimeSlightlyOff()
		{
			var trackQuery = new TrackQuery { TrackTitle = "track", TrackNumber = 3, TrackLength = new TimeSpan(0, 0, 2, 34) };
			var track = new Track {TrackTitle = "track", TrackNumber = 3, TrackLength = new TimeSpan(0, 0, 2, 30)};

			Assert.That(TrackSimilarity.Similarity(trackQuery, track), Is.InRange(.95, .995));
		}

		[Test]
		public void Similarity_TrackNumberWrong()
		{
			var trackQuery = new TrackQuery { TrackTitle = "track", TrackNumber = 3, TrackLength = new TimeSpan(0, 0, 2, 34) };
			var track = new Track {TrackTitle = "track", TrackNumber = 2, TrackLength = new TimeSpan(0, 0, 2, 34)};

			Assert.That(TrackSimilarity.Similarity(trackQuery, track), Is.InRange(.7, .9));
		}
	}
}
