-
-
Notifications
You must be signed in to change notification settings - Fork 395
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* MonoTorrent.Tests/MonoTorrent.Tests.csproj:
* MonoTorrent.Tests/Common/SpeedMonitorTest.cs: Add tests to ensure the correctness of the transfer rate estimation code. * MonoTorrent/MonoTorrent.Common/SpeedMonitor.cs: Add missing license header and update the rate estimation algorithm so that it no longer gives insane answers when the number of ticks is less than the averaging period. Patch by 'nop'. svn path=/trunk/bitsharp/; revision=156979
- Loading branch information
1 parent
0ed1f9f
commit 8799aa8
Showing
3 changed files
with
146 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using System; | ||
using NUnit.Framework; | ||
|
||
namespace MonoTorrent.Common | ||
{ | ||
[TestFixture] | ||
public class SpeedMonitorTest | ||
{ | ||
[Test] | ||
public void ZeroAveragingPeriod () | ||
{ | ||
var monitor = new SpeedMonitor (0); | ||
monitor.AddDelta (1000); | ||
monitor.Tick (1000); | ||
|
||
Assert.AreEqual (1000, monitor.Rate, "#1"); | ||
} | ||
|
||
[Test] | ||
public void Tick () | ||
{ | ||
var monitor = new SpeedMonitor (); | ||
monitor.AddDelta (1000); | ||
monitor.Tick (1000); | ||
|
||
Assert.AreEqual (1000, monitor.Rate, "#1"); | ||
} | ||
|
||
[Test] | ||
public void TickTwice () | ||
{ | ||
// Send 1000 bytes in 2000 milliseconds. Check | ||
// transfer rate is then 500bytes/second | ||
var monitor = new SpeedMonitor (); | ||
monitor.AddDelta (1000); | ||
monitor.Tick (1000); | ||
monitor.Tick (1000); | ||
|
||
Assert.AreEqual (500, monitor.Rate, "#1"); | ||
} | ||
|
||
[Test] | ||
public void TickFull () | ||
{ | ||
// Averaging period is 3, tick 3 times. | ||
var monitor = new SpeedMonitor (3); | ||
monitor.AddDelta (1200); | ||
monitor.Tick (1000); | ||
monitor.Tick (1000); | ||
monitor.Tick (1000); | ||
|
||
Assert.AreEqual (400, monitor.Rate, "#1"); | ||
} | ||
|
||
[Test] | ||
public void Tick_AveragingTwo_TickThree () | ||
{ | ||
// Send data only in the first tick. When we tick a third time | ||
// we should have a transfer rate of zero as the data should vanish. | ||
var monitor = new SpeedMonitor (2); | ||
monitor.AddDelta (1200); | ||
monitor.Tick (1000); | ||
monitor.Tick (1000); | ||
monitor.Tick (1000); | ||
|
||
Assert.AreEqual (0, monitor.Rate, "#1"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters