Added MinOrDefault for IEnumberable<int>

pull/3113/head
Mark McDowall 13 years ago
parent aa2a3d997a
commit 25aa39e0f3

@ -125,8 +125,8 @@
<virtualDirectory path="/" physicalPath="%NZBDRONE_PATH%\NZBDrone.Web" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:8980:localhost" />
<binding protocol="http" bindingInformation="*:8980:" />
<binding protocol="http" bindingInformation="*:8989:localhost" />
<binding protocol="http" bindingInformation="*:8989:" />
</bindings>
</site>
<applicationDefaults applicationPool="IISExpressAppPool" />
@ -698,8 +698,8 @@
<system.webServer>
<security>
<authentication>
<anonymousAuthentication enabled="false" />
<windowsAuthentication enabled="true" />
<anonymousAuthentication enabled="true" />
<windowsAuthentication enabled="false" />
</authentication>
</security>
</system.webServer>

@ -219,5 +219,31 @@ namespace NzbDrone.Core.Test
var result = new System.Text.UTF8Encoding().GetBytes(resultString);
result.Length.Should().Be(11);
}
[Test]
public void MinOrDefault_should_return_zero_when_collection_is_empty()
{
//Setup
//Act
var result = (new List<int>()).MinOrDefault();
//Resolve
result.Should().Be(0);
}
[Test]
public void MinOrDefault_should_return_max_when_collection_is_not_empty()
{
//Setup
var list = new List<int> { 6, 4, 5, 3, 8, 10 };
//Act
var result = list.MinOrDefault();
//Resolve
result.Should().Be(3);
}
}
}

@ -57,7 +57,7 @@ namespace NzbDrone.Core
{
var intList = ints.ToList();
if (intList.Count() == 0)
if (!intList.Any())
return 0;
return intList.Max();
@ -142,5 +142,15 @@ namespace NzbDrone.Core
return String.Format("{0:N" + precision + "} {1}", size, suffix);
}
public static int MinOrDefault(this IEnumerable<int> ints)
{
var intsList = ints.ToList();
if (!intsList.Any())
return 0;
return intsList.Min();
}
}
}

Loading…
Cancel
Save