From 503f7286b94a823ed8ab7113563e790fb9731e1a Mon Sep 17 00:00:00 2001 From: Qstick Date: Wed, 1 Jan 2020 21:13:57 -0500 Subject: [PATCH] Fixed: Treat any CF over Cutoff as Cutoff Met --- .../Qualities/QualityModelComparerFixture.cs | 60 ++++++++++++++++++- .../Qualities/QualityModelComparer.cs | 16 +---- 2 files changed, 61 insertions(+), 15 deletions(-) diff --git a/src/NzbDrone.Core.Test/Qualities/QualityModelComparerFixture.cs b/src/NzbDrone.Core.Test/Qualities/QualityModelComparerFixture.cs index 834208c47..1fe68807c 100644 --- a/src/NzbDrone.Core.Test/Qualities/QualityModelComparerFixture.cs +++ b/src/NzbDrone.Core.Test/Qualities/QualityModelComparerFixture.cs @@ -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 { _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 { _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 { _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 { _customFormat1, _customFormat2 }; + var second = _customFormat2.Id; + + var compare = Subject.Compare(first, second); + + compare.Should().Be(0); + } } } diff --git a/src/NzbDrone.Core/Qualities/QualityModelComparer.cs b/src/NzbDrone.Core/Qualities/QualityModelComparer.cs index 62972de52..a08bb1968 100644 --- a/src/NzbDrone.Core/Qualities/QualityModelComparer.cs +++ b/src/NzbDrone.Core/Qualities/QualityModelComparer.cs @@ -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 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 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(); } } }