-
Notifications
You must be signed in to change notification settings - Fork 964
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #294 from mexx/bytesize-untyped-comparison
provide untyped comparison for ByteSize
- Loading branch information
Showing
5 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Humanizer.Bytes; | ||
using Xunit; | ||
using Xunit.Extensions; | ||
|
||
namespace Humanizer.Tests.Bytes | ||
{ | ||
public class ComparingTests | ||
{ | ||
[Theory] | ||
[InlineData(13, 23, -1)] | ||
[InlineData(23, 23, 0)] | ||
[InlineData(45, 23, 1)] | ||
public void CompareStrongTyped(double value, double valueToCompareWith, int expectedResult) | ||
{ | ||
var valueSize = new ByteSize(value); | ||
var otherSize = new ByteSize(valueToCompareWith); | ||
var result = valueSize.CompareTo(otherSize); | ||
|
||
Assert.Equal(expectedResult, result); | ||
} | ||
|
||
[Theory] | ||
[InlineData(13, 23, -1)] | ||
[InlineData(23, 23, 0)] | ||
[InlineData(45, 23, 1)] | ||
public void CompareUntyped(double value, double valueToCompareWith, int expectedResult) | ||
{ | ||
var valueSize = new ByteSize(value); | ||
object otherSize = new ByteSize(valueToCompareWith); | ||
var result = valueSize.CompareTo(otherSize); | ||
|
||
Assert.Equal(expectedResult, result); | ||
} | ||
|
||
[Theory] | ||
[InlineData(new[] { "1GB", "3KB", "5MB" }, new[] { "3KB", "5MB", "1GB"})] | ||
[InlineData(new[] { "1MB", "3KB", "5MB" }, new[] { "3KB", "1MB", "5MB"})] | ||
public void SortList(IEnumerable<string> values, IEnumerable<string> expected) | ||
{ | ||
var list = values.Select(ByteSize.Parse).ToList(); | ||
list.Sort(); | ||
|
||
Assert.Equal(expected.Select(ByteSize.Parse), list); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters