mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-18 21:34:28 -04:00
Improve the fuzzy matching (#522)
* Fixed: improve track matching * Deal with tracks sequentially numbered across discs
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Common.Test
|
||||
{
|
||||
[TestFixture]
|
||||
public class FuzzyContainsFixture : TestBase
|
||||
{
|
||||
[TestCase("abcdef", "abcdef", 0.5, 0)]
|
||||
[TestCase("", "abcdef", 0.5, -1)]
|
||||
[TestCase("abcdef", "", 0.5, -1)]
|
||||
[TestCase("", "", 0.5, -1)]
|
||||
[TestCase("abcdef", "de", 0.5, 3)]
|
||||
[TestCase("abcdef", "defy", 0.5, 3)]
|
||||
[TestCase("abcdef", "abcdefy", 0.5, 0)]
|
||||
[TestCase("I am the very model of a modern major general.", " that berry ", 0.3, 4)]
|
||||
[TestCase("abcdefghijk", "fgh", 0.5, 5)]
|
||||
[TestCase("abcdefghijk", "fgh", 0.5, 5)]
|
||||
[TestCase("abcdefghijk", "efxhi", 0.5, 4)]
|
||||
[TestCase("abcdefghijk", "cdefxyhijk", 0.5, 2)]
|
||||
[TestCase("abcdefghijk", "bxy", 0.5, -1)]
|
||||
[TestCase("123456789xx0", "3456789x0", 0.5, 2)]
|
||||
[TestCase("abcdef", "xxabc", 0.5, 0)]
|
||||
[TestCase("abcdef", "defyy", 0.5, 3)]
|
||||
[TestCase("abcdef", "xabcdefy", 0.5, 0)]
|
||||
[TestCase("abcdefghijk", "efxyhi", 0.6, 4)]
|
||||
[TestCase("abcdefghijk", "efxyhi", 0.7, -1)]
|
||||
[TestCase("abcdefghijk", "bcdef", 0.0, 1)]
|
||||
[TestCase("abcdexyzabcde", "abccde", 0.5, 0)]
|
||||
[TestCase("abcdefghijklmnopqrstuvwxyz", "abcdxxefg", 0.5, 0)]
|
||||
[TestCase("abcdefghijklmnopqrstuvwxyz", "abcdefg", 0.5, 0)]
|
||||
[TestCase("The quick brown fox jumps over the lazy dog", "The quick brown fox jumps over the lazy d", 0.5, 0)]
|
||||
[TestCase("The quick brown fox jumps over the lazy dog", "The quick brown fox jumps over the lazy g", 0.5, 0)]
|
||||
[TestCase("The quick brown fox jumps over the lazy dog", "quikc brown fox jumps over the lazy dog", 0.5, 4)]
|
||||
[TestCase("The quick brown fox jumps over the lazy dog", "qui jumps over the lazy dog", 0.5, 16)]
|
||||
[TestCase("The quick brown fox jumps over the lazy dog", "quikc brown fox jumps over the lazy dog", 0.5, 4)]
|
||||
[TestCase("u6IEytQiYpzAccsbjQ5ISuE4smDQ1ZiU42cFBrTeKB2XrVLEqAvgIiKlDP75iApy07jzmK", "xEytQiYpzAccsbjQ5ISuE4smDQ1ZiU42cFBrTeKB2XrVLEqAvgIiKlDP75iApy07jzmK", 0.5, 2)]
|
||||
[TestCase("plusifeelneedforredundantinformationintitlefield", "anthology", 0.5, -1)]
|
||||
public void FuzzyFind(string text, string pattern, double threshold, int expected)
|
||||
{
|
||||
text.FuzzyFind(pattern, threshold).Should().Be(expected);
|
||||
}
|
||||
|
||||
[TestCase("abcdef", "abcdef", 1)]
|
||||
[TestCase("", "abcdef", 0)]
|
||||
[TestCase("abcdef", "", 0)]
|
||||
[TestCase("", "", 0)]
|
||||
[TestCase("abcdef", "de", 1)]
|
||||
[TestCase("abcdef", "defy", 0.75)]
|
||||
[TestCase("abcdef", "abcdefghk", 6.0/9)]
|
||||
[TestCase("abcdef", "zabcdefz", 6.0/8)]
|
||||
[TestCase("plusifeelneedforredundantinformationintitlefield", "anthology", 4.0/9)]
|
||||
[TestCase("+ (Plus) - I feel the need for redundant information in the title field", "+", 1)]
|
||||
public void FuzzyContains(string text, string pattern, double expectedScore)
|
||||
{
|
||||
text.FuzzyContains(pattern).Should().BeApproximately(expectedScore, 1e-9);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,5 +42,21 @@ namespace NzbDrone.Common.Test
|
||||
{
|
||||
text.ToLower().LevenshteinDistanceClean(other.ToLower()).Should().Be(expected);
|
||||
}
|
||||
|
||||
[TestCase("hello", "hello")]
|
||||
[TestCase("hello", "bye")]
|
||||
[TestCase("a longer string", "a different long string")]
|
||||
public void FuzzyMatchSymmetric(string a, string b)
|
||||
{
|
||||
a.FuzzyMatch(b).Should().Be(b.FuzzyMatch(a));
|
||||
}
|
||||
|
||||
[TestCase("", "", 0)]
|
||||
[TestCase("a", "", 0)]
|
||||
[TestCase("", "a", 0)]
|
||||
public void FuzzyMatchEmptyValuesReturnZero(string a, string b, double expected)
|
||||
{
|
||||
a.FuzzyMatch(b).Should().Be(expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,6 +84,7 @@
|
||||
<Compile Include="ExtensionTests\IEnumerableExtensionTests\IntersectByFixture.cs" />
|
||||
<Compile Include="ExtensionTests\Int64ExtensionFixture.cs" />
|
||||
<Compile Include="ExtensionTests\UrlExtensionsFixture.cs" />
|
||||
<Compile Include="ExtensionTests\FuzzyContainsFixture.cs" />
|
||||
<Compile Include="HashUtilFixture.cs" />
|
||||
<Compile Include="Http\HttpClientFixture.cs" />
|
||||
<Compile Include="Http\HttpHeaderFixture.cs" />
|
||||
|
||||
Reference in New Issue
Block a user