Skip to content

Commit

Permalink
Merged ProgressSteps into ProgressMonitor
Browse files Browse the repository at this point in the history
  • Loading branch information
pescuma committed Apr 30, 2014
1 parent 947bba6 commit f04943f
Show file tree
Hide file tree
Showing 9 changed files with 262 additions and 323 deletions.
110 changes: 55 additions & 55 deletions csharp/ProgressMonitor.Test/FlatToHierarchicalProgressMonitorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,88 +37,88 @@ public void TestConfigure()
[Test]
public void TestStart()
{
var steps = progress.ConfigureSteps(1);
steps.StartStep();
progress.ConfigureSteps(1);
progress.StartStep();

flat.Verify(f => f.SetCurrent(0, 1000, ""));
}

[Test]
public void Test2Steps()
{
var steps = progress.ConfigureSteps(2);
steps.StartStep();
steps.StartStep();
progress.ConfigureSteps(2);
progress.StartStep();
progress.StartStep();

flat.Verify(f => f.SetCurrent(500, 1000, ""));
}

[Test]
public void Test2Steps19()
{
var steps = progress.ConfigureSteps(1, 9);
steps.StartStep();
steps.StartStep();
progress.ConfigureSteps(1, 9);
progress.StartStep();
progress.StartStep();

flat.Verify(f => f.SetCurrent(100, 1000, ""));
}

[Test]
public void Test2Steps172()
{
var steps = progress.ConfigureSteps(1, 7, 2);
steps.StartStep();
steps.StartStep();
steps.StartStep();
progress.ConfigureSteps(1, 7, 2);
progress.StartStep();
progress.StartStep();
progress.StartStep();

flat.Verify(f => f.SetCurrent(800, 1000, ""));
}

[Test]
public void TestDispose_NotStarted()
{
var steps = progress.ConfigureSteps(1);
steps.Dispose();
var disp = progress.ConfigureSteps(1);
disp.Dispose();

flat.Verify(f => f.SetCurrent(1000, 1000, ""), Times.Never);
}

[Test]
public void TestFinished_UsedAll()
{
var steps = progress.ConfigureSteps(1);
steps.StartStep();
steps.Finished();
progress.ConfigureSteps(1);
progress.StartStep();
progress.Finished();

flat.Verify(f => f.SetCurrent(1000, 1000));
}

[Test]
public void TestFinished_NotUsedAll()
{
var steps = progress.ConfigureSteps(10);
steps.StartStep();
steps.Finished();
progress.ConfigureSteps(10);
progress.StartStep();
progress.Finished();

flat.Verify(f => f.SetCurrent(1000, 1000));
}

[Test]
public void TestStepName()
{
var steps = progress.ConfigureSteps(1);
steps.StartStep("A");
progress.ConfigureSteps(1);
progress.StartStep("A");

flat.Verify(f => f.SetCurrent(0, 1000, "A"));
}

[Test]
public void TestSubStep_ConfigureDoesntPropagate()
{
var steps = progress.ConfigureSteps(2);
steps.StartStep();
progress.ConfigureSteps(2);
progress.StartStep();

var sub = steps.CreateSubMonitor();
var sub = progress.CreateSubMonitor();
sub.ConfigureSteps(2);

flat.Verify(f => f.SetCurrent(0, 1000, ""), Times.Once);
Expand All @@ -128,11 +128,11 @@ public void TestSubStep_ConfigureDoesntPropagate()
[Test]
public void TestSubStep_DisposeDoesntPropagate()
{
var steps = progress.ConfigureSteps(2);
steps.StartStep();
progress.ConfigureSteps(2);
progress.StartStep();

var sub = steps.CreateSubMonitor()
.ConfigureSteps(2);
var sub = progress.CreateSubMonitor();
sub.ConfigureSteps(2);
sub.StartStep();
sub.Finished();

Expand All @@ -143,11 +143,11 @@ public void TestSubStep_DisposeDoesntPropagate()
[Test]
public void TestSubStep_StepPropagates()
{
var steps = progress.ConfigureSteps(2);
steps.StartStep();
progress.ConfigureSteps(2);
progress.StartStep();

var sub = steps.CreateSubMonitor()
.ConfigureSteps(2);
var sub = progress.CreateSubMonitor();
sub.ConfigureSteps(2);
sub.StartStep();
sub.StartStep();

Expand All @@ -157,11 +157,11 @@ public void TestSubStep_StepPropagates()
[Test]
public void TestSubStep_SetStepNamePropagates()
{
var steps = progress.ConfigureSteps(2);
steps.StartStep("A");
progress.ConfigureSteps(2);
progress.StartStep("A");

var sub = steps.CreateSubMonitor()
.ConfigureSteps(2);
var sub = progress.CreateSubMonitor();
sub.ConfigureSteps(2);
sub.StartStep("B");

flat.Verify(f => f.SetCurrent(0, 1000, "A", "B"));
Expand All @@ -178,59 +178,59 @@ public void TestOnStarted_NotCalledOnConfigure()
[Test]
public void TestOnStarted_CalledOnFirstStart()
{
var steps = progress.ConfigureSteps(2);
steps.StartStep();
progress.ConfigureSteps(2);
progress.StartStep();

Assert.AreEqual(1, onStartedCalls);
}

[Test]
public void TestOnStarted_CalledOnMultipleStart()
{
var steps = progress.ConfigureSteps(2);
steps.StartStep();
steps.StartStep();
progress.ConfigureSteps(2);
progress.StartStep();
progress.StartStep();

Assert.AreEqual(2, onStartedCalls);
}

[Test]
public void TestOnStarted_NotCalledOnFinish()
{
var steps = progress.ConfigureSteps(2);
steps.StartStep();
steps.StartStep();
steps.Finished();
progress.ConfigureSteps(2);
progress.StartStep();
progress.StartStep();
progress.Finished();

Assert.AreEqual(2, onStartedCalls);
}

[Test]
public void TestOnFinished_NotCalledOnStart()
{
var steps = progress.ConfigureSteps(2);
steps.StartStep();
progress.ConfigureSteps(2);
progress.StartStep();

Assert.AreEqual(0, onFinishedCalls);
}

[Test]
public void TestOnFinished_CalledOnMulitpleStarts()
{
var steps = progress.ConfigureSteps(2);
steps.StartStep();
steps.StartStep();
progress.ConfigureSteps(2);
progress.StartStep();
progress.StartStep();

Assert.AreEqual(1, onFinishedCalls);
}

[Test]
public void TestOnFinished_CalledOnFinish()
{
var steps = progress.ConfigureSteps(2);
steps.StartStep();
steps.StartStep();
steps.Finished();
progress.ConfigureSteps(2);
progress.StartStep();
progress.StartStep();
progress.Finished();

Assert.AreEqual(2, onFinishedCalls);
}
Expand Down
1 change: 0 additions & 1 deletion csharp/ProgressMonitor.Test/flat/console/widget/ETATest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using NUnit.Framework;
using org.pescuma.progressmonitor.console.widget;
using org.pescuma.progressmonitor.utils;

namespace org.pescuma.progressmonitor.flat.console.widget
Expand Down
2 changes: 1 addition & 1 deletion csharp/ProgressMonitor/FlatProgressMonitor.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace org.pescuma.progressmonitor
{
/// <summary>
/// A simple progress monitor, that doesn't allow sub-steps.
/// A simple progress monitor that doesn't allow sub-steps.
///
/// Usually used internally by progress monitors.
/// </summary>
Expand Down
36 changes: 28 additions & 8 deletions csharp/ProgressMonitor/ProgressMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,30 @@

namespace org.pescuma.progressmonitor
{
public interface ProgressMonitor : FlatProgressMonitor
public interface ProgressMonitor : ProgressReporter
{
/// <summary>
/// Configure the number of steps. Must be called before StartStep
/// </summary>
/// <param name="steps">If one element: the number of steps. If more than one: the weighs for each step.</param>
/// <returns>Disposable to stop this monitor. It can also be stopped by calling Finished()</returns>
ProgressSteps ConfigureSteps(params int[] steps);
/// <returns>IDisposable that calls Finished()</returns>
IDisposable ConfigureSteps(params int[] steps);

/// <summary>
/// Finishes the previous step and starts the next one.
/// </summary>
/// <param name="stepName">The next step name. Optional.</param>
void StartStep(string stepName = null);

/// <summary>
/// Create a monitor for sub-steps of the current step.
/// </summary>
ProgressMonitor CreateSubMonitor();

/// <summary>
/// Finishes all the steps. Must be the last method called.
/// </summary>
void Finished();
}

public static class ProgressMonitorExtensions
Expand All @@ -29,7 +45,9 @@ public static IEnumerable<T> Wrap<T>(this ProgressMonitor monitor, IEnumerable<T

int size;
if (c != null)
{
size = c.Count;
}
else
{
c = new List<T>();
Expand All @@ -40,12 +58,14 @@ public static IEnumerable<T> Wrap<T>(this ProgressMonitor monitor, IEnumerable<T

if (size > 0)
{
var steps = monitor.ConfigureSteps(size);

foreach (var el in c)
using (monitor.ConfigureSteps(size))
{
steps.StartStep(stepName(el));
yield return el;
foreach (var el in c)
{
monitor.StartStep(stepName(el));

yield return el;
}
}
}
}
Expand Down
1 change: 0 additions & 1 deletion csharp/ProgressMonitor/ProgressMonitor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
<Compile Include="console\MachineReadableConsole.cs" />
<Compile Include="console\MachineReadableConsoleFlatProgressMonitor.cs" />
<Compile Include="ProgressReporter.cs" />
<Compile Include="ProgressSteps.cs" />
<Compile Include="ProgressMonitor.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="console\widget\BarWidget.cs" />
Expand Down
23 changes: 0 additions & 23 deletions csharp/ProgressMonitor/ProgressSteps.cs

This file was deleted.

3 changes: 1 addition & 2 deletions csharp/ProgressMonitor/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,4 @@

[assembly: AssemblyVersion("0.1.0.0")]
[assembly: AssemblyFileVersion("0.1.0.0")]

[assembly: InternalsVisibleTo("ProgressMonitor.Test")]
[assembly: InternalsVisibleTo("ProgressMonitor.Test")]
Loading

0 comments on commit f04943f

Please sign in to comment.