mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-08-03 02:17:59 +08:00
Adding TransferSpeedColumn configuration to display bits/bytes + binary/decimal prefixes (#904)
* Adding configuration to TransferSpeedColumn to be able to display in both bytes/bits, as well as using binary/decimal prefix definitions. --------- Co-authored-by: Frank Ray <52075808+FrankRay78@users.noreply.github.com>
This commit is contained in:
@ -0,0 +1,85 @@
|
||||
namespace Spectre.Console.Tests.Unit.Internal;
|
||||
|
||||
public sealed class FileSizeTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(0, "0 bytes")]
|
||||
[InlineData(37, "37 bytes")]
|
||||
[InlineData(512, "512 bytes")]
|
||||
[InlineData(15 * 1024, "15.0 KiB")]
|
||||
[InlineData(1024 * 512, "512.0 KiB")]
|
||||
[InlineData(5 * 1024 * 1024, "5.0 MiB")]
|
||||
[InlineData(9 * 1024 * 1024, "9.0 MiB")]
|
||||
public void Binary_Unit_In_Bytes_Should_Return_Expected(double bytes, string expected)
|
||||
{
|
||||
// Given
|
||||
var filesize = new FileSize(bytes, FileSizeBase.Binary);
|
||||
|
||||
// When
|
||||
var result = filesize.ToString();
|
||||
|
||||
// Then
|
||||
result.ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0, "0 bits")]
|
||||
[InlineData(37, "296 bits")]
|
||||
[InlineData(512, "4.0 Kibit")]
|
||||
[InlineData(15 * 1024, "120.0 Kibit")]
|
||||
[InlineData(1024 * 512, "4.0 Mibit")]
|
||||
[InlineData(5 * 1024 * 1024, "40.0 Mibit")]
|
||||
[InlineData(210 * 1024 * 1024, "1.6 Gibit")]
|
||||
[InlineData(900 * 1024 * 1024, "7.0 Gibit")]
|
||||
public void Binary_Unit_In_Bits_Should_Return_Expected(double bytes, string expected)
|
||||
{
|
||||
// Given
|
||||
var filesize = new FileSize(bytes, FileSizeBase.Binary, showBits: true);
|
||||
|
||||
// When
|
||||
var result = filesize.ToString();
|
||||
|
||||
// Then
|
||||
result.ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0, "0 bytes")]
|
||||
[InlineData(37, "37 bytes")]
|
||||
[InlineData(512, "512 bytes")]
|
||||
[InlineData(15 * 1024, "15.4 KB")]
|
||||
[InlineData(1024 * 512, "524.3 KB")]
|
||||
[InlineData(5 * 1024 * 1024, "5.2 MB")]
|
||||
[InlineData(9 * 1024 * 1024, "9.4 MB")]
|
||||
public void Decimal_Unit_In_Bytes_Should_Return_Expected(double bytes, string expected)
|
||||
{
|
||||
// Given
|
||||
var filesize = new FileSize(bytes, FileSizeBase.Decimal);
|
||||
|
||||
// When
|
||||
var result = filesize.ToString();
|
||||
|
||||
// Then
|
||||
result.ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0, "0 bits")]
|
||||
[InlineData(37, "296 bits")]
|
||||
[InlineData(512, "4.1 Kbit")]
|
||||
[InlineData(15 * 1024, "122.9 Kbit")]
|
||||
[InlineData(1024 * 512, "4.2 Mbit")]
|
||||
[InlineData(5 * 1024 * 1024, "41.9 Mbit")]
|
||||
[InlineData(900 * 1024 * 1024, "7.5 Gbit")]
|
||||
public void Decimal_Unit_In_Bits_Should_Return_Expected(double bytes, string expected)
|
||||
{
|
||||
// Given
|
||||
var filesize = new FileSize(bytes, FileSizeBase.Decimal, showBits: true);
|
||||
|
||||
// When
|
||||
var result = filesize.ToString();
|
||||
|
||||
// Then
|
||||
result.ShouldBe(expected);
|
||||
}
|
||||
}
|
@ -6,15 +6,71 @@ public sealed class DownloadedColumnTests
|
||||
[InlineData(0, 1, "0/1 byte")]
|
||||
[InlineData(37, 101, "37/101 bytes")]
|
||||
[InlineData(101, 101, "101 bytes")]
|
||||
[InlineData(512, 1024, "0.5/1.0 KB")]
|
||||
[InlineData(1024, 1024, "1.0 KB")]
|
||||
[InlineData(1024 * 512, 5 * 1024 * 1024, "0.5/5.0 MB")]
|
||||
[InlineData(5 * 1024 * 1024, 5 * 1024 * 1024, "5.0 MB")]
|
||||
public void Should_Return_Correct_Value(double value, double total, string expected)
|
||||
[InlineData(512, 1024, "0.5/1.0 KiB")]
|
||||
[InlineData(1024, 1024, "1.0 KiB")]
|
||||
[InlineData(1024 * 512, 5 * 1024 * 1024, "0.5/5.0 MiB")]
|
||||
[InlineData(5 * 1024 * 1024, 5 * 1024 * 1024, "5.0 MiB")]
|
||||
public void Binary_Unit_In_Bytes_Should_Return_Expected(double value, double total, string expected)
|
||||
{
|
||||
// Given
|
||||
var fixture = new ProgressColumnFixture<DownloadedColumn>(value, total);
|
||||
fixture.Column.Culture = CultureInfo.InvariantCulture;
|
||||
fixture.Column.Base = FileSizeBase.Binary;
|
||||
fixture.Column.ShowBits = false;
|
||||
|
||||
// When
|
||||
var result = fixture.Render();
|
||||
|
||||
// Then
|
||||
result.ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(512, 1024, "4.0/8.0 Kibit")]
|
||||
[InlineData(1024, 1024, "8.0 Kibit")]
|
||||
public void Binary_Unit_In_Bits_Should_Return_Expected(double value, double total, string expected)
|
||||
{
|
||||
// Given
|
||||
var fixture = new ProgressColumnFixture<DownloadedColumn>(value, total);
|
||||
fixture.Column.Culture = CultureInfo.InvariantCulture;
|
||||
fixture.Column.Base = FileSizeBase.Binary;
|
||||
fixture.Column.ShowBits = true;
|
||||
|
||||
// When
|
||||
var result = fixture.Render();
|
||||
|
||||
// Then
|
||||
result.ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(500, 1000, "0.5/1.0 KB")]
|
||||
[InlineData(1000, 1000, "1.0 KB")]
|
||||
public void Decimal_Unit_In_Bytes_Should_Return_Expected(double value, double total, string expected)
|
||||
{
|
||||
// Given
|
||||
var fixture = new ProgressColumnFixture<DownloadedColumn>(value, total);
|
||||
fixture.Column.Culture = CultureInfo.InvariantCulture;
|
||||
fixture.Column.Base = FileSizeBase.Decimal;
|
||||
fixture.Column.ShowBits = false;
|
||||
|
||||
// When
|
||||
var result = fixture.Render();
|
||||
|
||||
// Then
|
||||
result.ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(500, 1000, "4.0/8.0 Kbit")]
|
||||
[InlineData(1000, 1000, "8.0 Kbit")]
|
||||
public void Decimal_Unit_In_Bits_Should_Return_Expected(double value, double total, string expected)
|
||||
{
|
||||
// Given
|
||||
var fixture = new ProgressColumnFixture<DownloadedColumn>(value, total);
|
||||
fixture.Column.Culture = CultureInfo.InvariantCulture;
|
||||
fixture.Column.Base = FileSizeBase.Decimal;
|
||||
fixture.Column.ShowBits = true;
|
||||
|
||||
// When
|
||||
var result = fixture.Render();
|
||||
|
Reference in New Issue
Block a user