Skip to content

Commit

Permalink
Fix Highest/Lowest comparisons with unbounded bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
dbent committed Dec 14, 2016
1 parent 0763a89 commit c36ace0
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
12 changes: 10 additions & 2 deletions Core/Versioning/KspVersionBound.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ public static KspVersionBound Lowest(params KspVersionBound[] versionBounds)
if (versionBounds.Any(i => i == null))
throw new ArgumentException("Value cannot contain null.", "versionBounds");

return versionBounds.OrderBy(i => i.Value).ThenBy(i => i.Inclusive).First();
return versionBounds
.OrderBy(i => i == Unbounded)
.ThenBy(i => i.Value)
.ThenBy(i => i.Inclusive)
.First();
}

/// <summary>
Expand All @@ -115,7 +119,11 @@ public static KspVersionBound Highest(params KspVersionBound[] versionBounds)
if (versionBounds.Any(i => i == null))
throw new ArgumentException("Value cannot contain null.", "versionBounds");

return versionBounds.OrderByDescending(i => i.Value).ThenBy(i => i.Inclusive).First();
return versionBounds
.OrderBy(i => i == Unbounded)
.ThenByDescending(i => i.Value)
.ThenBy(i => i.Inclusive)
.First();
}
}
}
47 changes: 46 additions & 1 deletion Tests/Core/Versioning/KspVersionRangeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,51 @@ public sealed class KspVersionRangeTests
),
null
},
new object[]
{
new KspVersionRange(
new KspVersionBound(new KspVersion(1, 0, 4, 0), true),
new KspVersionBound()
),
new KspVersionRange(
new KspVersionBound(new KspVersion(1, 0, 4, 0), true),
new KspVersionBound(new KspVersion(1, 0, 5, 0), false)
),
new KspVersionRange(
new KspVersionBound(new KspVersion(1, 0, 4, 0), true),
new KspVersionBound(new KspVersion(1, 0, 5, 0), false)
)
},
new object[]
{
new KspVersionRange(
new KspVersionBound(),
new KspVersionBound(new KspVersion(1, 0, 4, 0), true)
),
new KspVersionRange(
new KspVersionBound(new KspVersion(1, 0, 4, 0), true),
new KspVersionBound(new KspVersion(1, 0, 5, 0), false)
),
new KspVersionRange(
new KspVersionBound(new KspVersion(1, 0, 4, 0), true),
new KspVersionBound(new KspVersion(1, 0, 4, 0), true)
)
},
new object[]
{
new KspVersionRange(
new KspVersionBound(),
new KspVersionBound(new KspVersion(1, 0, 4, 0), false)
),
new KspVersionRange(
new KspVersionBound(new KspVersion(1, 0, 3, 0), true),
new KspVersionBound(new KspVersion(1, 0, 4, 0), false)
),
new KspVersionRange(
new KspVersionBound(new KspVersion(1, 0, 3, 0), true),
new KspVersionBound(new KspVersion(1, 0, 4, 0), false)
)
}
};

private static readonly object[] IsSupersetOfCases =
Expand Down Expand Up @@ -376,7 +421,7 @@ public sealed class KspVersionRangeTests
new KspVersionBound(new KspVersion(2, 0, 0, 0), true)
),
true
}
},
};

[Test]
Expand Down

0 comments on commit c36ace0

Please sign in to comment.