using System;
using System.Linq;
using MusicMetaTagger.Core.Utility;
using NUnit.Framework;

namespace MusicMetaTagger.Client.Tests.Utility
{
	[TestFixture]
	public class StringUtilityTests
	{
		[Test]
		public void Similarity_ExactMatch()
		{
			var result = StringUtility.Similarity("hey", "hey");
			Assert.AreEqual(1, result);
		}

		[Test, ExpectedException(typeof(ArgumentNullException))]
		public void Similarity_EmptyStrings()
		{
			StringUtility.Similarity("", "");
		}

		[Test]
		public void Similarity_AppleToOrange()
		{
			var similarity = StringUtility.Similarity("apple", "orange");
			Assert.That(similarity, Is.InRange(.1, .2));
		}

		[Test]
		public void Similarity_AppleToMaple()
		{
			var similarity = StringUtility.Similarity("apple", "maple");
			Assert.That(similarity, Is.InRange(.5, .6));
		}

		[Test]
		public void ProgressiveCleaner_ReplacesSlash()
		{
			const string s = @"East/West";
			Func<string, bool[]> foo = str => new []{str.Contains("-")};
			var result = StringUtility.ProgressiveCleaner(foo, s).ToList();
			Assert.IsTrue(result[0]);
		}

		[Test]
		public void ProgressiveCleaner_RunsAll()
		{
			const string s = @"East/West : The Next Generation";
			Func<string, bool[]> foo = str => new bool[0];
			var result = StringUtility.ProgressiveCleaner(foo, s).ToList();
			Assert.IsFalse(result.Any());
		}
	}
}
