mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-18 21:34:28 -04:00
Fixed: Search results from trakt are now sorted based on similarity with the search query.
Using a Levenshtein distance algorithm.
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Common.Test
|
||||
{
|
||||
[TestFixture]
|
||||
public class LevenshteinDistanceFixture : TestBase
|
||||
{
|
||||
[TestCase("", "", 0)]
|
||||
[TestCase("abc", "abc", 0)]
|
||||
[TestCase("abc", "abcd", 1)]
|
||||
[TestCase("abcd", "abc", 1)]
|
||||
[TestCase("abc", "abd", 1)]
|
||||
[TestCase("abc", "adc", 1)]
|
||||
[TestCase("abcdefgh", "abcghdef", 4)]
|
||||
[TestCase("a.b.c.", "abc", 3)]
|
||||
[TestCase("Agents Of SHIELD", "Marvel's Agents Of S.H.I.E.L.D.", 15)]
|
||||
[TestCase("Agents of cracked", "Agents of shield", 6)]
|
||||
[TestCase("ABCxxx", "ABC1xx", 1)]
|
||||
[TestCase("ABC1xx", "ABCxxx", 1)]
|
||||
public void LevenshteinDistance(String text, String other, Int32 expected)
|
||||
{
|
||||
text.LevenshteinDistance(other).Should().Be(expected);
|
||||
}
|
||||
|
||||
[TestCase("", "", 0)]
|
||||
[TestCase("abc", "abc", 0)]
|
||||
[TestCase("abc", "abcd", 1)]
|
||||
[TestCase("abcd", "abc", 3)]
|
||||
[TestCase("abc", "abd", 3)]
|
||||
[TestCase("abc", "adc", 3)]
|
||||
[TestCase("abcdefgh", "abcghdef", 8)]
|
||||
[TestCase("a.b.c.", "abc", 0)]
|
||||
[TestCase("Agents of shield", "Marvel's Agents Of S.H.I.E.L.D.", 9)]
|
||||
[TestCase("Agents of shield", "Agents of cracked", 14)]
|
||||
[TestCase("Agents of shield", "the shield", 24)]
|
||||
[TestCase("ABCxxx", "ABC1xx", 3)]
|
||||
[TestCase("ABC1xx", "ABCxxx", 3)]
|
||||
public void LevenshteinDistanceClean(String text, String other, Int32 expected)
|
||||
{
|
||||
text.ToLower().LevenshteinDistanceClean(other.ToLower()).Should().Be(expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,6 +67,7 @@
|
||||
<Compile Include="EnsureTest\PathExtensionFixture.cs" />
|
||||
<Compile Include="EnvironmentTests\StartupArgumentsFixture.cs" />
|
||||
<Compile Include="EnvironmentTests\EnvironmentProviderTest.cs" />
|
||||
<Compile Include="LevenshteinDistanceFixture.cs" />
|
||||
<Compile Include="ReflectionExtensions.cs" />
|
||||
<Compile Include="PathExtensionFixture.cs" />
|
||||
<Compile Include="DiskProviderTests\DiskProviderFixtureBase.cs" />
|
||||
|
||||
Reference in New Issue
Block a user