Fixed: Treat any CF over Cutoff as Cutoff Met

pull/2/head
Qstick 5 years ago
parent 0f9c6038ca
commit 503f7286b9

@ -16,6 +16,8 @@ namespace NzbDrone.Core.Test.Qualities
private CustomFormat _customFormat1;
private CustomFormat _customFormat2;
private CustomFormat _customFormat3;
private CustomFormat _customFormat4;
[SetUp]
public void Setup()
@ -80,10 +82,12 @@ namespace NzbDrone.Core.Test.Qualities
{
_customFormat1 = new CustomFormat("My Format 1", "L_ENGLISH") { Id = 1 };
_customFormat2 = new CustomFormat("My Format 2", "L_FRENCH") { Id = 2 };
_customFormat3 = new CustomFormat("My Format 3", "L_SPANISH") { Id = 3 };
_customFormat4 = new CustomFormat("My Format 4", "L_ITALIAN") { Id = 4 };
CustomFormatsFixture.GivenCustomFormats(CustomFormat.None, _customFormat1, _customFormat2);
CustomFormatsFixture.GivenCustomFormats(CustomFormat.None, _customFormat1, _customFormat2, _customFormat3, _customFormat4);
Subject = new QualityModelComparer(new Profile { Items = QualityFixture.GetDefaultQualities(), FormatItems = CustomFormatsFixture.GetSampleFormatItems() });
Subject = new QualityModelComparer(new Profile { Items = QualityFixture.GetDefaultQualities(), FormatItems = CustomFormatsFixture.GetSampleFormatItems(), FormatCutoff = _customFormat2.Id });
}
[Test]
@ -189,5 +193,57 @@ namespace NzbDrone.Core.Test.Qualities
compare.Should().BeLessThan(0);
}
[Test]
public void should_be_greater_when_one_format_over_cutoff()
{
GivenDefaultProfileWithFormats();
var first = new List<CustomFormat> { _customFormat3 };
var second = _customFormat2.Id;
var compare = Subject.Compare(first, second);
compare.Should().BeGreaterThan(0);
}
[Test]
public void should_be_greater_when_multiple_formats_over_cutoff()
{
GivenDefaultProfileWithFormats();
var first = new List<CustomFormat> { _customFormat3, _customFormat4 };
var second = _customFormat2.Id;
var compare = Subject.Compare(first, second);
compare.Should().BeGreaterThan(0);
}
[Test]
public void should_be_greater_when_one_better_one_worse_than_cutoff()
{
GivenDefaultProfileWithFormats();
var first = new List<CustomFormat> { _customFormat1, _customFormat3 };
var second = _customFormat2.Id;
var compare = Subject.Compare(first, second);
compare.Should().BeGreaterThan(0);
}
[Test]
public void should_be_zero_when_one_worse_one_equal_to_cutoff()
{
GivenDefaultProfileWithFormats();
var first = new List<CustomFormat> { _customFormat1, _customFormat2 };
var second = _customFormat2.Id;
var compare = Subject.Compare(first, second);
compare.Should().Be(0);
}
}
}

@ -79,20 +79,10 @@ namespace NzbDrone.Core.Qualities
public int Compare(CustomFormat left, CustomFormat right)
{
int leftIndex = _profile.FormatItems.FindIndex(v => Equals(v.Format, left));
int rightIndex = _profile.FormatItems.FindIndex(v => Equals(v.Format, right));
return leftIndex.CompareTo(rightIndex);
}
public int Compare(List<CustomFormat> left, CustomFormat right)
{
left = left.WithNone();
var leftIndicies = GetIndicies(left, _profile);
var leftIndex = _profile.FormatItems.FindIndex(v => Equals(v.Format, left));
var rightIndex = _profile.FormatItems.FindIndex(v => Equals(v.Format, right));
return leftIndicies.Select(i => i.CompareTo(rightIndex)).Sum();
return leftIndex.CompareTo(rightIndex);
}
public int Compare(List<CustomFormat> left, int right)
@ -102,7 +92,7 @@ namespace NzbDrone.Core.Qualities
var leftIndicies = GetIndicies(left, _profile);
var rightIndex = _profile.FormatItems.FindIndex(v => Equals(v.Format.Id, right));
return leftIndicies.Select(i => i.CompareTo(rightIndex)).Sum();
return leftIndicies.Select(i => i.CompareTo(rightIndex)).Max();
}
}
}

Loading…
Cancel
Save