Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ByteSizeExtensions method for long inputs #365

Merged
merged 1 commit into from
Dec 23, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions release_notes.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@ 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) { }
public Humanizer.Bytes.ByteSize Gigabytes(ushort input) { }
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) { }
Expand All @@ -86,13 +88,15 @@ 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) { }
public Humanizer.Bytes.ByteSize Megabytes(ushort input) { }
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) { }
Expand All @@ -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
Expand Down
35 changes: 35 additions & 0 deletions src/Humanizer.Tests/Bytes/ByteSizeExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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")]
Expand Down Expand Up @@ -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")]
Expand Down Expand Up @@ -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")]
Expand Down Expand Up @@ -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")]
Expand Down
50 changes: 50 additions & 0 deletions src/Humanizer/Bytes/ByteSizeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,16 @@ public static ByteSize Bytes(this double input)
return ByteSize.FromBytes(input);
}

/// <summary>
/// Considers input as bytes
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public static ByteSize Bytes(this long input)
{
return ByteSize.FromBytes(input);
}

/// <summary>
/// Considers input as kilobytes
/// </summary>
Expand Down Expand Up @@ -219,6 +229,16 @@ public static ByteSize Kilobytes(this double input)
return ByteSize.FromKilobytes(input);
}

/// <summary>
/// Considers input as kilobytes
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public static ByteSize Kilobytes(this long input)
{
return ByteSize.FromKilobytes(input);
}

/// <summary>
/// Considers input as megabytes
/// </summary>
Expand Down Expand Up @@ -289,6 +309,16 @@ public static ByteSize Megabytes(this double input)
return ByteSize.FromMegabytes(input);
}

/// <summary>
/// Considers input as megabytes
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public static ByteSize Megabytes(this long input)
{
return ByteSize.FromMegabytes(input);
}

/// <summary>
/// Considers input as gigabytes
/// </summary>
Expand Down Expand Up @@ -359,6 +389,16 @@ public static ByteSize Gigabytes(this double input)
return ByteSize.FromGigabytes(input);
}

/// <summary>
/// Considers input as gigabytes
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public static ByteSize Gigabytes(this long input)
{
return ByteSize.FromGigabytes(input);
}

/// <summary>
/// Considers input as terabytes
/// </summary>
Expand Down Expand Up @@ -429,6 +469,16 @@ public static ByteSize Terabytes(this double input)
return ByteSize.FromTerabytes(input);
}

/// <summary>
/// Considers input as terabytes
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public static ByteSize Terabytes(this long input)
{
return ByteSize.FromTerabytes(input);
}

/// <summary>
/// Turns a byte quantity into human readable form, eg 2 GB
/// </summary>
Expand Down