From b29472039cd42330f3a75833f748a724154c07d0 Mon Sep 17 00:00:00 2001 From: brz Date: Tue, 23 Dec 2014 06:31:45 +0330 Subject: [PATCH] Added ByteSizeExtensions method for long inputs --- release_notes.md | 1 + ...provalTest.approve_public_api.approved.txt | 5 ++ .../Bytes/ByteSizeExtensionsTests.cs | 35 +++++++++++++ src/Humanizer/Bytes/ByteSizeExtensions.cs | 50 +++++++++++++++++++ 4 files changed, 91 insertions(+) diff --git a/release_notes.md b/release_notes.md index f2547f820..cbe7a6bdf 100644 --- a/release_notes.md +++ b/release_notes.md @@ -1,5 +1,6 @@ ###In Development + - [#365](https://github.com/MehdiK/Humanizer/pull/365): Added ByteSizeExtensions method for long inputs - [#364](https://github.com/MehdiK/Humanizer/pull/364): Added "campuses" as plural of "campus" - [#363](https://github.com/MehdiK/Humanizer/pull/363): Use RegexOptions.Compiled if available diff --git a/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.approve_public_api.approved.txt b/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.approve_public_api.approved.txt index a7f24d443..955bf1c34 100644 --- a/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.approve_public_api.approved.txt +++ b/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.approve_public_api.approved.txt @@ -71,6 +71,7 @@ public class ByteSizeExtensions public Humanizer.Bytes.ByteSize Bytes(int input) { } public Humanizer.Bytes.ByteSize Bytes(uint input) { } public Humanizer.Bytes.ByteSize Bytes(double input) { } + public Humanizer.Bytes.ByteSize Bytes(long input) { } public Humanizer.Bytes.ByteSize Gigabytes(byte input) { } public Humanizer.Bytes.ByteSize Gigabytes(sbyte input) { } public Humanizer.Bytes.ByteSize Gigabytes(short input) { } @@ -78,6 +79,7 @@ public class ByteSizeExtensions public Humanizer.Bytes.ByteSize Gigabytes(int input) { } public Humanizer.Bytes.ByteSize Gigabytes(uint input) { } public Humanizer.Bytes.ByteSize Gigabytes(double input) { } + public Humanizer.Bytes.ByteSize Gigabytes(long input) { } public string Humanize(Humanizer.Bytes.ByteSize input, string format) { } public Humanizer.Bytes.ByteSize Kilobytes(byte input) { } public Humanizer.Bytes.ByteSize Kilobytes(sbyte input) { } @@ -86,6 +88,7 @@ public class ByteSizeExtensions public Humanizer.Bytes.ByteSize Kilobytes(int input) { } public Humanizer.Bytes.ByteSize Kilobytes(uint input) { } public Humanizer.Bytes.ByteSize Kilobytes(double input) { } + public Humanizer.Bytes.ByteSize Kilobytes(long input) { } public Humanizer.Bytes.ByteSize Megabytes(byte input) { } public Humanizer.Bytes.ByteSize Megabytes(sbyte input) { } public Humanizer.Bytes.ByteSize Megabytes(short input) { } @@ -93,6 +96,7 @@ public class ByteSizeExtensions public Humanizer.Bytes.ByteSize Megabytes(int input) { } public Humanizer.Bytes.ByteSize Megabytes(uint input) { } public Humanizer.Bytes.ByteSize Megabytes(double input) { } + public Humanizer.Bytes.ByteSize Megabytes(long input) { } public Humanizer.Bytes.ByteRate Per(Humanizer.Bytes.ByteSize size, System.TimeSpan interval) { } public Humanizer.Bytes.ByteSize Terabytes(byte input) { } public Humanizer.Bytes.ByteSize Terabytes(sbyte input) { } @@ -101,6 +105,7 @@ public class ByteSizeExtensions public Humanizer.Bytes.ByteSize Terabytes(int input) { } public Humanizer.Bytes.ByteSize Terabytes(uint input) { } public Humanizer.Bytes.ByteSize Terabytes(double input) { } + public Humanizer.Bytes.ByteSize Terabytes(long input) { } } public class CasingExtensions diff --git a/src/Humanizer.Tests/Bytes/ByteSizeExtensionsTests.cs b/src/Humanizer.Tests/Bytes/ByteSizeExtensionsTests.cs index 4ed19d7b4..9ff6500ac 100644 --- a/src/Humanizer.Tests/Bytes/ByteSizeExtensionsTests.cs +++ b/src/Humanizer.Tests/Bytes/ByteSizeExtensionsTests.cs @@ -57,6 +57,13 @@ public void DoubleTerabytes() Assert.Equal(ByteSize.FromTerabytes(size), size.Terabytes()); } + [Fact] + public void LongTerabytes() + { + const long size = 2; + Assert.Equal(ByteSize.FromTerabytes(size), size.Terabytes()); + } + [Theory] [InlineData(2, null, "2 TB")] [InlineData(2, "GB", "2048 GB")] @@ -115,6 +122,13 @@ public void DoubleGigabytes() Assert.Equal(ByteSize.FromGigabytes(size), size.Gigabytes()); } + [Fact] + public void LongGigabytes() + { + const long size = 2; + Assert.Equal(ByteSize.FromGigabytes(size), size.Gigabytes()); + } + [Theory] [InlineData(2, null, "2 GB")] [InlineData(2, "MB", "2048 MB")] @@ -173,6 +187,13 @@ public void DoubleMegabytes() Assert.Equal(ByteSize.FromMegabytes(size), size.Megabytes()); } + [Fact] + public void LongMegabytes() + { + const long size = 2; + Assert.Equal(ByteSize.FromMegabytes(size), size.Megabytes()); + } + [Theory] [InlineData(2, null, "2 MB")] [InlineData(2, "KB", "2048 KB")] @@ -231,6 +252,13 @@ public void DoubleKilobytes() Assert.Equal(ByteSize.FromKilobytes(size), size.Kilobytes()); } + [Fact] + public void LongKilobytes() + { + const long size = 2; + Assert.Equal(ByteSize.FromKilobytes(size), size.Kilobytes()); + } + [Theory] [InlineData(2, null, "2 KB")] [InlineData(2, "B", "2048 B")] @@ -289,6 +317,13 @@ public void DoubleBytes() Assert.Equal(ByteSize.FromBytes(size), size.Bytes()); } + [Fact] + public void LongBytes() + { + const long size = 2; + Assert.Equal(ByteSize.FromBytes(size), size.Bytes()); + } + [Theory] [InlineData(2, null, "2 B")] [InlineData(2000, "KB", "1.95 KB")] diff --git a/src/Humanizer/Bytes/ByteSizeExtensions.cs b/src/Humanizer/Bytes/ByteSizeExtensions.cs index 2fbd7a784..b16ad5992 100644 --- a/src/Humanizer/Bytes/ByteSizeExtensions.cs +++ b/src/Humanizer/Bytes/ByteSizeExtensions.cs @@ -149,6 +149,16 @@ public static ByteSize Bytes(this double input) return ByteSize.FromBytes(input); } + /// + /// Considers input as bytes + /// + /// + /// + public static ByteSize Bytes(this long input) + { + return ByteSize.FromBytes(input); + } + /// /// Considers input as kilobytes /// @@ -219,6 +229,16 @@ public static ByteSize Kilobytes(this double input) return ByteSize.FromKilobytes(input); } + /// + /// Considers input as kilobytes + /// + /// + /// + public static ByteSize Kilobytes(this long input) + { + return ByteSize.FromKilobytes(input); + } + /// /// Considers input as megabytes /// @@ -289,6 +309,16 @@ public static ByteSize Megabytes(this double input) return ByteSize.FromMegabytes(input); } + /// + /// Considers input as megabytes + /// + /// + /// + public static ByteSize Megabytes(this long input) + { + return ByteSize.FromMegabytes(input); + } + /// /// Considers input as gigabytes /// @@ -359,6 +389,16 @@ public static ByteSize Gigabytes(this double input) return ByteSize.FromGigabytes(input); } + /// + /// Considers input as gigabytes + /// + /// + /// + public static ByteSize Gigabytes(this long input) + { + return ByteSize.FromGigabytes(input); + } + /// /// Considers input as terabytes /// @@ -429,6 +469,16 @@ public static ByteSize Terabytes(this double input) return ByteSize.FromTerabytes(input); } + /// + /// Considers input as terabytes + /// + /// + /// + public static ByteSize Terabytes(this long input) + { + return ByteSize.FromTerabytes(input); + } + /// /// Turns a byte quantity into human readable form, eg 2 GB ///