Skip to content

Commit 1bb37bf

Browse files
authored
Speed test results should be displayed in user specified scale (#62)
1 parent f83c586 commit 1bb37bf

17 files changed

Lines changed: 640 additions & 41 deletions

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ USAGE:
9191
OPTIONS:
9292
DEFAULT
9393
-h, --help Prints help information.
94+
-v, --version Prints version information.
9495
--loop Performs the speed test on continuous loop.
9596
--count Stop speed testing after this many times.
9697
--delay Time between multiple speed tests (HH:MM:SS)
@@ -105,6 +106,7 @@ OPTIONS:
105106
--downloadsize Stop the download test after this many megabytes (IEC MiB).
106107
--uploadsize Stop the upload test after this many megabytes (IEC MiB).
107108
-u, --unit BitsPerSecond The speed unit. <BitsPerSecond, BytesPerSecond>
109+
--unit-scale Auto The speed unit scale. <Auto, Base, Kilo, Mega, Giga, Tera, Peta>
108110
--unit-system SI The speed unit system. <SI, IEC>
109111
SI steps up in powers of 1000 (KB, MB, GB), common in networking,
110112
while IEC uses powers of 1024 (KiB, MiB, GiB), standard in computing

USER_GUIDE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ Run a simple speed test using the nearest available server:
55
NetPace
66
```
77

8-
Produce minimal CSV output, suitable for scripting or parsing:
8+
Produce CSV output with test results in megabits, suitable for parsing:
99
```bash
10-
NetPace --csv
10+
NetPace --csv --unit-scale Mega
1111
```
1212

1313
Run download test only:

src/NetPace.Console.Tests/Expectations/NetPaceConsoleTests.Should_Display_Help.verified.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ OPTIONS:
3030
--downloadsize Stop the download test after this many megabytes (IEC MiB).
3131
--uploadsize Stop the upload test after this many megabytes (IEC MiB).
3232
-u, --unit BitsPerSecond The speed unit. <BitsPerSecond, BytesPerSecond>
33+
--unit-scale Auto The speed unit scale. <Auto, Base, Kilo, Mega, Giga, Tera, Peta>
3334
--unit-system SI The speed unit system. <SI, IEC>
3435
SI steps up in powers of 1000 (KB, MB, GB), common in networking, while IEC uses powers of 1024 (KiB, MiB, GiB), standard in computing and storage.
3536
--verbosity Normal The verbosity level. <Minimal, Normal, Debug>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Latency: 75 ms, Download: 0.25 Mbps, Upload: 0.5 Mbps
2+
Latency: 100 ms, Download: 1 Mbps, Upload: 3 Mbps
3+
Latency: 150 ms, Download: 2.75 Mbps, Upload: 1.33 Mbps
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Timestamp,Latency,Download,Upload
2+
1980-01-01 10:05:00,75 ms,0.25 Mbps,0.5 Mbps
3+
1980-01-01 10:05:05,100 ms,1 Mbps,3 Mbps
4+
1980-01-01 10:05:10,150 ms,2.75 Mbps,1.33 Mbps
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
Test Sponsor 1
3+
http://test1.com
4+
5+
Latency: 100 ms, Download: 0.01 Mbps, Upload: 0.02 Mbps
6+
7+
Try 'NetPace --help' for more information.

src/NetPace.Console.Tests/NetPaceConsoleTests.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,24 @@ public async Task Should_Perform_Speed_Test()
141141
await Verify(result.Output);
142142
}
143143

144+
[Fact]
145+
public async Task Should_Perform_Speed_Test_With_Fixed_Unit_Scale()
146+
{
147+
// Given
148+
var registrar = new TypeRegistrar();
149+
registrar.Register(typeof(ISpeedTestService), typeof(SpeedTestStub));
150+
registrar.Register(typeof(IClock), typeof(ClockStub));
151+
registrar.Register(typeof(IWaiter), typeof(NoDelayStub));
152+
var app = GetCommandAppTester(registrar);
153+
154+
// When
155+
var result = await app.RunAsync("--unit-scale", "Mega");
156+
157+
// Then
158+
Assert.Equal(0, result.ExitCode);
159+
await Verify(result.Output);
160+
}
161+
144162
[Fact]
145163
public async Task Should_Perform_Speed_Test_Continuously()
146164
{
@@ -203,6 +221,24 @@ public async Task Should_Perform_Speed_Test_Multiple_Times_With_Delay(int count,
203221
await Verify(result.Output).UseParameters(count, delay);
204222
}
205223

224+
[Fact]
225+
public async Task Should_Perform_Speed_Test_Multiple_Times_With_Fixed_Scale()
226+
{
227+
// Given
228+
var registrar = new TypeRegistrar();
229+
registrar.Register(typeof(ISpeedTestService), typeof(VariableSpeedTester));
230+
registrar.Register(typeof(IClock), typeof(IncrementingClockStub));
231+
registrar.Register(typeof(IWaiter), typeof(NoDelayStub));
232+
var app = GetCommandAppTester(registrar);
233+
234+
// When
235+
var result = await app.RunAsync("--count", "3", "--unit-scale", "Mega", "--verbosity", "Minimal");
236+
237+
// Then
238+
Assert.Equal(0, result.ExitCode);
239+
await Verify(result.Output);
240+
}
241+
206242
[InlineData("Minimal")]
207243
[InlineData("Normal")]
208244
[InlineData("Debug")]
@@ -326,6 +362,24 @@ public async Task Should_Perform_Speed_Test_With_CSV_Multiple_Times_With_Delay(i
326362
await Verify(result.Output).UseParameters(count, delay);
327363
}
328364

365+
[Fact]
366+
public async Task Should_Perform_Speed_Test_With_CSV_Multiple_Times_With_Fixed_Scale()
367+
{
368+
// Given
369+
var registrar = new TypeRegistrar();
370+
registrar.Register(typeof(ISpeedTestService), typeof(VariableSpeedTester));
371+
registrar.Register(typeof(IClock), typeof(IncrementingClockStub));
372+
registrar.Register(typeof(IWaiter), typeof(NoDelayStub));
373+
var app = GetCommandAppTester(registrar);
374+
375+
// When
376+
var result = await app.RunAsync("--csv", "--count", "3", "--unit-scale", "Mega", "--verbosity", "Minimal");
377+
378+
// Then
379+
Assert.Equal(0, result.ExitCode);
380+
await Verify(result.Output);
381+
}
382+
329383
[Fact]
330384
public async Task Should_Perform_Speed_Test_With_CSV_No_Download()
331385
{
@@ -665,4 +719,5 @@ public async Task Should_Display_Version(string version)
665719
}
666720

667721
#endregion
722+
668723
}

src/NetPace.Console.Tests/VerifyConfiguration.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Runtime.CompilerServices;
2+
using DiffEngine;
23

34
namespace NetPace.Console.Tests;
45

src/NetPace.Console/Commands/SpeedTestCommand.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ private async Task internalExecuteAsync(bool includeCSVHeader, SpeedTestCommandS
164164
{
165165
settings.IncludeTimestamp ? clock.Now.ToString(settings.DateTimeFormat) : null,
166166
$"{fastest.Latency} ms",
167-
!settings.NoDownload ? downloadResult.GetSpeedString(settings.SpeedUnit, settings.SpeedUnitSystem) : null,
168-
!settings.NoUpload ? uploadResult.GetSpeedString(settings.SpeedUnit, settings.SpeedUnitSystem) : null
167+
!settings.NoDownload ? downloadResult.GetSpeedString(settings.SpeedUnit, settings.SpeedUnitSystem, settings.SpeedScale) : null,
168+
!settings.NoUpload ? uploadResult.GetSpeedString(settings.SpeedUnit, settings.SpeedUnitSystem, settings.SpeedScale) : null
169169
}.Where(s => !string.IsNullOrEmpty(s))));
170170
}
171171
else
@@ -207,8 +207,8 @@ private async Task internalExecuteAsync(bool includeCSVHeader, SpeedTestCommandS
207207
{
208208
settings.IncludeTimestamp ? clock.Now.ToString(settings.DateTimeFormat) : null,
209209
$"Latency: {fastest.Latency} ms",
210-
!settings.NoDownload ? $"Download: {downloadResult.GetSpeedString(settings.SpeedUnit, settings.SpeedUnitSystem)}" : null,
211-
!settings.NoUpload ? $"Upload: {uploadResult.GetSpeedString(settings.SpeedUnit, settings.SpeedUnitSystem)}" : null
210+
!settings.NoDownload ? $"Download: {downloadResult.GetSpeedString(settings.SpeedUnit, settings.SpeedUnitSystem, settings.SpeedScale)}" : null,
211+
!settings.NoUpload ? $"Upload: {uploadResult.GetSpeedString(settings.SpeedUnit, settings.SpeedUnitSystem, settings.SpeedScale)}" : null
212212
}.Where(s => !string.IsNullOrEmpty(s))));
213213

214214

0 commit comments

Comments
 (0)