1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-05 02:22:31 +01:00

Fixed: Treat any CF over Cutoff as Cutoff Met

This commit is contained in:
Qstick 2020-01-01 21:13:57 -05:00
parent 0f9c6038ca
commit 503f7286b9
2 changed files with 61 additions and 15 deletions

View File

@ -16,6 +16,8 @@ public class QualityModelComparerFixture : CoreTest
private CustomFormat _customFormat1;
private CustomFormat _customFormat2;
private CustomFormat _customFormat3;
private CustomFormat _customFormat4;
[SetUp]
public void Setup()
@ -80,10 +82,12 @@ private void GivenDefaultProfileWithFormats()
{
_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 @@ public void should_respect_group_order()
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);
}
}
}

View File

@ -79,20 +79,10 @@ public static List<int> GetIndicies(List<CustomFormat> formats, Profile profile)
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 @@ public int Compare(List<CustomFormat> left, int right)
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();
}
}
}