+27
-0
lines changedFilter options
+27
-0
lines changed Original file line number Diff line number Diff line change
@@ -51,5 +51,19 @@ public class BitswapLedger
51
51
/// </value>
52
52
public ulong DataSent { get; set; }
53
53
54
+
/// <summary>
55
+
/// The calculated debt to the peer.
56
+
/// </summary>
57
+
/// <value>
58
+
/// <see cref="DataSent"/> divided by <see cref="DataReceived"/>.
59
+
/// </value>
60
+
public float DebtRatio
61
+
{
62
+
get
63
+
{
64
+
return (float)DataSent / (float)(DataReceived + 1); // +1 is to prevent division by zero
65
+
}
66
+
}
67
+
54
68
}
55
69
}
Original file line number Diff line number Diff line change
@@ -18,8 +18,21 @@ public void Defaults()
18
18
Assert.AreEqual(0ul, ledger.BlocksSent);
19
19
Assert.AreEqual(0ul, ledger.DataReceived);
20
20
Assert.AreEqual(0ul, ledger.DataSent);
21
+
Assert.AreEqual(0f, ledger.DebtRatio);
21
22
}
22
23
24
+
[TestMethod]
25
+
public void DebtRatio_Positive()
26
+
{
27
+
var ledger = new BitswapLedger { DataSent = 1024 * 1024 };
28
+
Assert.IsTrue(ledger.DebtRatio >= 1);
29
+
}
23
30
31
+
[TestMethod]
32
+
public void DebtRatio_Negative()
33
+
{
34
+
var ledger = new BitswapLedger { DataReceived = 1024 * 1024 };
35
+
Assert.IsTrue(ledger.DebtRatio < 1);
36
+
}
24
37
}
25
38
}
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4