From 0c6e48ae32292d3f012f4ea8a341aec31c4336ae Mon Sep 17 00:00:00 2001 From: Collin Alpert Date: Sun, 18 Feb 2024 16:06:37 +0100 Subject: [PATCH 1/4] Fix ByteSize implementation in regards to IEC specification --- .../Bytes/ByteSizeExtensionsTests.cs | 316 +++++++++++++++++- ....Approve_Public_Api.DotNet8_0.verified.txt | 38 ++- src/Humanizer/Bytes/ByteSize.cs | 88 ++++- src/Humanizer/Bytes/ByteSizeExtensions.cs | 192 +++++++++++ src/Humanizer/Localisation/DataUnit.cs | 24 +- src/Humanizer/Properties/Resources.de.resx | 12 + src/Humanizer/Properties/Resources.fr.resx | 12 + src/Humanizer/Properties/Resources.resx | 24 ++ 8 files changed, 683 insertions(+), 23 deletions(-) diff --git a/src/Humanizer.Tests.Shared/Bytes/ByteSizeExtensionsTests.cs b/src/Humanizer.Tests.Shared/Bytes/ByteSizeExtensionsTests.cs index 9ccd1c074..a6906be53 100644 --- a/src/Humanizer.Tests.Shared/Bytes/ByteSizeExtensionsTests.cs +++ b/src/Humanizer.Tests.Shared/Bytes/ByteSizeExtensionsTests.cs @@ -62,7 +62,7 @@ public void LongTerabytes() [Theory] [InlineData(2, null, "en", "2 TB")] [InlineData(2, null, "fr", "2 To")] - [InlineData(2, "GB", "en", "2048 GB")] + [InlineData(2, "GB", "en", "2000 GB")] [InlineData(2.1, null, "en", "2.1 TB")] [InlineData(2.123, "#.#", "en", "2.1 TB")] [InlineData(2.1, null, "ru-RU", "2,1 TB")] @@ -74,6 +74,81 @@ public void HumanizesTerabytes(double input, string format, string cultureName, Assert.Equal(expectedValue, input.Terabytes().Humanize(format, culture)); } + [Fact] + public void ByteTebibytes() + { + const byte size = 2; + Assert.Equal(ByteSize.FromTebibytes(size), size.Tebibytes()); + } + + [Fact] + public void SbyteTebibytes() + { + const sbyte size = 2; + Assert.Equal(ByteSize.FromTebibytes(size), size.Tebibytes()); + } + + [Fact] + public void ShortTebibytes() + { + const short size = 2; + Assert.Equal(ByteSize.FromTebibytes(size), size.Tebibytes()); + } + + [Fact] + public void UshortTebibytes() + { + const ushort size = 2; + Assert.Equal(ByteSize.FromTebibytes(size), size.Tebibytes()); + } + + [Fact] + public void IntTebibytes() + { + const int size = 2; + Assert.Equal(ByteSize.FromTebibytes(size), size.Tebibytes()); + } + + [Fact] + public void UintTebibytes() + { + const uint size = 2; + Assert.Equal(ByteSize.FromTebibytes(size), size.Tebibytes()); + } + + [Fact] + public void DoubleTebibytes() + { + const double size = 2; + Assert.Equal(ByteSize.FromTebibytes(size), size.Tebibytes()); + } + + [Fact] + public void LongTebibytes() + { + const long size = 2; + Assert.Equal(ByteSize.FromTebibytes(size), size.Tebibytes()); + } + + [Theory] + [InlineData(2, null, "en", "2.2 TB")] + [InlineData(2, null, "fr", "2,2 To")] + [InlineData(2, "TiB", "en", "2 TiB")] + [InlineData(2, "TiB", "fr", "2 Tio")] + [InlineData(2, "GiB", "en", "2048 GiB")] + [InlineData(2.1, null, "en", "2.31 TB")] + [InlineData(2.1, "TiB", "en", "2.1 TiB")] + [InlineData(2.123, "#.#", "en", "2.3 TB")] + [InlineData(2.123, "#.# TiB", "en", "2.1 TiB")] + [InlineData(2.1, null, "ru-RU", "2,31 TB")] + [InlineData(2.123, "#.# TiB", "ru-RU", "2,1 TiB")] + public void HumanizesTebibytes(double input, string format, string cultureName, string expectedValue) + { + var culture = new CultureInfo(cultureName); + + Assert.Equal(expectedValue, input.Tebibytes().Humanize(format, culture)); + } + [Fact] public void ByteGigabytes() { @@ -135,7 +210,7 @@ public void LongGigabytes() [InlineData(0, "GB", "en", "0 GB")] [InlineData(2, null, "en", "2 GB")] [InlineData(2, null, "fr", "2 Go")] - [InlineData(2, "MB", "en", "2048 MB")] + [InlineData(2, "MB", "en", "2000 MB")] [InlineData(2.123, "#.##", "en", "2.12 GB")] public void HumanizesGigabytes(double input, string format, string cultureName, string expectedValue) { @@ -144,6 +219,79 @@ public void HumanizesGigabytes(double input, string format, string cultureName, Assert.Equal(expectedValue, input.Gigabytes().Humanize(format, cultureInfo)); } + [Fact] + public void ByteGibibytes() + { + const byte size = 2; + Assert.Equal(ByteSize.FromGibibytes(size), size.Gibibytes()); + } + + [Fact] + public void SbyteGibibytes() + { + const sbyte size = 2; + Assert.Equal(ByteSize.FromGibibytes(size), size.Gibibytes()); + } + + [Fact] + public void ShortGibibytes() + { + const short size = 2; + Assert.Equal(ByteSize.FromGibibytes(size), size.Gibibytes()); + } + + [Fact] + public void UshortGibibytes() + { + const ushort size = 2; + Assert.Equal(ByteSize.FromGibibytes(size), size.Gibibytes()); + } + + [Fact] + public void IntGibibytes() + { + const int size = 2; + Assert.Equal(ByteSize.FromGibibytes(size), size.Gibibytes()); + } + + [Fact] + public void UintGibibytes() + { + const uint size = 2; + Assert.Equal(ByteSize.FromGibibytes(size), size.Gibibytes()); + } + + [Fact] + public void DoubleGibibytes() + { + const double size = 2; + Assert.Equal(ByteSize.FromGibibytes(size), size.Gibibytes()); + } + + [Fact] + public void LongGibibytes() + { + const long size = 2; + Assert.Equal(ByteSize.FromGibibytes(size), size.Gibibytes()); + } + + [Theory] + [InlineData(0, null, "en", "0 b")] + [InlineData(0, "GiB", "en", "0 GiB")] + [InlineData(2, null, "en", "2.15 GB")] + [InlineData(2, "GiB", "en", "2 GiB")] + [InlineData(2, null, "fr", "2,15 Go")] + [InlineData(2, "GiB", "fr", "2 Gio")] + [InlineData(2, "MiB", "en", "2048 MiB")] + [InlineData(2.123, "#.##", "en", "2.28 GB")] + [InlineData(2.123, "#.## GiB", "en", "2.12 GiB")] + public void HumanizesGibibytes(double input, string format, string cultureName, string expectedValue) + { + var cultureInfo = new CultureInfo(cultureName); + + Assert.Equal(expectedValue, input.Gibibytes().Humanize(format, cultureInfo)); + } + [Fact] public void ByteMegabytes() { @@ -205,7 +353,7 @@ public void LongMegabytes() [InlineData(0, "MB", "en", "0 MB")] [InlineData(2, null, "en", "2 MB")] [InlineData(2, null, "fr", "2 Mo")] - [InlineData(2, "KB", "en", "2048 KB")] + [InlineData(2, "KB", "en", "2000 KB")] [InlineData(2.123, "#", "en", "2 MB")] public void HumanizesMegabytes(double input, string format, string cultureName, string expectedValue) { @@ -214,6 +362,79 @@ public void HumanizesMegabytes(double input, string format, string cultureName, Assert.Equal(expectedValue, input.Megabytes().Humanize(format, cultureInfo)); } + [Fact] + public void ByteMebibytes() + { + const byte size = 2; + Assert.Equal(ByteSize.FromMebibytes(size), size.Mebibytes()); + } + + [Fact] + public void SbyteMebibytes() + { + const sbyte size = 2; + Assert.Equal(ByteSize.FromMebibytes(size), size.Mebibytes()); + } + + [Fact] + public void ShortMebibytes() + { + const short size = 2; + Assert.Equal(ByteSize.FromMebibytes(size), size.Mebibytes()); + } + + [Fact] + public void UshortMebibytes() + { + const ushort size = 2; + Assert.Equal(ByteSize.FromMebibytes(size), size.Mebibytes()); + } + + [Fact] + public void IntMebibytes() + { + const int size = 2; + Assert.Equal(ByteSize.FromMebibytes(size), size.Mebibytes()); + } + + [Fact] + public void UintMebibytes() + { + const uint size = 2; + Assert.Equal(ByteSize.FromMebibytes(size), size.Mebibytes()); + } + + [Fact] + public void DoubleMebibytes() + { + const double size = 2; + Assert.Equal(ByteSize.FromMebibytes(size), size.Mebibytes()); + } + + [Fact] + public void LongMebibytes() + { + const long size = 2; + Assert.Equal(ByteSize.FromMebibytes(size), size.Mebibytes()); + } + + [Theory] + [InlineData(0, null, "en", "0 b")] + [InlineData(0, "MiB", "en", "0 MiB")] + [InlineData(2, null, "en", "2.1 MB")] + [InlineData(2, "MiB", "en", "2 MiB")] + [InlineData(2, null, "fr", "2,1 Mo")] + [InlineData(2, "MiB", "fr", "2 Mio")] + [InlineData(2, "KiB", "en", "2048 KiB")] + [InlineData(2.123, "#", "en", "2 MB")] + [InlineData(2.123, "# MiB", "en", "2 MiB")] + public void HumanizesMebibytes(double input, string format, string cultureName, string expectedValue) + { + var cultureInfo = new CultureInfo(cultureName); + + Assert.Equal(expectedValue, input.Mebibytes().Humanize(format, cultureInfo)); + } + [Fact] public void ByteKilobytes() { @@ -275,7 +496,7 @@ public void LongKilobytes() [InlineData(0, "KB", "en", "0 KB")] [InlineData(2, null, "en", "2 KB")] [InlineData(2, null, "fr", "2 Ko")] - [InlineData(2, "B", "en", "2048 B")] + [InlineData(2, "B", "en", "2000 B")] [InlineData(2.123, "#.####", "en", "2.123 KB")] public void HumanizesKilobytes(double input, string format, string cultureName, string expectedValue) { @@ -284,6 +505,79 @@ public void HumanizesKilobytes(double input, string format, string cultureName, Assert.Equal(expectedValue, input.Kilobytes().Humanize(format, cultureInfo)); } + [Fact] + public void ByteKibibytes() + { + const byte size = 2; + Assert.Equal(ByteSize.FromKibibytes(size), size.Kibibytes()); + } + + [Fact] + public void SbyteKibibytes() + { + const sbyte size = 2; + Assert.Equal(ByteSize.FromKibibytes(size), size.Kibibytes()); + } + + [Fact] + public void ShortKibibytes() + { + const short size = 2; + Assert.Equal(ByteSize.FromKibibytes(size), size.Kibibytes()); + } + + [Fact] + public void UshortKibibytes() + { + const ushort size = 2; + Assert.Equal(ByteSize.FromKibibytes(size), size.Kibibytes()); + } + + [Fact] + public void IntKibibytes() + { + const int size = 2; + Assert.Equal(ByteSize.FromKibibytes(size), size.Kibibytes()); + } + + [Fact] + public void UintKibibytes() + { + const uint size = 2; + Assert.Equal(ByteSize.FromKibibytes(size), size.Kibibytes()); + } + + [Fact] + public void DoubleKibibytes() + { + const double size = 2; + Assert.Equal(ByteSize.FromKibibytes(size), size.Kibibytes()); + } + + [Fact] + public void LongKibibytes() + { + const long size = 2; + Assert.Equal(ByteSize.FromKibibytes(size), size.Kibibytes()); + } + + [Theory] + [InlineData(0, null, "en", "0 b")] + [InlineData(0, "KiB", "en", "0 KiB")] + [InlineData(2, null, "en", "2.05 KB")] + [InlineData(2, "KiB", "en", "2 KiB")] + [InlineData(2, null, "fr", "2,05 Ko")] + [InlineData(2, "KiB", "fr", "2 Kio")] + [InlineData(2, "B", "en", "2048 B")] + [InlineData(2.123, "#.####", "en", "2.174 KB")] + [InlineData(2.123, "#.#### KiB", "en", "2.123 KiB")] + public void HumanizesKibibytes(double input, string format, string cultureName, string expectedValue) + { + var cultureInfo = new CultureInfo(cultureName); + + Assert.Equal(expectedValue, input.Kibibytes().Humanize(format, cultureInfo)); + } + [Fact] public void ByteBytes() { @@ -347,11 +641,11 @@ public void LongBytes() [InlineData(0, "B", "en", "0 B")] [InlineData(2, null, "en", "2 B")] [InlineData(2, null, "fr", "2 o")] - [InlineData(2000, "KB", "en", "1.95 KB")] - [InlineData(2123, "#.##", "en", "2.07 KB")] - [InlineData(10000000, "KB", "en", "9765.63 KB")] - [InlineData(10000000, "#,##0 KB", "en", "9,766 KB")] - [InlineData(10000000, "#,##0.# KB", "en", "9,765.6 KB")] + [InlineData(2000, "KB", "en", "2 KB")] + [InlineData(2123, "#.##", "en", "2.12 KB")] + [InlineData(10000000, "KB", "en", "10000 KB")] + [InlineData(10000000, "#,##0 KB", "en", "10,000 KB")] + [InlineData(10000000, "#,##0.# KB", "en", "10,000 KB")] public void HumanizesBytes(double input, string format, string cultureName, string expectedValue) { var cultureInfo = new CultureInfo(cultureName); @@ -414,7 +708,9 @@ public void LongBits() [InlineData(2, null, "en", "2 b")] [InlineData(2, null, "fr", "2 b")] [InlineData(12, "B", "en", "1.5 B")] - [InlineData(10000, "#.# KB", "en", "1.2 KB")] + [InlineData(10000, "#.# KB", "en", "1.3 KB")] + [InlineData(30000, "#.# KB", "en", "3.8 KB")] + [InlineData(30000, "#.# KiB", "en", "3.7 KiB")] public void HumanizesBits(long input, string format, string cultureName, string expectedValue) { var cultureInfo = new CultureInfo(cultureName); diff --git a/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.DotNet8_0.verified.txt b/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.DotNet8_0.verified.txt index 7bdc87f93..3d144f6ac 100644 --- a/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.DotNet8_0.verified.txt +++ b/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.DotNet8_0.verified.txt @@ -18,16 +18,28 @@ namespace Humanizer public const long BitsInByte = 8; public const string Byte = "byte"; public const string ByteSymbol = "B"; - public const long BytesInGigabyte = 1073741824; - public const long BytesInKilobyte = 1024; - public const long BytesInMegabyte = 1048576; - public const long BytesInTerabyte = 1099511627776; + public const long BytesInGibibyte = 1073741824; + public const long BytesInGigabyte = 1000000000; + public const long BytesInKibibyte = 1024; + public const long BytesInKilobyte = 1000; + public const long BytesInMebibyte = 1048576; + public const long BytesInMegabyte = 1000000; + public const long BytesInTebibyte = 1099511627776; + public const long BytesInTerabyte = 1000000000000; + public const string Gibibyte = "gibibyte"; + public const string GibibyteSymbol = "GiB"; public const string Gigabyte = "gigabyte"; public const string GigabyteSymbol = "GB"; + public const string Kibibyte = "kibibyte"; + public const string KibibyteSymbol = "KiB"; public const string Kilobyte = "kilobyte"; public const string KilobyteSymbol = "KB"; + public const string Mebibyte = "mebibyte"; + public const string MebibyteSymbol = "MiB"; public const string Megabyte = "megabyte"; public const string MegabyteSymbol = "MB"; + public const string Tebibyte = "tebibyte"; + public const string TebibyteSymbol = "TiB"; public const string Terabyte = "terabyte"; public const string TerabyteSymbol = "TB"; public static readonly Humanizer.ByteSize MaxValue; @@ -35,12 +47,16 @@ namespace Humanizer public ByteSize(double byteSize) { } public long Bits { get; } public double Bytes { get; } + public double Gibibytes { get; } public double Gigabytes { get; } + public double Kibibytes { get; } public double Kilobytes { get; } public string LargestWholeNumberFullWord { get; } public string LargestWholeNumberSymbol { get; } public double LargestWholeNumberValue { get; } + public double Mebibytes { get; } public double Megabytes { get; } + public double Tebibytes { get; } public double Terabytes { get; } public Humanizer.ByteSize Add(Humanizer.ByteSize bs) { } public Humanizer.ByteSize AddBits(long value) { } @@ -64,9 +80,13 @@ namespace Humanizer public string ToString(string format, System.IFormatProvider provider) { } public static Humanizer.ByteSize FromBits(long value) { } public static Humanizer.ByteSize FromBytes(double value) { } + public static Humanizer.ByteSize FromGibibytes(double value) { } public static Humanizer.ByteSize FromGigabytes(double value) { } + public static Humanizer.ByteSize FromKibibytes(double value) { } public static Humanizer.ByteSize FromKilobytes(double value) { } + public static Humanizer.ByteSize FromMebibytes(double value) { } public static Humanizer.ByteSize FromMegabytes(double value) { } + public static Humanizer.ByteSize FromTebibytes(double value) { } public static Humanizer.ByteSize FromTerabytes(double value) { } public static Humanizer.ByteSize Parse(string s) { } public static Humanizer.ByteSize Parse(string s, System.IFormatProvider formatProvider) { } @@ -176,9 +196,13 @@ namespace Humanizer Bit = 0, Byte = 1, Kilobyte = 2, - Megabyte = 3, - Gigabyte = 4, - Terabyte = 5, + Kibibyte = 3, + Megabyte = 4, + Mebibyte = 5, + Gigabyte = 6, + Gibibyte = 7, + Terabyte = 8, + Tebibyte = 9, } public static class DateHumanizeExtensions { diff --git a/src/Humanizer/Bytes/ByteSize.cs b/src/Humanizer/Bytes/ByteSize.cs index 4db2b6cf7..0b000351c 100644 --- a/src/Humanizer/Bytes/ByteSize.cs +++ b/src/Humanizer/Bytes/ByteSize.cs @@ -38,30 +38,46 @@ public struct ByteSize(double byteSize) : public static readonly ByteSize MaxValue = FromBits(long.MaxValue); public const long BitsInByte = 8; - public const long BytesInKilobyte = 1024; - public const long BytesInMegabyte = 1048576; - public const long BytesInGigabyte = 1073741824; - public const long BytesInTerabyte = 1099511627776; + public const long BytesInKilobyte = 1000; + public const long BytesInKibibyte = 1024; + public const long BytesInMegabyte = 1_000_000; + public const long BytesInMebibyte = 1_048_576; + public const long BytesInGigabyte = 1_000_000_000; + public const long BytesInGibibyte = 1_073_741_824; + public const long BytesInTerabyte = 1_000_000_000_000; + public const long BytesInTebibyte = 1_099_511_627_776; public const string BitSymbol = "b"; public const string Bit = "bit"; public const string ByteSymbol = "B"; public const string Byte = "byte"; public const string KilobyteSymbol = "KB"; + public const string KibibyteSymbol = "KiB"; public const string Kilobyte = "kilobyte"; + public const string Kibibyte = "kibibyte"; public const string MegabyteSymbol = "MB"; + public const string MebibyteSymbol = "MiB"; public const string Megabyte = "megabyte"; + public const string Mebibyte = "mebibyte"; public const string GigabyteSymbol = "GB"; + public const string GibibyteSymbol = "GiB"; public const string Gigabyte = "gigabyte"; + public const string Gibibyte = "gibibyte"; public const string TerabyteSymbol = "TB"; + public const string TebibyteSymbol = "TiB"; public const string Terabyte = "terabyte"; + public const string Tebibyte = "tebibyte"; public long Bits { get; } = (long)Math.Ceiling(byteSize * BitsInByte); public double Bytes { get; } = byteSize; public double Kilobytes { get; } = byteSize / BytesInKilobyte; + public double Kibibytes { get; } = byteSize / BytesInKibibyte; public double Megabytes { get; } = byteSize / BytesInMegabyte; + public double Mebibytes { get; } = byteSize / BytesInMebibyte; public double Gigabytes { get; } = byteSize / BytesInGigabyte; + public double Gibibytes { get; } = byteSize / BytesInGibibyte; public double Terabytes { get; } = byteSize / BytesInTerabyte; + public double Tebibytes { get; } = byteSize / BytesInTebibyte; public string LargestWholeNumberSymbol => GetLargestWholeNumberSymbol(); @@ -178,15 +194,27 @@ public static ByteSize FromBytes(double value) => public static ByteSize FromKilobytes(double value) => new(value * BytesInKilobyte); + public static ByteSize FromKibibytes(double value) => + new(value * BytesInKibibyte); + public static ByteSize FromMegabytes(double value) => new(value * BytesInMegabyte); + public static ByteSize FromMebibytes(double value) => + new(value * BytesInMebibyte); + public static ByteSize FromGigabytes(double value) => new(value * BytesInGigabyte); + public static ByteSize FromGibibytes(double value) => + new(value * BytesInGibibyte); + public static ByteSize FromTerabytes(double value) => new(value * BytesInTerabyte); + public static ByteSize FromTebibytes(double value) => + new(value * BytesInTebibyte); + /// /// Converts the value of the current ByteSize object to a string. /// The metric prefix symbol (bit, byte, kilo, mega, giga, tera) used is @@ -241,24 +269,48 @@ string ToString(string format, IFormatProvider provider, bool toSymbol) return output(Terabytes); } + if (has(TebibyteSymbol)) + { + format = format.Replace(TebibyteSymbol, cultureFormatter.DataUnitHumanize(DataUnit.Tebibyte, Tebibytes, toSymbol)); + return output(Tebibytes); + } + if (has(GigabyteSymbol)) { format = format.Replace(GigabyteSymbol, cultureFormatter.DataUnitHumanize(DataUnit.Gigabyte, Gigabytes, toSymbol)); return output(Gigabytes); } + if (has(GibibyteSymbol)) + { + format = format.Replace(GibibyteSymbol, cultureFormatter.DataUnitHumanize(DataUnit.Gibibyte, Gibibytes, toSymbol)); + return output(Gibibytes); + } + if (has(MegabyteSymbol)) { format = format.Replace(MegabyteSymbol, cultureFormatter.DataUnitHumanize(DataUnit.Megabyte, Megabytes, toSymbol)); return output(Megabytes); } + if (has(MebibyteSymbol)) + { + format = format.Replace(MebibyteSymbol, cultureFormatter.DataUnitHumanize(DataUnit.Mebibyte, Mebibytes, toSymbol)); + return output(Mebibytes); + } + if (has(KilobyteSymbol)) { format = format.Replace(KilobyteSymbol, cultureFormatter.DataUnitHumanize(DataUnit.Kilobyte, Kilobytes, toSymbol)); return output(Kilobytes); } + if (has(KibibyteSymbol)) + { + format = format.Replace(KibibyteSymbol, cultureFormatter.DataUnitHumanize(DataUnit.Kibibyte, Kibibytes, toSymbol)); + return output(Kibibytes); + } + // Byte and Bit symbol look must be case-sensitive if (format.IndexOf(ByteSymbol, StringComparison.Ordinal) != -1) { @@ -346,15 +398,27 @@ public ByteSize AddBytes(double value) => public ByteSize AddKilobytes(double value) => this + FromKilobytes(value); + public ByteSize AddKibibytes(double value) => + this + FromKibibytes(value); + public ByteSize AddMegabytes(double value) => this + FromMegabytes(value); + public ByteSize AddMebibytes(double value) => + this + FromMebibytes(value); + public ByteSize AddGigabytes(double value) => this + FromGigabytes(value); + public ByteSize AddGibibytes(double value) => + this + FromGibibytes(value); + public ByteSize AddTerabytes(double value) => this + FromTerabytes(value); + public ByteSize AddTebibytes(double value) => + this + FromTebibytes(value); + public ByteSize Subtract(ByteSize bs) => new(Bytes - bs.Bytes); @@ -474,18 +538,34 @@ public static bool TryParse(string s, IFormatProvider formatProvider, out ByteSi result = FromKilobytes(number); break; + case KibibyteSymbol: + result = FromKibibytes(number); + break; + case MegabyteSymbol: result = FromMegabytes(number); break; + case MebibyteSymbol: + result = FromMebibytes(number); + break; + case GigabyteSymbol: result = FromGigabytes(number); break; + case GibibyteSymbol: + result = FromGibibytes(number); + break; + case TerabyteSymbol: result = FromTerabytes(number); break; + case TebibyteSymbol: + result = FromTebibytes(number); + break; + default: return false; } diff --git a/src/Humanizer/Bytes/ByteSizeExtensions.cs b/src/Humanizer/Bytes/ByteSizeExtensions.cs index ba3c5f292..6762a04fd 100644 --- a/src/Humanizer/Bytes/ByteSizeExtensions.cs +++ b/src/Humanizer/Bytes/ByteSizeExtensions.cs @@ -144,6 +144,54 @@ public static ByteSize Kilobytes(this double input) => public static ByteSize Kilobytes(this long input) => ByteSize.FromKilobytes(input); + /// + /// Considers input as kibibytes + /// + public static ByteSize Kibibytes(this byte input) => + ByteSize.FromKibibytes(input); + + /// + /// Considers input as kibibytes + /// + public static ByteSize Kibibytes(this sbyte input) => + ByteSize.FromKibibytes(input); + + /// + /// Considers input as kibibytes + /// + public static ByteSize Kibibytes(this short input) => + ByteSize.FromKibibytes(input); + + /// + /// Considers input as kibibytes + /// + public static ByteSize Kibibytes(this ushort input) => + ByteSize.FromKibibytes(input); + + /// + /// Considers input as kibibytes + /// + public static ByteSize Kibibytes(this int input) => + ByteSize.FromKibibytes(input); + + /// + /// Considers input as kibibytes + /// + public static ByteSize Kibibytes(this uint input) => + ByteSize.FromKibibytes(input); + + /// + /// Considers input as kibibytes + /// + public static ByteSize Kibibytes(this double input) => + ByteSize.FromKibibytes(input); + + /// + /// Considers input as kibibytes + /// + public static ByteSize Kibibytes(this long input) => + ByteSize.FromKibibytes(input); + /// /// Considers input as megabytes /// @@ -192,6 +240,54 @@ public static ByteSize Megabytes(this double input) => public static ByteSize Megabytes(this long input) => ByteSize.FromMegabytes(input); + /// + /// Considers input as mebibytes + /// + public static ByteSize Mebibytes(this byte input) => + ByteSize.FromMebibytes(input); + + /// + /// Considers input as mebibytes + /// + public static ByteSize Mebibytes(this sbyte input) => + ByteSize.FromMebibytes(input); + + /// + /// Considers input as mebibytes + /// + public static ByteSize Mebibytes(this short input) => + ByteSize.FromMebibytes(input); + + /// + /// Considers input as mebibytes + /// + public static ByteSize Mebibytes(this ushort input) => + ByteSize.FromMebibytes(input); + + /// + /// Considers input as mebibytes + /// + public static ByteSize Mebibytes(this int input) => + ByteSize.FromMebibytes(input); + + /// + /// Considers input as mebibytes + /// + public static ByteSize Mebibytes(this uint input) => + ByteSize.FromMebibytes(input); + + /// + /// Considers input as mebibytes + /// + public static ByteSize Mebibytes(this double input) => + ByteSize.FromMebibytes(input); + + /// + /// Considers input as mebibytes + /// + public static ByteSize Mebibytes(this long input) => + ByteSize.FromMebibytes(input); + /// /// Considers input as gigabytes /// @@ -240,6 +336,54 @@ public static ByteSize Gigabytes(this double input) => public static ByteSize Gigabytes(this long input) => ByteSize.FromGigabytes(input); + /// + /// Considers input as gibibytes + /// + public static ByteSize Gibibytes(this byte input) => + ByteSize.FromGibibytes(input); + + /// + /// Considers input as gibibytes + /// + public static ByteSize Gibibytes(this sbyte input) => + ByteSize.FromGibibytes(input); + + /// + /// Considers input as gibibytes + /// + public static ByteSize Gibibytes(this short input) => + ByteSize.FromGibibytes(input); + + /// + /// Considers input as gibibytes + /// + public static ByteSize Gibibytes(this ushort input) => + ByteSize.FromGibibytes(input); + + /// + /// Considers input as gibibytes + /// + public static ByteSize Gibibytes(this int input) => + ByteSize.FromGibibytes(input); + + /// + /// Considers input as gibibytes + /// + public static ByteSize Gibibytes(this uint input) => + ByteSize.FromGibibytes(input); + + /// + /// Considers input as gibibytes + /// + public static ByteSize Gibibytes(this double input) => + ByteSize.FromGibibytes(input); + + /// + /// Considers input as gibibytes + /// + public static ByteSize Gibibytes(this long input) => + ByteSize.FromGibibytes(input); + /// /// Considers input as terabytes /// @@ -288,6 +432,54 @@ public static ByteSize Terabytes(this double input) => public static ByteSize Terabytes(this long input) => ByteSize.FromTerabytes(input); + /// + /// Considers input as tebibytes + /// + public static ByteSize Tebibytes(this byte input) => + ByteSize.FromTebibytes(input); + + /// + /// Considers input as tebibytes + /// + public static ByteSize Tebibytes(this sbyte input) => + ByteSize.FromTebibytes(input); + + /// + /// Considers input as tebibytes + /// + public static ByteSize Tebibytes(this short input) => + ByteSize.FromTebibytes(input); + + /// + /// Considers input as tebibytes + /// + public static ByteSize Tebibytes(this ushort input) => + ByteSize.FromTebibytes(input); + + /// + /// Considers input as tebibytes + /// + public static ByteSize Tebibytes(this int input) => + ByteSize.FromTebibytes(input); + + /// + /// Considers input as tebibytes + /// + public static ByteSize Tebibytes(this uint input) => + ByteSize.FromTebibytes(input); + + /// + /// Considers input as tebibytes + /// + public static ByteSize Tebibytes(this double input) => + ByteSize.FromTebibytes(input); + + /// + /// Considers input as tebibytes + /// + public static ByteSize Tebibytes(this long input) => + ByteSize.FromTebibytes(input); + /// /// Turns a byte quantity into human readable form, eg 2 GB /// diff --git a/src/Humanizer/Localisation/DataUnit.cs b/src/Humanizer/Localisation/DataUnit.cs index d8e564f6d..f67b549c9 100644 --- a/src/Humanizer/Localisation/DataUnit.cs +++ b/src/Humanizer/Localisation/DataUnit.cs @@ -20,19 +20,39 @@ public enum DataUnit /// Kilobyte, + /// + /// Kibibyte + /// + Kibibyte, + /// /// Megabyte /// Megabyte, + /// + /// Mebibyte + /// + Mebibyte, + /// /// Gigabyte /// Gigabyte, /// - /// Terrabyte + /// Gibibyte + /// + Gibibyte, + + /// + /// Terabyte + /// + Terabyte, + + /// + /// Tebibyte /// - Terabyte + Tebibyte } } diff --git a/src/Humanizer/Properties/Resources.de.resx b/src/Humanizer/Properties/Resources.de.resx index b127c0b49..c5c974f4c 100644 --- a/src/Humanizer/Properties/Resources.de.resx +++ b/src/Humanizer/Properties/Resources.de.resx @@ -381,24 +381,36 @@ Kilobyte + + Kibibyte + kB Megabyte + + Mebibyte + MB Gigabyte + + Gibibyte + GB Terabyte + + Tebibyte + TB diff --git a/src/Humanizer/Properties/Resources.fr.resx b/src/Humanizer/Properties/Resources.fr.resx index 3b53300d5..9c46f1533 100644 --- a/src/Humanizer/Properties/Resources.fr.resx +++ b/src/Humanizer/Properties/Resources.fr.resx @@ -318,24 +318,36 @@ Ko + + Kio + mégaoctet Mo + + Mio + gigaoctet Go + + Gio + téraoctet To + + Tio + ms diff --git a/src/Humanizer/Properties/Resources.resx b/src/Humanizer/Properties/Resources.resx index d1c7050c4..cceecc6af 100644 --- a/src/Humanizer/Properties/Resources.resx +++ b/src/Humanizer/Properties/Resources.resx @@ -690,27 +690,51 @@ kilobyte + + kibibyte + KB + + KiB + megabyte + + mebibyte + MB + + MiB + gigabyte + + gibibyte + GB + + GiB + terabyte + + tebibyte + TB + + TiB + ms From 3326a7edf39cb0643d828bd760e387fe32968a30 Mon Sep 17 00:00:00 2001 From: Collin Alpert Date: Sun, 18 Feb 2024 23:41:56 +0100 Subject: [PATCH 2/4] Fix tests --- .../Bytes/ArithmeticTests.cs | 66 ++++++++++++++++--- .../Bytes/ByteRateTests.cs | 21 +++--- .../Bytes/CreatingTests.cs | 65 +++++++++++++++--- .../Bytes/ToFullWordsTests.cs | 3 +- .../Bytes/ToStringTests.cs | 20 +++++- .../Localisation/de/Bytes/ByteRateTests.cs | 21 +++--- .../de/Bytes/ByteSizeExtensionsTests.cs | 55 +++++++++++++--- .../Localisation/de/Bytes/ToFullWordsTests.cs | 3 +- .../Localisation/de/Bytes/ToStringTests.cs | 20 +++++- .../fr/Bytes/ByteSizeExtensionsTests.cs | 21 +++--- .../Localisation/fr/Bytes/ToFullWordsTests.cs | 3 +- .../Localisation/fr/Bytes/ToStringTests.cs | 4 +- .../is/Bytes/ByteSizeExtensionsTests.cs | 21 +++--- .../Localisation/is/Bytes/ToFullWordsTests.cs | 2 +- .../Localisation/is/Bytes/ToStringTests.cs | 4 +- .../Localisation/lb/Bytes/ByteRateTests.cs | 21 +++--- .../lb/Bytes/ByteSizeExtensionsTests.cs | 21 +++--- .../Localisation/lb/Bytes/ToFullWordsTests.cs | 3 +- .../Localisation/lb/Bytes/ToStringTests.cs | 4 +- ....Approve_Public_Api.DotNet8_0.verified.txt | 36 ++++++++++ 20 files changed, 311 insertions(+), 103 deletions(-) diff --git a/src/Humanizer.Tests.Shared/Bytes/ArithmeticTests.cs b/src/Humanizer.Tests.Shared/Bytes/ArithmeticTests.cs index a3b84063b..f8f9378f6 100644 --- a/src/Humanizer.Tests.Shared/Bytes/ArithmeticTests.cs +++ b/src/Humanizer.Tests.Shared/Bytes/ArithmeticTests.cs @@ -35,9 +35,19 @@ public void AddKilobytes() { var size = ByteSize.FromKilobytes(2).AddKilobytes(2); + Assert.Equal(4 * 1000 * 8, size.Bits); + Assert.Equal(4 * 1000, size.Bytes); + Assert.Equal(4, size.Kilobytes); + } + + [Fact] + public void AddKibibytes() + { + var size = ByteSize.FromKibibytes(2).AddKibibytes(2); + Assert.Equal(4 * 1024 * 8, size.Bits); Assert.Equal(4 * 1024, size.Bytes); - Assert.Equal(4, size.Kilobytes); + Assert.Equal(4, size.Kibibytes); } [Fact] @@ -45,10 +55,21 @@ public void AddMegabytes() { var size = ByteSize.FromMegabytes(2).AddMegabytes(2); + Assert.Equal(4 * 1000 * 1000 * 8, size.Bits); + Assert.Equal(4 * 1000 * 1000, size.Bytes); + Assert.Equal(4 * 1000, size.Kilobytes); + Assert.Equal(4, size.Megabytes); + } + + [Fact] + public void AddMebibytes() + { + var size = ByteSize.FromMebibytes(2).AddMebibytes(2); + Assert.Equal(4 * 1024 * 1024 * 8, size.Bits); Assert.Equal(4 * 1024 * 1024, size.Bytes); - Assert.Equal(4 * 1024, size.Kilobytes); - Assert.Equal(4, size.Megabytes); + Assert.Equal(4 * 1024, size.Kibibytes); + Assert.Equal(4, size.Mebibytes); } [Fact] @@ -56,11 +77,23 @@ public void AddGigabytes() { var size = ByteSize.FromGigabytes(2).AddGigabytes(2); + Assert.Equal(4d * 1000 * 1000 * 1000 * 8, size.Bits); + Assert.Equal(4d * 1000 * 1000 * 1000, size.Bytes); + Assert.Equal(4d * 1000 * 1000, size.Kilobytes); + Assert.Equal(4d * 1000, size.Megabytes); + Assert.Equal(4d, size.Gigabytes); + } + + [Fact] + public void AddGibibytes() + { + var size = ByteSize.FromGibibytes(2).AddGibibytes(2); + Assert.Equal(4d * 1024 * 1024 * 1024 * 8, size.Bits); Assert.Equal(4d * 1024 * 1024 * 1024, size.Bytes); - Assert.Equal(4d * 1024 * 1024, size.Kilobytes); - Assert.Equal(4d * 1024, size.Megabytes); - Assert.Equal(4d, size.Gigabytes); + Assert.Equal(4d * 1024 * 1024, size.Kibibytes); + Assert.Equal(4d * 1024, size.Mebibytes); + Assert.Equal(4d, size.Gibibytes); } [Fact] @@ -68,12 +101,25 @@ public void AddTerabytes() { var size = ByteSize.FromTerabytes(2).AddTerabytes(2); + Assert.Equal(4d * 1000 * 1000 * 1000 * 1000 * 8, size.Bits); + Assert.Equal(4d * 1000 * 1000 * 1000 * 1000, size.Bytes); + Assert.Equal(4d * 1000 * 1000 * 1000, size.Kilobytes); + Assert.Equal(4d * 1000 * 1000, size.Megabytes); + Assert.Equal(4d * 1000, size.Gigabytes); + Assert.Equal(4d, size.Terabytes); + } + + [Fact] + public void AddTebibytes() + { + var size = ByteSize.FromTebibytes(2).AddTebibytes(2); + Assert.Equal(4d * 1024 * 1024 * 1024 * 1024 * 8, size.Bits); Assert.Equal(4d * 1024 * 1024 * 1024 * 1024, size.Bytes); - Assert.Equal(4d * 1024 * 1024 * 1024, size.Kilobytes); - Assert.Equal(4d * 1024 * 1024, size.Megabytes); - Assert.Equal(4d * 1024, size.Gigabytes); - Assert.Equal(4d, size.Terabytes); + Assert.Equal(4d * 1024 * 1024 * 1024, size.Kibibytes); + Assert.Equal(4d * 1024 * 1024, size.Mebibytes); + Assert.Equal(4d * 1024, size.Gibibytes); + Assert.Equal(4d, size.Tebibytes); } [Fact] diff --git a/src/Humanizer.Tests.Shared/Bytes/ByteRateTests.cs b/src/Humanizer.Tests.Shared/Bytes/ByteRateTests.cs index 09f4938e6..93cda71f8 100644 --- a/src/Humanizer.Tests.Shared/Bytes/ByteRateTests.cs +++ b/src/Humanizer.Tests.Shared/Bytes/ByteRateTests.cs @@ -5,11 +5,11 @@ public class ByteRateTests { [Theory] [InlineData(400, 1, "400 B/s")] - [InlineData(4 * 1024, 1, "4 KB/s")] - [InlineData(4 * 1024 * 1024, 1, "4 MB/s")] - [InlineData(4 * 2 * 1024 * 1024, 2, "4 MB/s")] - [InlineData(4 * 1024, 0.1, "40 KB/s")] - [InlineData(15 * 60 * 1024 * 1024, 60, "15 MB/s")] + [InlineData(4 * 1000, 1, "4 KB/s")] + [InlineData(4 * 1000 * 1000, 1, "4 MB/s")] + [InlineData(4 * 2 * 1000 * 1000, 2, "4 MB/s")] + [InlineData(4 * 1000, 0.1, "40 KB/s")] + [InlineData(15 * 60 * 1000 * 1000, 60, "15 MB/s")] public void HumanizesRates(long inputBytes, double perSeconds, string expectedValue) { var size = new ByteSize(inputBytes); @@ -27,9 +27,9 @@ public void HumanizesRates(long inputBytes, double perSeconds, string expectedVa [InlineData(10, 1, TimeUnit.Second, "10 MB/s")] [InlineData(10, 60, TimeUnit.Minute, "10 MB/min")] [InlineData(10, 60 * 60, TimeUnit.Hour, "10 MB/h")] - [InlineData(1, 10 * 1, TimeUnit.Second, "102.4 KB/s")] - [InlineData(1, 10 * 60, TimeUnit.Minute, "102.4 KB/min")] - [InlineData(1, 10 * 60 * 60, TimeUnit.Hour, "102.4 KB/h")] + [InlineData(1, 10 * 1, TimeUnit.Second, "100 KB/s")] + [InlineData(1, 10 * 60, TimeUnit.Minute, "100 KB/min")] + [InlineData(1, 10 * 60 * 60, TimeUnit.Hour, "100 KB/h")] public void TimeUnitTests(long megabytes, double measurementIntervalSeconds, TimeUnit displayInterval, string expectedValue) { var size = ByteSize.FromMegabytes(megabytes); @@ -42,8 +42,9 @@ public void TimeUnitTests(long megabytes, double measurementIntervalSeconds, Tim } [Theory] - [InlineData(19854651984, 1, TimeUnit.Second, null, "18.49 GB/s")] - [InlineData(19854651984, 1, TimeUnit.Second, "#.##", "18.49 GB/s")] + [InlineData(19854651984, 1, TimeUnit.Second, null, "19.85 GB/s")] + [InlineData(19854651984, 1, TimeUnit.Second, "#.##", "19.85 GB/s")] + [InlineData(19854651984, 1, TimeUnit.Second, "#.## GiB", "18.49 GiB/s")] public void FormattedTimeUnitTests(long bytes, int measurementIntervalSeconds, TimeUnit displayInterval, string format, string expectedValue) { var size = ByteSize.FromBytes(bytes); diff --git a/src/Humanizer.Tests.Shared/Bytes/CreatingTests.cs b/src/Humanizer.Tests.Shared/Bytes/CreatingTests.cs index 191259253..dd19aef1e 100644 --- a/src/Humanizer.Tests.Shared/Bytes/CreatingTests.cs +++ b/src/Humanizer.Tests.Shared/Bytes/CreatingTests.cs @@ -26,15 +26,28 @@ public class CreatingTests { [Fact] public void Constructor() + { + var result = new ByteSize(1000000000000); + + Assert.Equal(8000000000000, result.Bits); + Assert.Equal(1000000000000, result.Bytes); + Assert.Equal(1000000000, result.Kilobytes); + Assert.Equal(1000000, result.Megabytes); + Assert.Equal(1000, result.Gigabytes); + Assert.Equal(1, result.Terabytes); + } + + [Fact] + public void Constructor_Binary() { var result = new ByteSize(1099511627776); Assert.Equal(8.796093022208e12, result.Bits); Assert.Equal(1099511627776, result.Bytes); - Assert.Equal(1073741824, result.Kilobytes); - Assert.Equal(1048576, result.Megabytes); - Assert.Equal(1024, result.Gigabytes); - Assert.Equal(1, result.Terabytes); + Assert.Equal(1073741824, result.Kibibytes); + Assert.Equal(1048576, result.Mebibytes); + Assert.Equal(1024, result.Gibibytes); + Assert.Equal(1, result.Tebibytes); } [Fact] @@ -60,35 +73,71 @@ public void FromKilobytes() { var result = ByteSize.FromKilobytes(1.5); - Assert.Equal(1536, result.Bytes); + Assert.Equal(1500, result.Bytes); Assert.Equal(1.5, result.Kilobytes); } + [Fact] + public void FromKibibytes() + { + var result = ByteSize.FromKibibytes(1.5); + + Assert.Equal(1536, result.Bytes); + Assert.Equal(1.5, result.Kibibytes); + } + [Fact] public void FromMegabytes() { var result = ByteSize.FromMegabytes(1.5); - Assert.Equal(1572864, result.Bytes); + Assert.Equal(1500000, result.Bytes); Assert.Equal(1.5, result.Megabytes); } + [Fact] + public void FromMebibytes() + { + var result = ByteSize.FromMebibytes(1.5); + + Assert.Equal(1572864, result.Bytes); + Assert.Equal(1.5, result.Mebibytes); + } + [Fact] public void FromGigabytes() { var result = ByteSize.FromGigabytes(1.5); - Assert.Equal(1610612736, result.Bytes); + Assert.Equal(1500000000, result.Bytes); Assert.Equal(1.5, result.Gigabytes); } + [Fact] + public void FromGibibytes() + { + var result = ByteSize.FromGibibytes(1.5); + + Assert.Equal(1610612736, result.Bytes); + Assert.Equal(1.5, result.Gibibytes); + } + [Fact] public void FromTerabytes() { var result = ByteSize.FromTerabytes(1.5); - Assert.Equal(1649267441664, result.Bytes); + Assert.Equal(1500000000000, result.Bytes); Assert.Equal(1.5, result.Terabytes); } + + [Fact] + public void FromTebibytes() + { + var result = ByteSize.FromTebibytes(1.5); + + Assert.Equal(1649267441664, result.Bytes); + Assert.Equal(1.5, result.Tebibytes); + } } } diff --git a/src/Humanizer.Tests.Shared/Bytes/ToFullWordsTests.cs b/src/Humanizer.Tests.Shared/Bytes/ToFullWordsTests.cs index a5ffb3252..dd329cace 100644 --- a/src/Humanizer.Tests.Shared/Bytes/ToFullWordsTests.cs +++ b/src/Humanizer.Tests.Shared/Bytes/ToFullWordsTests.cs @@ -75,7 +75,8 @@ public void ReturnsPluralTerabytes() => [Theory] [InlineData(229376, "B", "229376 bytes")] - [InlineData(229376, "# KB", "224 kilobytes")] + [InlineData(229376, "# KB", "229 kilobytes")] + [InlineData(229376, "# KiB", "224 kibibytes")] public void ToFullWordsFormatted(double input, string format, string expectedValue) => Assert.Equal(expectedValue, ByteSize.FromBytes(input).ToFullWords(format)); } diff --git a/src/Humanizer.Tests.Shared/Bytes/ToStringTests.cs b/src/Humanizer.Tests.Shared/Bytes/ToStringTests.cs index 748fede4b..80f22e46b 100644 --- a/src/Humanizer.Tests.Shared/Bytes/ToStringTests.cs +++ b/src/Humanizer.Tests.Shared/Bytes/ToStringTests.cs @@ -52,29 +52,45 @@ public void ReturnsBytes() => public void ReturnsKilobytes() => Assert.Equal("10 KB", ByteSize.FromKilobytes(10).ToString("##.#### KB")); + [Fact] + public void ReturnsKibibytes() => + Assert.Equal("10 KiB", ByteSize.FromKibibytes(10).ToString("##.#### KiB")); + [Fact] public void ReturnsMegabytes() => Assert.Equal("10 MB", ByteSize.FromMegabytes(10).ToString("##.#### MB")); + [Fact] + public void ReturnsMebibytes() => + Assert.Equal("10 MiB", ByteSize.FromMebibytes(10).ToString("##.#### MiB")); + [Fact] public void ReturnsGigabytes() => Assert.Equal("10 GB", ByteSize.FromGigabytes(10).ToString("##.#### GB")); + [Fact] + public void ReturnsGibibytes() => + Assert.Equal("10 GiB", ByteSize.FromGibibytes(10).ToString("##.#### GiB")); + [Fact] public void ReturnsTerabytes() => Assert.Equal("10 TB", ByteSize.FromTerabytes(10).ToString("##.#### TB")); + [Fact] + public void ReturnsTebibytes() => + Assert.Equal("10 TiB", ByteSize.FromTebibytes(10).ToString("##.#### TiB")); + [Fact] public void ReturnsSelectedFormat() => Assert.Equal("10.0 TB", ByteSize.FromTerabytes(10).ToString("0.0 TB")); [Fact] public void ReturnsLargestMetricPrefixLargerThanZero() => - Assert.Equal("512 KB", ByteSize.FromMegabytes(.5).ToString("#.#")); + Assert.Equal("500 KB", ByteSize.FromMegabytes(.5).ToString("#.#")); [Fact] public void ReturnsLargestMetricPrefixLargerThanZeroForNegativeValues() => - Assert.Equal("-512 KB", ByteSize.FromMegabytes(-.5).ToString("#.#")); + Assert.Equal("-500 KB", ByteSize.FromMegabytes(-.5).ToString("#.#")); [Fact] public void ReturnsBytesViaGeneralFormat() => diff --git a/src/Humanizer.Tests.Shared/Localisation/de/Bytes/ByteRateTests.cs b/src/Humanizer.Tests.Shared/Localisation/de/Bytes/ByteRateTests.cs index 372798986..d5c30f40c 100644 --- a/src/Humanizer.Tests.Shared/Localisation/de/Bytes/ByteRateTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/de/Bytes/ByteRateTests.cs @@ -5,11 +5,11 @@ public class ByteRateTests { [Theory] [InlineData(400, 1, "400 B/s")] - [InlineData(4 * 1024, 1, "4 kB/s")] - [InlineData(4 * 1024 * 1024, 1, "4 MB/s")] - [InlineData(4 * 2 * 1024 * 1024, 2, "4 MB/s")] - [InlineData(4 * 1024, 0.1, "40 kB/s")] - [InlineData(15 * 60 * 1024 * 1024, 60, "15 MB/s")] + [InlineData(4 * 1000, 1, "4 kB/s")] + [InlineData(4 * 1000 * 1000, 1, "4 MB/s")] + [InlineData(4 * 2 * 1000 * 1000, 2, "4 MB/s")] + [InlineData(4 * 1000, 0.1, "40 kB/s")] + [InlineData(15 * 60 * 1000 * 1000, 60, "15 MB/s")] public void HumanizesRates(long inputBytes, double perSeconds, string expectedValue) { var size = new ByteSize(inputBytes); @@ -27,9 +27,9 @@ public void HumanizesRates(long inputBytes, double perSeconds, string expectedVa [InlineData(10, 1, TimeUnit.Second, "10 MB/s")] [InlineData(10, 60, TimeUnit.Minute, "10 MB/min")] [InlineData(10, 60 * 60, TimeUnit.Hour, "10 MB/h")] - [InlineData(1, 10 * 1, TimeUnit.Second, "102,4 kB/s")] - [InlineData(1, 10 * 60, TimeUnit.Minute, "102,4 kB/min")] - [InlineData(1, 10 * 60 * 60, TimeUnit.Hour, "102,4 kB/h")] + [InlineData(1, 10 * 1, TimeUnit.Second, "100 kB/s")] + [InlineData(1, 10 * 60, TimeUnit.Minute, "100 kB/min")] + [InlineData(1, 10 * 60 * 60, TimeUnit.Hour, "100 kB/h")] public void TimeUnitTests(long megabytes, double measurementIntervalSeconds, TimeUnit displayInterval, string expectedValue) { var size = ByteSize.FromMegabytes(megabytes); @@ -42,8 +42,9 @@ public void TimeUnitTests(long megabytes, double measurementIntervalSeconds, Tim } [Theory] - [InlineData(19854651984, 1, TimeUnit.Second, null, "18,49 GB/s")] - [InlineData(19854651984, 1, TimeUnit.Second, "#.##", "18,49 GB/s")] + [InlineData(19854651984, 1, TimeUnit.Second, null, "19,85 GB/s")] + [InlineData(19854651984, 1, TimeUnit.Second, "#.##", "19,85 GB/s")] + [InlineData(19854651984, 1, TimeUnit.Second, "#.## GiB", "18,49 GiB/s")] public void FormattedTimeUnitTests(long bytes, int measurementIntervalSeconds, TimeUnit displayInterval, string format, string expectedValue) { var size = ByteSize.FromBytes(bytes); diff --git a/src/Humanizer.Tests.Shared/Localisation/de/Bytes/ByteSizeExtensionsTests.cs b/src/Humanizer.Tests.Shared/Localisation/de/Bytes/ByteSizeExtensionsTests.cs index 47db0a373..004f18478 100644 --- a/src/Humanizer.Tests.Shared/Localisation/de/Bytes/ByteSizeExtensionsTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/de/Bytes/ByteSizeExtensionsTests.cs @@ -5,49 +5,83 @@ public class ByteSizeExtensionsTests { [Theory] [InlineData(2, null, "2 TB")] - [InlineData(2, "GB", "2048 GB")] + [InlineData(2, "GB", "2000 GB")] [InlineData(2.123, "#.#", "2,1 TB")] public void HumanizesTerabytes(double input, string format, string expectedValue) => Assert.Equal(expectedValue, input.Terabytes().Humanize(format)); + [Theory] + [InlineData(2, "GiB", "2048 GiB")] + [InlineData(2.123, "#.# TiB", "2,1 TiB")] + public void HumanizesTebibytes(double input, string format, string expectedValue) => + Assert.Equal(expectedValue, input.Tebibytes().Humanize(format)); + [Theory] [InlineData(0, null, "0 bit")] [InlineData(0, "GB", "0 GB")] [InlineData(2, null, "2 GB")] - [InlineData(2, "MB", "2048 MB")] + [InlineData(2, "MB", "2000 MB")] [InlineData(2.123, "#.##", "2,12 GB")] public void HumanizesGigabytes(double input, string format, string expectedValue) => Assert.Equal(expectedValue, input.Gigabytes().Humanize(format)); + [Theory] + [InlineData(0, null, "0 bit")] + [InlineData(0, "GiB", "0 GiB")] + [InlineData(2, "MiB", "2048 MiB")] + [InlineData(2.123, "#.## GiB", "2,28 GiB")] + public void HumanizesGibibytes(double input, string format, string expectedValue) => + Assert.Equal(expectedValue, input.Gibibytes().Humanize(format)); + [Theory] [InlineData(0, null, "0 bit")] [InlineData(0, "MB", "0 MB")] [InlineData(2, null, "2 MB")] - [InlineData(2, "KB", "2048 kB")] + [InlineData(2, "KB", "2000 kB")] [InlineData(2.123, "#", "2 MB")] public void HumanizesMegabytes(double input, string format, string expectedValue) => Assert.Equal(expectedValue, input.Megabytes().Humanize(format)); + [Theory] + [InlineData(0, null, "0 bit")] + [InlineData(0, "MiB", "0 MiB")] + [InlineData(2, "KiB", "2048 KiB")] + [InlineData(2.123, "# MiB", "2 MiB")] + public void HumanizesMebibytes(double input, string format, string expectedValue) => + Assert.Equal(expectedValue, input.Mebibytes().Humanize(format)); + [Theory] [InlineData(0, null, "0 bit")] [InlineData(0, "KB", "0 kB")] [InlineData(2, null, "2 kB")] - [InlineData(2, "B", "2048 B")] + [InlineData(2, "B", "2000 B")] [InlineData(2.123, "#.####", "2,123 kB")] public void HumanizesKilobytes(double input, string format, string expectedValue) => Assert.Equal(expectedValue, input.Kilobytes().Humanize(format)); + [Theory] + [InlineData(0, null, "0 bit")] + [InlineData(0, "KiB", "0 KiB")] + [InlineData(2, "B", "2048 B")] + [InlineData(2.123, "#.#### KiB", "2,174 KiB")] + public void HumanizesKibibytes(double input, string format, string expectedValue) => + Assert.Equal(expectedValue, input.Kibibytes().Humanize(format)); + [Theory] [InlineData(0, null, "0 bit")] [InlineData(0, "#.##", "0 bit")] [InlineData(0, "#.## B", "0 B")] [InlineData(0, "B", "0 B")] [InlineData(2, null, "2 B")] - [InlineData(2000, "KB", "1,95 kB")] - [InlineData(2123, "#.##", "2,07 kB")] - [InlineData(10000000, "KB", "9765,63 kB")] - [InlineData(10000000, "#,##0 KB", "9.766 kB")] - [InlineData(10000000, "#,##0.# KB", "9.765,6 kB")] + [InlineData(1950, "KB", "1,95 kB")] + [InlineData(2000, "KiB", "1,95 KiB")] + [InlineData(2123, "#.##", "2,12 kB")] + [InlineData(9765630, "KB", "9765,63 kB")] + [InlineData(9765630, "#,##0 KB", "9.766 kB")] + [InlineData(9765630, "#,##0.# KB", "9.765,6 kB")] + [InlineData(10000000, "KiB", "9765,63 KiB")] + [InlineData(10000000, "#,##0 KiB", "9.766 KiB")] + [InlineData(10000000, "#,##0.# KiB", "9.765,6 KiB")] public void HumanizesBytes(double input, string format, string expectedValue) => Assert.Equal(expectedValue, input.Bytes().Humanize(format)); @@ -56,7 +90,8 @@ public void HumanizesBytes(double input, string format, string expectedValue) => [InlineData(0, "b", "0 bit")] [InlineData(2, null, "2 bit")] [InlineData(12, "B", "1,5 B")] - [InlineData(10000, "#.# KB", "1,2 kB")] + [InlineData(10000, "#.# KB", "1,3 kB")] + [InlineData(10000, "#.# KiB", "1,2 KiB")] public void HumanizesBits(long input, string format, string expectedValue) => Assert.Equal(expectedValue, input.Bits().Humanize(format)); } diff --git a/src/Humanizer.Tests.Shared/Localisation/de/Bytes/ToFullWordsTests.cs b/src/Humanizer.Tests.Shared/Localisation/de/Bytes/ToFullWordsTests.cs index 82dc74736..604d80936 100644 --- a/src/Humanizer.Tests.Shared/Localisation/de/Bytes/ToFullWordsTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/de/Bytes/ToFullWordsTests.cs @@ -53,7 +53,8 @@ public void ReturnsPluralTerabytes() => [Theory] [InlineData(229376, "B", "229376 Byte")] - [InlineData(229376, "# KB", "224 Kilobyte")] + [InlineData(229376, "# KB", "229 Kilobyte")] + [InlineData(229376, "# KiB", "224 Kibibyte")] public void ToFullWordsFormatted(double input, string format, string expectedValue) => Assert.Equal(expectedValue, ByteSize.FromBytes(input).ToFullWords(format)); } diff --git a/src/Humanizer.Tests.Shared/Localisation/de/Bytes/ToStringTests.cs b/src/Humanizer.Tests.Shared/Localisation/de/Bytes/ToStringTests.cs index 95cefdd8f..2a9e743db 100644 --- a/src/Humanizer.Tests.Shared/Localisation/de/Bytes/ToStringTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/de/Bytes/ToStringTests.cs @@ -27,29 +27,45 @@ public void ReturnsBytes() => public void ReturnsKilobytes() => Assert.Equal("10 kB", ByteSize.FromKilobytes(10).ToString("##.#### KB")); + [Fact] + public void ReturnsKibibytes() => + Assert.Equal("10 KiB", ByteSize.FromKibibytes(10).ToString("##.#### KiB")); + [Fact] public void ReturnsMegabytes() => Assert.Equal("10 MB", ByteSize.FromMegabytes(10).ToString("##.#### MB")); + [Fact] + public void ReturnsMebibytes() => + Assert.Equal("10 MiB", ByteSize.FromMebibytes(10).ToString("##.#### MiB")); + [Fact] public void ReturnsGigabytes() => Assert.Equal("10 GB", ByteSize.FromGigabytes(10).ToString("##.#### GB")); + [Fact] + public void ReturnsGibibytes() => + Assert.Equal("10 GiB", ByteSize.FromGibibytes(10).ToString("##.#### GiB")); + [Fact] public void ReturnsTerabytes() => Assert.Equal("10 TB", ByteSize.FromTerabytes(10).ToString("##.#### TB")); + [Fact] + public void ReturnsTebibytes() => + Assert.Equal("10 TiB", ByteSize.FromTebibytes(10).ToString("##.#### TiB")); + [Fact] public void ReturnsSelectedFormat() => Assert.Equal("10,0 TB", ByteSize.FromTerabytes(10).ToString("0.0 TB")); [Fact] public void ReturnsLargestMetricPrefixLargerThanZero() => - Assert.Equal("512 kB", ByteSize.FromMegabytes(.5).ToString("#.#")); + Assert.Equal("500 kB", ByteSize.FromMegabytes(.5).ToString("#.#")); [Fact] public void ReturnsLargestMetricPrefixLargerThanZeroForNegativeValues() => - Assert.Equal("-512 kB", ByteSize.FromMegabytes(-.5).ToString("#.#")); + Assert.Equal("-500 kB", ByteSize.FromMegabytes(-.5).ToString("#.#")); [Fact] public void ReturnsBytesViaGeneralFormat() => diff --git a/src/Humanizer.Tests.Shared/Localisation/fr/Bytes/ByteSizeExtensionsTests.cs b/src/Humanizer.Tests.Shared/Localisation/fr/Bytes/ByteSizeExtensionsTests.cs index 900fd87e1..8f2d90f68 100644 --- a/src/Humanizer.Tests.Shared/Localisation/fr/Bytes/ByteSizeExtensionsTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/fr/Bytes/ByteSizeExtensionsTests.cs @@ -5,7 +5,7 @@ public class ByteSizeExtensionsTests { [Theory] [InlineData(2, null, "2 To")] - [InlineData(2, "GB", "2048 Go")] + [InlineData(2, "GB", "2000 Go")] [InlineData(2.123, "#.#", "2,1 To")] public void HumanizesTerabytes(double input, string format, string expectedValue) => Assert.Equal(expectedValue, input.Terabytes().Humanize(format)); @@ -14,7 +14,7 @@ public void HumanizesTerabytes(double input, string format, string expectedValue [InlineData(0, null, "0 b")] [InlineData(0, "GB", "0 Go")] [InlineData(2, null, "2 Go")] - [InlineData(2, "MB", "2048 Mo")] + [InlineData(2, "MB", "2000 Mo")] [InlineData(2.123, "#.##", "2,12 Go")] public void HumanizesGigabytes(double input, string format, string expectedValue) => Assert.Equal(expectedValue, input.Gigabytes().Humanize(format)); @@ -23,7 +23,7 @@ public void HumanizesGigabytes(double input, string format, string expectedValue [InlineData(0, null, "0 b")] [InlineData(0, "MB", "0 Mo")] [InlineData(2, null, "2 Mo")] - [InlineData(2, "KB", "2048 Ko")] + [InlineData(2, "KB", "2000 Ko")] [InlineData(2.123, "#", "2 Mo")] public void HumanizesMegabytes(double input, string format, string expectedValue) => Assert.Equal(expectedValue, input.Megabytes().Humanize(format)); @@ -32,7 +32,7 @@ public void HumanizesMegabytes(double input, string format, string expectedValue [InlineData(0, null, "0 b")] [InlineData(0, "KB", "0 Ko")] [InlineData(2, null, "2 Ko")] - [InlineData(2, "B", "2048 o")] + [InlineData(2, "B", "2000 o")] [InlineData(2.123, "#.####", "2,123 Ko")] public void HumanizesKilobytes(double input, string format, string expectedValue) => Assert.Equal(expectedValue, input.Kilobytes().Humanize(format)); @@ -43,11 +43,11 @@ public void HumanizesKilobytes(double input, string format, string expectedValue [InlineData(0, "#.## B", "0 o")] [InlineData(0, "B", "0 o")] [InlineData(2, null, "2 o")] - [InlineData(2000, "KB", "1,95 Ko")] - [InlineData(2123, "#.##", "2,07 Ko")] - [InlineData(10000000, "KB", "9765,63 Ko")] - [InlineData(10000000, "#,##0 KB", "9 766 Ko")] - [InlineData(10000000, "#,##0.# KB", "9 765,6 Ko")] + [InlineData(1950, "KB", "1,95 Ko")] + [InlineData(2123, "#.##", "2,12 Ko")] + [InlineData(9765630, "KB", "9765,63 Ko")] + [InlineData(9765630, "#,##0 KB", "9 766 Ko")] + [InlineData(9765630, "#,##0.# KB", "9 765,6 Ko")] public void HumanizesBytes(double input, string format, string expectedValue) => Assert.Equal(expectedValue, input.Bytes().Humanize(format)); @@ -56,7 +56,8 @@ public void HumanizesBytes(double input, string format, string expectedValue) => [InlineData(0, "b", "0 b")] [InlineData(2, null, "2 b")] [InlineData(12, "B", "1,5 o")] - [InlineData(10000, "#.# KB", "1,2 Ko")] + [InlineData(10000, "#.# KB", "1,3 Ko")] + [InlineData(10000, "#.# KiB", "1,2 Kio")] public void HumanizesBits(long input, string format, string expectedValue) => Assert.Equal(expectedValue, input.Bits().Humanize(format)); } diff --git a/src/Humanizer.Tests.Shared/Localisation/fr/Bytes/ToFullWordsTests.cs b/src/Humanizer.Tests.Shared/Localisation/fr/Bytes/ToFullWordsTests.cs index 6842b133d..a79cdd4fe 100644 --- a/src/Humanizer.Tests.Shared/Localisation/fr/Bytes/ToFullWordsTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/fr/Bytes/ToFullWordsTests.cs @@ -53,7 +53,8 @@ public void ReturnsPluralTerabytes() => [Theory] [InlineData(229376, "B", "229376 octets")] - [InlineData(229376, "# KB", "224 kilooctets")] + [InlineData(229376, "# KB", "229 kilooctets")] + [InlineData(229376, "# KiB", "224 kibibytes")] public void ToFullWordsFormatted(double input, string format, string expectedValue) => Assert.Equal(expectedValue, ByteSize.FromBytes(input).ToFullWords(format)); } diff --git a/src/Humanizer.Tests.Shared/Localisation/fr/Bytes/ToStringTests.cs b/src/Humanizer.Tests.Shared/Localisation/fr/Bytes/ToStringTests.cs index 9ba85307f..eb188b496 100644 --- a/src/Humanizer.Tests.Shared/Localisation/fr/Bytes/ToStringTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/fr/Bytes/ToStringTests.cs @@ -45,11 +45,11 @@ public void ReturnsSelectedFormat() => [Fact] public void ReturnsLargestMetricPrefixLargerThanZero() => - Assert.Equal("512 Ko", ByteSize.FromMegabytes(.5).ToString("#.#")); + Assert.Equal("500 Ko", ByteSize.FromMegabytes(.5).ToString("#.#")); [Fact] public void ReturnsLargestMetricPrefixLargerThanZeroForNegativeValues() => - Assert.Equal("-512 Ko", ByteSize.FromMegabytes(-.5).ToString("#.#")); + Assert.Equal("-500 Ko", ByteSize.FromMegabytes(-.5).ToString("#.#")); [Fact] public void ReturnsBytesViaGeneralFormat() => diff --git a/src/Humanizer.Tests.Shared/Localisation/is/Bytes/ByteSizeExtensionsTests.cs b/src/Humanizer.Tests.Shared/Localisation/is/Bytes/ByteSizeExtensionsTests.cs index 753bedac7..708d2191f 100644 --- a/src/Humanizer.Tests.Shared/Localisation/is/Bytes/ByteSizeExtensionsTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/is/Bytes/ByteSizeExtensionsTests.cs @@ -5,7 +5,7 @@ public class ByteSizeExtensionsTests { [Theory] [InlineData(2, null, "2 TB")] - [InlineData(2, "GB", "2048 GB")] + [InlineData(2, "GB", "2000 GB")] [InlineData(2.123, "#.#", "2,1 TB")] public void HumanizesTerabytes(double input, string format, string expectedValue) => Assert.Equal(expectedValue, input.Terabytes().Humanize(format)); @@ -14,7 +14,7 @@ public void HumanizesTerabytes(double input, string format, string expectedValue [InlineData(0, null, "0 b")] [InlineData(0, "GB", "0 GB")] [InlineData(2, null, "2 GB")] - [InlineData(2, "MB", "2048 MB")] + [InlineData(2, "MB", "2000 MB")] [InlineData(2.123, "#.##", "2,12 GB")] public void HumanizesGigabytes(double input, string format, string expectedValue) => Assert.Equal(expectedValue, input.Gigabytes().Humanize(format)); @@ -23,7 +23,7 @@ public void HumanizesGigabytes(double input, string format, string expectedValue [InlineData(0, null, "0 b")] [InlineData(0, "MB", "0 MB")] [InlineData(2, null, "2 MB")] - [InlineData(2, "KB", "2048 kB")] + [InlineData(2, "KB", "2000 kB")] [InlineData(2.123, "#", "2 MB")] public void HumanizesMegabytes(double input, string format, string expectedValue) => Assert.Equal(expectedValue, input.Megabytes().Humanize(format)); @@ -32,7 +32,7 @@ public void HumanizesMegabytes(double input, string format, string expectedValue [InlineData(0, null, "0 b")] [InlineData(0, "KB", "0 kB")] [InlineData(2, null, "2 kB")] - [InlineData(2, "B", "2048 B")] + [InlineData(2, "B", "2000 B")] [InlineData(2.123, "#.####", "2,123 kB")] public void HumanizesKilobytes(double input, string format, string expectedValue) => Assert.Equal(expectedValue, input.Kilobytes().Humanize(format)); @@ -43,11 +43,11 @@ public void HumanizesKilobytes(double input, string format, string expectedValue [InlineData(0, "#.## B", "0 B")] [InlineData(0, "B", "0 B")] [InlineData(2, null, "2 B")] - [InlineData(2000, "KB", "1,95 kB")] - [InlineData(2123, "#.##", "2,07 kB")] - [InlineData(10000000, "KB", "9765,63 kB")] - [InlineData(10000000, "#,##0 KB", "9.766 kB")] - [InlineData(10000000, "#,##0.# KB", "9.765,6 kB")] + [InlineData(1950, "KB", "1,95 kB")] + [InlineData(2123, "#.##", "2,12 kB")] + [InlineData(9765630, "KB", "9765,63 kB")] + [InlineData(9765630, "#,##0 KB", "9.766 kB")] + [InlineData(9765630, "#,##0.# KB", "9.765,6 kB")] public void HumanizesBytes(double input, string format, string expectedValue) => Assert.Equal(expectedValue, input.Bytes().Humanize(format)); @@ -56,7 +56,8 @@ public void HumanizesBytes(double input, string format, string expectedValue) => [InlineData(0, "b", "0 b")] [InlineData(2, null, "2 b")] [InlineData(12, "B", "1,5 B")] - [InlineData(10000, "#.# KB", "1,2 kB")] + [InlineData(10000, "#.# KB", "1,3 kB")] + [InlineData(10000, "#.# KiB", "1,2 KiB")] public void HumanizesBits(long input, string format, string expectedValue) => Assert.Equal(expectedValue, input.Bits().Humanize(format)); } diff --git a/src/Humanizer.Tests.Shared/Localisation/is/Bytes/ToFullWordsTests.cs b/src/Humanizer.Tests.Shared/Localisation/is/Bytes/ToFullWordsTests.cs index 42dc647eb..707916ccc 100644 --- a/src/Humanizer.Tests.Shared/Localisation/is/Bytes/ToFullWordsTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/is/Bytes/ToFullWordsTests.cs @@ -53,7 +53,7 @@ public void ReturnsPluralTerabytes() => [Theory] [InlineData(229376, "B", "229376 bæti")] - [InlineData(229376, "# KB", "224 kílóbæti")] + [InlineData(229376, "# KB", "229 kílóbæti")] public void ToFullWordsFormatted(double input, string format, string expectedValue) => Assert.Equal(expectedValue, ByteSize.FromBytes(input).ToFullWords(format)); } diff --git a/src/Humanizer.Tests.Shared/Localisation/is/Bytes/ToStringTests.cs b/src/Humanizer.Tests.Shared/Localisation/is/Bytes/ToStringTests.cs index 1510db7c9..f022980ae 100644 --- a/src/Humanizer.Tests.Shared/Localisation/is/Bytes/ToStringTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/is/Bytes/ToStringTests.cs @@ -45,11 +45,11 @@ public void ReturnsSelectedFormat() => [Fact] public void ReturnsLargestMetricPrefixLargerThanZero() => - Assert.Equal("512 kB", ByteSize.FromMegabytes(.5).ToString("#.#")); + Assert.Equal("500 kB", ByteSize.FromMegabytes(.5).ToString("#.#")); [Fact] public void ReturnsLargestMetricPrefixLargerThanZeroForNegativeValues() => - Assert.Equal("-512 kB", ByteSize.FromMegabytes(-.5).ToString("#.#")); + Assert.Equal("-500 kB", ByteSize.FromMegabytes(-.5).ToString("#.#")); [Fact] public void ReturnsBytesViaGeneralFormat() => diff --git a/src/Humanizer.Tests.Shared/Localisation/lb/Bytes/ByteRateTests.cs b/src/Humanizer.Tests.Shared/Localisation/lb/Bytes/ByteRateTests.cs index 01b608958..981f59ceb 100644 --- a/src/Humanizer.Tests.Shared/Localisation/lb/Bytes/ByteRateTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/lb/Bytes/ByteRateTests.cs @@ -5,11 +5,11 @@ public class ByteRateTests { [Theory] [InlineData(400, 1, "400 B/s")] - [InlineData(4 * 1024, 1, "4 KB/s")] - [InlineData(4 * 1024 * 1024, 1, "4 MB/s")] - [InlineData(4 * 2 * 1024 * 1024, 2, "4 MB/s")] - [InlineData(4 * 1024, 0.1, "40 KB/s")] - [InlineData(15 * 60 * 1024 * 1024, 60, "15 MB/s")] + [InlineData(4 * 1000, 1, "4 KB/s")] + [InlineData(4 * 1000 * 1000, 1, "4 MB/s")] + [InlineData(4 * 2 * 1000 * 1000, 2, "4 MB/s")] + [InlineData(4 * 1000, 0.1, "40 KB/s")] + [InlineData(15 * 60 * 1000 * 1000, 60, "15 MB/s")] public void HumanizesRates(long inputBytes, double perSeconds, string expectedValue) { var size = new ByteSize(inputBytes); @@ -27,9 +27,9 @@ public void HumanizesRates(long inputBytes, double perSeconds, string expectedVa [InlineData(10, 1, TimeUnit.Second, "10 MB/s")] [InlineData(10, 60, TimeUnit.Minute, "10 MB/min")] [InlineData(10, 60 * 60, TimeUnit.Hour, "10 MB/h")] - [InlineData(1, 10 * 1, TimeUnit.Second, "102,4 KB/s")] - [InlineData(1, 10 * 60, TimeUnit.Minute, "102,4 KB/min")] - [InlineData(1, 10 * 60 * 60, TimeUnit.Hour, "102,4 KB/h")] + [InlineData(1, 10 * 1, TimeUnit.Second, "100 KB/s")] + [InlineData(1, 10 * 60, TimeUnit.Minute, "100 KB/min")] + [InlineData(1, 10 * 60 * 60, TimeUnit.Hour, "100 KB/h")] public void TimeUnitTests(long megabytes, double measurementIntervalSeconds, TimeUnit displayInterval, string expectedValue) { var size = ByteSize.FromMegabytes(megabytes); @@ -42,8 +42,9 @@ public void TimeUnitTests(long megabytes, double measurementIntervalSeconds, Tim } [Theory] - [InlineData(19854651984, 1, TimeUnit.Second, null, "18,49 GB/s")] - [InlineData(19854651984, 1, TimeUnit.Second, "#.##", "18,49 GB/s")] + [InlineData(19854651984, 1, TimeUnit.Second, null, "19,85 GB/s")] + [InlineData(19854651984, 1, TimeUnit.Second, "#.##", "19,85 GB/s")] + [InlineData(19854651984, 1, TimeUnit.Second, "#.## GiB", "18,49 GiB/s")] public void FormattedTimeUnitTests(long bytes, int measurementIntervalSeconds, TimeUnit displayInterval, string format, string expectedValue) { var size = ByteSize.FromBytes(bytes); diff --git a/src/Humanizer.Tests.Shared/Localisation/lb/Bytes/ByteSizeExtensionsTests.cs b/src/Humanizer.Tests.Shared/Localisation/lb/Bytes/ByteSizeExtensionsTests.cs index 79e637abd..fb23b3257 100644 --- a/src/Humanizer.Tests.Shared/Localisation/lb/Bytes/ByteSizeExtensionsTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/lb/Bytes/ByteSizeExtensionsTests.cs @@ -5,7 +5,7 @@ public class ByteSizeExtensionsTests { [Theory] [InlineData(2, null, "2 TB")] - [InlineData(2, "GB", "2048 GB")] + [InlineData(2, "GB", "2000 GB")] [InlineData(2.123, "#.#", "2,1 TB")] public void HumanizesTerabytes(double input, string format, string expectedValue) => Assert.Equal(expectedValue, input.Terabytes().Humanize(format)); @@ -14,7 +14,7 @@ public void HumanizesTerabytes(double input, string format, string expectedValue [InlineData(0, null, "0 bit")] [InlineData(0, "GB", "0 GB")] [InlineData(2, null, "2 GB")] - [InlineData(2, "MB", "2048 MB")] + [InlineData(2, "MB", "2000 MB")] [InlineData(2.123, "#.##", "2,12 GB")] public void HumanizesGigabytes(double input, string format, string expectedValue) => Assert.Equal(expectedValue, input.Gigabytes().Humanize(format)); @@ -23,7 +23,7 @@ public void HumanizesGigabytes(double input, string format, string expectedValue [InlineData(0, null, "0 bit")] [InlineData(0, "MB", "0 MB")] [InlineData(2, null, "2 MB")] - [InlineData(2, "KB", "2048 KB")] + [InlineData(2, "KB", "2000 KB")] [InlineData(2.123, "#", "2 MB")] public void HumanizesMegabytes(double input, string format, string expectedValue) => Assert.Equal(expectedValue, input.Megabytes().Humanize(format)); @@ -32,7 +32,7 @@ public void HumanizesMegabytes(double input, string format, string expectedValue [InlineData(0, null, "0 bit")] [InlineData(0, "KB", "0 KB")] [InlineData(2, null, "2 KB")] - [InlineData(2, "B", "2048 B")] + [InlineData(2, "B", "2000 B")] [InlineData(2.123, "#.####", "2,123 KB")] public void HumanizesKilobytes(double input, string format, string expectedValue) => Assert.Equal(expectedValue, input.Kilobytes().Humanize(format)); @@ -44,11 +44,11 @@ public void HumanizesKilobytes(double input, string format, string expectedValue [InlineData(0, "#.## B", "0 B")] [InlineData(0, "B", "0 B")] [InlineData(2, null, "2 B")] - [InlineData(2000, "KB", "1,95 KB")] - [InlineData(2123, "#.##", "2,07 KB")] - [InlineData(10000000, "KB", "9765,63 KB")] - [InlineData(10000000, "#,##0 KB", "9.766 KB")] - [InlineData(10000000, "#,##0.# KB", "9.765,6 KB")] + [InlineData(1950, "KB", "1,95 KB")] + [InlineData(2123, "#.##", "2,12 KB")] + [InlineData(9765630, "KB", "9765,63 KB")] + [InlineData(9765630, "#,##0 KB", "9.766 KB")] + [InlineData(9765630, "#,##0.# KB", "9.765,6 KB")] public void HumanizesBytes(double input, string format, string expectedValue) => Assert.Equal(expectedValue, input.Bytes().Humanize(format)); #endif @@ -58,7 +58,8 @@ public void HumanizesBytes(double input, string format, string expectedValue) => [InlineData(0, "b", "0 bit")] [InlineData(2, null, "2 bit")] [InlineData(12, "B", "1,5 B")] - [InlineData(10000, "#.# KB", "1,2 KB")] + [InlineData(10000, "#.# KB", "1,3 KB")] + [InlineData(10000, "#.# KiB", "1,2 KiB")] public void HumanizesBits(long input, string format, string expectedValue) => Assert.Equal(expectedValue, input.Bits().Humanize(format)); } diff --git a/src/Humanizer.Tests.Shared/Localisation/lb/Bytes/ToFullWordsTests.cs b/src/Humanizer.Tests.Shared/Localisation/lb/Bytes/ToFullWordsTests.cs index 8becfb62d..81c9ac143 100644 --- a/src/Humanizer.Tests.Shared/Localisation/lb/Bytes/ToFullWordsTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/lb/Bytes/ToFullWordsTests.cs @@ -53,7 +53,8 @@ public void ReturnsPluralTerabytes() => [Theory] [InlineData(229376, "B", "229376 Byte")] - [InlineData(229376, "# KB", "224 Kilobyte")] + [InlineData(229376, "# KB", "229 Kilobyte")] + [InlineData(229376, "# KiB", "224 Kibibyte")] public void ToFullWordsFormatted(double input, string format, string expectedValue) => Assert.Equal(expectedValue, ByteSize.FromBytes(input).ToFullWords(format)); } diff --git a/src/Humanizer.Tests.Shared/Localisation/lb/Bytes/ToStringTests.cs b/src/Humanizer.Tests.Shared/Localisation/lb/Bytes/ToStringTests.cs index 1b54fe2c3..71e4315ae 100644 --- a/src/Humanizer.Tests.Shared/Localisation/lb/Bytes/ToStringTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/lb/Bytes/ToStringTests.cs @@ -45,11 +45,11 @@ public void ReturnsSelectedFormat() => [Fact] public void ReturnsLargestMetricPrefixLargerThanZero() => - Assert.Equal("512 KB", ByteSize.FromMegabytes(.5).ToString("#.#")); + Assert.Equal("500 KB", ByteSize.FromMegabytes(.5).ToString("#.#")); [Fact] public void ReturnsLargestMetricPrefixLargerThanZeroForNegativeValues() => - Assert.Equal("-512 KB", ByteSize.FromMegabytes(-.5).ToString("#.#")); + Assert.Equal("-500 KB", ByteSize.FromMegabytes(-.5).ToString("#.#")); [Fact] public void ReturnsBytesViaGeneralFormat() => diff --git a/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.DotNet8_0.verified.txt b/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.DotNet8_0.verified.txt index 3d144f6ac..315bb8b10 100644 --- a/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.DotNet8_0.verified.txt +++ b/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.DotNet8_0.verified.txt @@ -61,9 +61,13 @@ namespace Humanizer public Humanizer.ByteSize Add(Humanizer.ByteSize bs) { } public Humanizer.ByteSize AddBits(long value) { } public Humanizer.ByteSize AddBytes(double value) { } + public Humanizer.ByteSize AddGibibytes(double value) { } public Humanizer.ByteSize AddGigabytes(double value) { } + public Humanizer.ByteSize AddKibibytes(double value) { } public Humanizer.ByteSize AddKilobytes(double value) { } + public Humanizer.ByteSize AddMebibytes(double value) { } public Humanizer.ByteSize AddMegabytes(double value) { } + public Humanizer.ByteSize AddTebibytes(double value) { } public Humanizer.ByteSize AddTerabytes(double value) { } public int CompareTo(Humanizer.ByteSize other) { } public int CompareTo(object obj) { } @@ -121,6 +125,14 @@ namespace Humanizer public static Humanizer.ByteSize Bytes(this short input) { } public static Humanizer.ByteSize Bytes(this uint input) { } public static Humanizer.ByteSize Bytes(this ushort input) { } + public static Humanizer.ByteSize Gibibytes(this byte input) { } + public static Humanizer.ByteSize Gibibytes(this double input) { } + public static Humanizer.ByteSize Gibibytes(this int input) { } + public static Humanizer.ByteSize Gibibytes(this long input) { } + public static Humanizer.ByteSize Gibibytes(this sbyte input) { } + public static Humanizer.ByteSize Gibibytes(this short input) { } + public static Humanizer.ByteSize Gibibytes(this uint input) { } + public static Humanizer.ByteSize Gibibytes(this ushort input) { } public static Humanizer.ByteSize Gigabytes(this byte input) { } public static Humanizer.ByteSize Gigabytes(this double input) { } public static Humanizer.ByteSize Gigabytes(this int input) { } @@ -132,6 +144,14 @@ namespace Humanizer public static string Humanize(this Humanizer.ByteSize input, System.IFormatProvider formatProvider) { } public static string Humanize(this Humanizer.ByteSize input, string format = null) { } public static string Humanize(this Humanizer.ByteSize input, string format, System.IFormatProvider formatProvider) { } + public static Humanizer.ByteSize Kibibytes(this byte input) { } + public static Humanizer.ByteSize Kibibytes(this double input) { } + public static Humanizer.ByteSize Kibibytes(this int input) { } + public static Humanizer.ByteSize Kibibytes(this long input) { } + public static Humanizer.ByteSize Kibibytes(this sbyte input) { } + public static Humanizer.ByteSize Kibibytes(this short input) { } + public static Humanizer.ByteSize Kibibytes(this uint input) { } + public static Humanizer.ByteSize Kibibytes(this ushort input) { } public static Humanizer.ByteSize Kilobytes(this byte input) { } public static Humanizer.ByteSize Kilobytes(this double input) { } public static Humanizer.ByteSize Kilobytes(this int input) { } @@ -140,6 +160,14 @@ namespace Humanizer public static Humanizer.ByteSize Kilobytes(this short input) { } public static Humanizer.ByteSize Kilobytes(this uint input) { } public static Humanizer.ByteSize Kilobytes(this ushort input) { } + public static Humanizer.ByteSize Mebibytes(this byte input) { } + public static Humanizer.ByteSize Mebibytes(this double input) { } + public static Humanizer.ByteSize Mebibytes(this int input) { } + public static Humanizer.ByteSize Mebibytes(this long input) { } + public static Humanizer.ByteSize Mebibytes(this sbyte input) { } + public static Humanizer.ByteSize Mebibytes(this short input) { } + public static Humanizer.ByteSize Mebibytes(this uint input) { } + public static Humanizer.ByteSize Mebibytes(this ushort input) { } public static Humanizer.ByteSize Megabytes(this byte input) { } public static Humanizer.ByteSize Megabytes(this double input) { } public static Humanizer.ByteSize Megabytes(this int input) { } @@ -149,6 +177,14 @@ namespace Humanizer public static Humanizer.ByteSize Megabytes(this uint input) { } public static Humanizer.ByteSize Megabytes(this ushort input) { } public static Humanizer.ByteRate Per(this Humanizer.ByteSize size, System.TimeSpan interval) { } + public static Humanizer.ByteSize Tebibytes(this byte input) { } + public static Humanizer.ByteSize Tebibytes(this double input) { } + public static Humanizer.ByteSize Tebibytes(this int input) { } + public static Humanizer.ByteSize Tebibytes(this long input) { } + public static Humanizer.ByteSize Tebibytes(this sbyte input) { } + public static Humanizer.ByteSize Tebibytes(this short input) { } + public static Humanizer.ByteSize Tebibytes(this uint input) { } + public static Humanizer.ByteSize Tebibytes(this ushort input) { } public static Humanizer.ByteSize Terabytes(this byte input) { } public static Humanizer.ByteSize Terabytes(this double input) { } public static Humanizer.ByteSize Terabytes(this int input) { } From cb33cda1a1fa7b107843f2f39b0f3cf95ca155fc Mon Sep 17 00:00:00 2001 From: Collin Alpert Date: Sun, 18 Feb 2024 23:49:55 +0100 Subject: [PATCH 3/4] Fix tests --- .../Localisation/de/Bytes/ByteSizeExtensionsTests.cs | 4 ++-- .../Localisation/lb/Bytes/ToFullWordsTests.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Humanizer.Tests.Shared/Localisation/de/Bytes/ByteSizeExtensionsTests.cs b/src/Humanizer.Tests.Shared/Localisation/de/Bytes/ByteSizeExtensionsTests.cs index 004f18478..2d3c4c921 100644 --- a/src/Humanizer.Tests.Shared/Localisation/de/Bytes/ByteSizeExtensionsTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/de/Bytes/ByteSizeExtensionsTests.cs @@ -29,7 +29,7 @@ public void HumanizesGigabytes(double input, string format, string expectedValue [InlineData(0, null, "0 bit")] [InlineData(0, "GiB", "0 GiB")] [InlineData(2, "MiB", "2048 MiB")] - [InlineData(2.123, "#.## GiB", "2,28 GiB")] + [InlineData(2.123, "#.## GiB", "2,12 GiB")] public void HumanizesGibibytes(double input, string format, string expectedValue) => Assert.Equal(expectedValue, input.Gibibytes().Humanize(format)); @@ -63,7 +63,7 @@ public void HumanizesKilobytes(double input, string format, string expectedValue [InlineData(0, null, "0 bit")] [InlineData(0, "KiB", "0 KiB")] [InlineData(2, "B", "2048 B")] - [InlineData(2.123, "#.#### KiB", "2,174 KiB")] + [InlineData(2.123, "#.#### KiB", "2,123 KiB")] public void HumanizesKibibytes(double input, string format, string expectedValue) => Assert.Equal(expectedValue, input.Kibibytes().Humanize(format)); diff --git a/src/Humanizer.Tests.Shared/Localisation/lb/Bytes/ToFullWordsTests.cs b/src/Humanizer.Tests.Shared/Localisation/lb/Bytes/ToFullWordsTests.cs index 81c9ac143..f5aa4c3f9 100644 --- a/src/Humanizer.Tests.Shared/Localisation/lb/Bytes/ToFullWordsTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/lb/Bytes/ToFullWordsTests.cs @@ -54,7 +54,7 @@ public void ReturnsPluralTerabytes() => [Theory] [InlineData(229376, "B", "229376 Byte")] [InlineData(229376, "# KB", "229 Kilobyte")] - [InlineData(229376, "# KiB", "224 Kibibyte")] + [InlineData(229376, "# KiB", "224 kibibyte")] public void ToFullWordsFormatted(double input, string format, string expectedValue) => Assert.Equal(expectedValue, ByteSize.FromBytes(input).ToFullWords(format)); } From e93d7f7b1bbcd89d0c324700f17af8fb29e85c9d Mon Sep 17 00:00:00 2001 From: Collin Alpert Date: Mon, 19 Feb 2024 00:01:27 +0100 Subject: [PATCH 4/4] Update Public API surface --- ...est.Approve_Public_Api.Net4_8.verified.txt | 74 +++++++++++++++++-- 1 file changed, 67 insertions(+), 7 deletions(-) diff --git a/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.Net4_8.verified.txt b/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.Net4_8.verified.txt index dad79f0e3..d8059adef 100644 --- a/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.Net4_8.verified.txt +++ b/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.Net4_8.verified.txt @@ -18,16 +18,28 @@ namespace Humanizer public const long BitsInByte = 8; public const string Byte = "byte"; public const string ByteSymbol = "B"; - public const long BytesInGigabyte = 1073741824; - public const long BytesInKilobyte = 1024; - public const long BytesInMegabyte = 1048576; - public const long BytesInTerabyte = 1099511627776; + public const long BytesInGibibyte = 1073741824; + public const long BytesInGigabyte = 1000000000; + public const long BytesInKibibyte = 1024; + public const long BytesInKilobyte = 1000; + public const long BytesInMebibyte = 1048576; + public const long BytesInMegabyte = 1000000; + public const long BytesInTebibyte = 1099511627776; + public const long BytesInTerabyte = 1000000000000; + public const string Gibibyte = "gibibyte"; + public const string GibibyteSymbol = "GiB"; public const string Gigabyte = "gigabyte"; public const string GigabyteSymbol = "GB"; + public const string Kibibyte = "kibibyte"; + public const string KibibyteSymbol = "KiB"; public const string Kilobyte = "kilobyte"; public const string KilobyteSymbol = "KB"; + public const string Mebibyte = "mebibyte"; + public const string MebibyteSymbol = "MiB"; public const string Megabyte = "megabyte"; public const string MegabyteSymbol = "MB"; + public const string Tebibyte = "tebibyte"; + public const string TebibyteSymbol = "TiB"; public const string Terabyte = "terabyte"; public const string TerabyteSymbol = "TB"; public static readonly Humanizer.ByteSize MaxValue; @@ -35,19 +47,27 @@ namespace Humanizer public ByteSize(double byteSize) { } public long Bits { get; } public double Bytes { get; } + public double Gibibytes { get; } public double Gigabytes { get; } + public double Kibibytes { get; } public double Kilobytes { get; } public string LargestWholeNumberFullWord { get; } public string LargestWholeNumberSymbol { get; } public double LargestWholeNumberValue { get; } + public double Mebibytes { get; } public double Megabytes { get; } + public double Tebibytes { get; } public double Terabytes { get; } public Humanizer.ByteSize Add(Humanizer.ByteSize bs) { } public Humanizer.ByteSize AddBits(long value) { } public Humanizer.ByteSize AddBytes(double value) { } + public Humanizer.ByteSize AddGibibytes(double value) { } public Humanizer.ByteSize AddGigabytes(double value) { } + public Humanizer.ByteSize AddKibibytes(double value) { } public Humanizer.ByteSize AddKilobytes(double value) { } + public Humanizer.ByteSize AddMebibytes(double value) { } public Humanizer.ByteSize AddMegabytes(double value) { } + public Humanizer.ByteSize AddTebibytes(double value) { } public Humanizer.ByteSize AddTerabytes(double value) { } public int CompareTo(Humanizer.ByteSize other) { } public int CompareTo(object obj) { } @@ -64,9 +84,13 @@ namespace Humanizer public string ToString(string format, System.IFormatProvider provider) { } public static Humanizer.ByteSize FromBits(long value) { } public static Humanizer.ByteSize FromBytes(double value) { } + public static Humanizer.ByteSize FromGibibytes(double value) { } public static Humanizer.ByteSize FromGigabytes(double value) { } + public static Humanizer.ByteSize FromKibibytes(double value) { } public static Humanizer.ByteSize FromKilobytes(double value) { } + public static Humanizer.ByteSize FromMebibytes(double value) { } public static Humanizer.ByteSize FromMegabytes(double value) { } + public static Humanizer.ByteSize FromTebibytes(double value) { } public static Humanizer.ByteSize FromTerabytes(double value) { } public static Humanizer.ByteSize Parse(string s) { } public static Humanizer.ByteSize Parse(string s, System.IFormatProvider formatProvider) { } @@ -101,6 +125,14 @@ namespace Humanizer public static Humanizer.ByteSize Bytes(this short input) { } public static Humanizer.ByteSize Bytes(this uint input) { } public static Humanizer.ByteSize Bytes(this ushort input) { } + public static Humanizer.ByteSize Gibibytes(this byte input) { } + public static Humanizer.ByteSize Gibibytes(this double input) { } + public static Humanizer.ByteSize Gibibytes(this int input) { } + public static Humanizer.ByteSize Gibibytes(this long input) { } + public static Humanizer.ByteSize Gibibytes(this sbyte input) { } + public static Humanizer.ByteSize Gibibytes(this short input) { } + public static Humanizer.ByteSize Gibibytes(this uint input) { } + public static Humanizer.ByteSize Gibibytes(this ushort input) { } public static Humanizer.ByteSize Gigabytes(this byte input) { } public static Humanizer.ByteSize Gigabytes(this double input) { } public static Humanizer.ByteSize Gigabytes(this int input) { } @@ -112,6 +144,14 @@ namespace Humanizer public static string Humanize(this Humanizer.ByteSize input, System.IFormatProvider formatProvider) { } public static string Humanize(this Humanizer.ByteSize input, string format = null) { } public static string Humanize(this Humanizer.ByteSize input, string format, System.IFormatProvider formatProvider) { } + public static Humanizer.ByteSize Kibibytes(this byte input) { } + public static Humanizer.ByteSize Kibibytes(this double input) { } + public static Humanizer.ByteSize Kibibytes(this int input) { } + public static Humanizer.ByteSize Kibibytes(this long input) { } + public static Humanizer.ByteSize Kibibytes(this sbyte input) { } + public static Humanizer.ByteSize Kibibytes(this short input) { } + public static Humanizer.ByteSize Kibibytes(this uint input) { } + public static Humanizer.ByteSize Kibibytes(this ushort input) { } public static Humanizer.ByteSize Kilobytes(this byte input) { } public static Humanizer.ByteSize Kilobytes(this double input) { } public static Humanizer.ByteSize Kilobytes(this int input) { } @@ -120,6 +160,14 @@ namespace Humanizer public static Humanizer.ByteSize Kilobytes(this short input) { } public static Humanizer.ByteSize Kilobytes(this uint input) { } public static Humanizer.ByteSize Kilobytes(this ushort input) { } + public static Humanizer.ByteSize Mebibytes(this byte input) { } + public static Humanizer.ByteSize Mebibytes(this double input) { } + public static Humanizer.ByteSize Mebibytes(this int input) { } + public static Humanizer.ByteSize Mebibytes(this long input) { } + public static Humanizer.ByteSize Mebibytes(this sbyte input) { } + public static Humanizer.ByteSize Mebibytes(this short input) { } + public static Humanizer.ByteSize Mebibytes(this uint input) { } + public static Humanizer.ByteSize Mebibytes(this ushort input) { } public static Humanizer.ByteSize Megabytes(this byte input) { } public static Humanizer.ByteSize Megabytes(this double input) { } public static Humanizer.ByteSize Megabytes(this int input) { } @@ -129,6 +177,14 @@ namespace Humanizer public static Humanizer.ByteSize Megabytes(this uint input) { } public static Humanizer.ByteSize Megabytes(this ushort input) { } public static Humanizer.ByteRate Per(this Humanizer.ByteSize size, System.TimeSpan interval) { } + public static Humanizer.ByteSize Tebibytes(this byte input) { } + public static Humanizer.ByteSize Tebibytes(this double input) { } + public static Humanizer.ByteSize Tebibytes(this int input) { } + public static Humanizer.ByteSize Tebibytes(this long input) { } + public static Humanizer.ByteSize Tebibytes(this sbyte input) { } + public static Humanizer.ByteSize Tebibytes(this short input) { } + public static Humanizer.ByteSize Tebibytes(this uint input) { } + public static Humanizer.ByteSize Tebibytes(this ushort input) { } public static Humanizer.ByteSize Terabytes(this byte input) { } public static Humanizer.ByteSize Terabytes(this double input) { } public static Humanizer.ByteSize Terabytes(this int input) { } @@ -172,9 +228,13 @@ namespace Humanizer Bit = 0, Byte = 1, Kilobyte = 2, - Megabyte = 3, - Gigabyte = 4, - Terabyte = 5, + Kibibyte = 3, + Megabyte = 4, + Mebibyte = 5, + Gigabyte = 6, + Gibibyte = 7, + Terabyte = 8, + Tebibyte = 9, } public static class DateHumanizeExtensions {