mirror of
https://github.com/Radarr/Radarr.git
synced 2024-10-05 23:57:20 +02:00
Fixed: Treat any CF over Cutoff as Cutoff Met
This commit is contained in:
parent
0f9c6038ca
commit
503f7286b9
@ -16,6 +16,8 @@ public class QualityModelComparerFixture : CoreTest
|
|||||||
|
|
||||||
private CustomFormat _customFormat1;
|
private CustomFormat _customFormat1;
|
||||||
private CustomFormat _customFormat2;
|
private CustomFormat _customFormat2;
|
||||||
|
private CustomFormat _customFormat3;
|
||||||
|
private CustomFormat _customFormat4;
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void Setup()
|
public void Setup()
|
||||||
@ -80,10 +82,12 @@ private void GivenDefaultProfileWithFormats()
|
|||||||
{
|
{
|
||||||
_customFormat1 = new CustomFormat("My Format 1", "L_ENGLISH") { Id = 1 };
|
_customFormat1 = new CustomFormat("My Format 1", "L_ENGLISH") { Id = 1 };
|
||||||
_customFormat2 = new CustomFormat("My Format 2", "L_FRENCH") { Id = 2 };
|
_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]
|
[Test]
|
||||||
@ -189,5 +193,57 @@ public void should_respect_group_order()
|
|||||||
|
|
||||||
compare.Should().BeLessThan(0);
|
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 @@ public static List<int> GetIndicies(List<CustomFormat> formats, Profile profile)
|
|||||||
|
|
||||||
public int Compare(CustomFormat left, CustomFormat right)
|
public int Compare(CustomFormat left, CustomFormat right)
|
||||||
{
|
{
|
||||||
int leftIndex = _profile.FormatItems.FindIndex(v => Equals(v.Format, left));
|
var 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 rightIndex = _profile.FormatItems.FindIndex(v => Equals(v.Format, right));
|
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)
|
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 leftIndicies = GetIndicies(left, _profile);
|
||||||
var rightIndex = _profile.FormatItems.FindIndex(v => Equals(v.Format.Id, right));
|
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…
Reference in New Issue
Block a user