Fixed: Identification failing if book metadata has no authors

pull/1017/head
ta264 3 years ago
parent 146fe04cce
commit 11577b6db9

@ -131,6 +131,38 @@ namespace NzbDrone.Core.Test.MediaFiles.BookImport.Identification
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { { "string", new List<double> { 0.0 } } }); dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { { "string", new List<double> { 0.0 } } });
} }
[Test]
public void test_add_string_empty_values_valid_target()
{
var dist = new Distance();
dist.AddString("string", new List<string>(), "target");
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { { "string", new List<double> { 1.0 } } });
}
[Test]
public void test_add_string_empty_values_empty_target()
{
var dist = new Distance();
dist.AddString("string", new List<string>(), string.Empty);
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { { "string", new List<double> { 0.0 } } });
}
[Test]
public void test_add_string_empty_options_valid_value()
{
var dist = new Distance();
dist.AddString("string", "value", new List<string>());
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { { "string", new List<double> { 1.0 } } });
}
[Test]
public void test_add_string_empty_options_empty_value()
{
var dist = new Distance();
dist.AddString("string", string.Empty, new List<string>());
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { { "string", new List<double> { 0.0 } } });
}
[Test] [Test]
public void test_distance() public void test_distance()
{ {

@ -151,12 +151,26 @@ namespace NzbDrone.Core.MediaFiles.BookImport.Identification
public void AddString(string key, string value, List<string> options) public void AddString(string key, string value, List<string> options)
{ {
Add(key, options.Min(x => StringScore(value, x))); if (!options.Any())
{
Add(key, StringScore(value, string.Empty));
}
else
{
Add(key, options.Min(x => StringScore(value, x)));
}
} }
public void AddString(string key, List<string> values, string target) public void AddString(string key, List<string> values, string target)
{ {
Add(key, values.Min(v => StringScore(v, target))); if (!values.Any())
{
Add(key, StringScore(string.Empty, target));
}
else
{
Add(key, values.Min(v => StringScore(v, target)));
}
} }
public void AddBool(string key, bool expr) public void AddBool(string key, bool expr)

Loading…
Cancel
Save