mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-15 00:12:50 +08:00
ProgressTask.GetPercentage() returns 100 when max value is 0 (#1694)
This commit is contained in:
parent
be45494d6e
commit
4515d89705
@ -224,6 +224,11 @@ public sealed class ProgressTask : IProgress<double>
|
|||||||
|
|
||||||
private double GetPercentage()
|
private double GetPercentage()
|
||||||
{
|
{
|
||||||
|
if (MaxValue == 0)
|
||||||
|
{
|
||||||
|
return 100;
|
||||||
|
}
|
||||||
|
|
||||||
var percentage = (Value / MaxValue) * 100;
|
var percentage = (Value / MaxValue) * 100;
|
||||||
percentage = Math.Min(100, Math.Max(0, percentage));
|
percentage = Math.Min(100, Math.Max(0, percentage));
|
||||||
return percentage;
|
return percentage;
|
||||||
|
@ -118,6 +118,31 @@ public sealed class ProgressTests
|
|||||||
task.Value.ShouldBe(20);
|
task.Value.ShouldBe(20);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Setting_Max_Value_To_Zero_Should_Make_Percentage_OneHundred()
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
var console = new TestConsole()
|
||||||
|
.Interactive();
|
||||||
|
|
||||||
|
var task = default(ProgressTask);
|
||||||
|
var progress = new Progress(console)
|
||||||
|
.Columns(new[] { new ProgressBarColumn() })
|
||||||
|
.AutoRefresh(false)
|
||||||
|
.AutoClear(false);
|
||||||
|
|
||||||
|
// When
|
||||||
|
progress.Start(ctx =>
|
||||||
|
{
|
||||||
|
task = ctx.AddTask("foo");
|
||||||
|
task.MaxValue = 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Then
|
||||||
|
task.Value.ShouldBe(0);
|
||||||
|
task.Percentage.ShouldBe(100);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Setting_Value_Should_Override_Incremented_Value()
|
public void Setting_Value_Should_Override_Incremented_Value()
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user