File tree Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,8 @@ public class BitswapLedger
5656 /// </summary>
5757 /// <value>
5858 /// <see cref="DataSent"/> divided by <see cref="DataReceived"/>.
59+ /// A value less than 1 indicates that we are in debt to the
60+ /// <see cref="Peer"/>.
5961 /// </value>
6062 public float DebtRatio
6163 {
@@ -65,5 +67,13 @@ public float DebtRatio
6567 }
6668 }
6769
70+ /// <summary>
71+ /// Determines if we owe the <see cref="Peer"/> some blocks.
72+ /// </summary>
73+ /// <value>
74+ /// <b>true</b> if we owe data to the peer; otherwise, <b>false</b>.
75+ /// </value>
76+ public bool IsInDebt => DebtRatio < 1 ;
77+
6878 }
6979}
Original file line number Diff line number Diff line change @@ -19,20 +19,23 @@ public void Defaults()
1919 Assert . AreEqual ( 0ul , ledger . DataReceived ) ;
2020 Assert . AreEqual ( 0ul , ledger . DataSent ) ;
2121 Assert . AreEqual ( 0f , ledger . DebtRatio ) ;
22+ Assert . IsTrue ( ledger . IsInDebt ) ;
2223 }
2324
2425 [ TestMethod ]
2526 public void DebtRatio_Positive ( )
2627 {
2728 var ledger = new BitswapLedger { DataSent = 1024 * 1024 } ;
2829 Assert . IsTrue ( ledger . DebtRatio >= 1 ) ;
30+ Assert . IsFalse ( ledger . IsInDebt ) ;
2931 }
3032
3133 [ TestMethod ]
3234 public void DebtRatio_Negative ( )
3335 {
3436 var ledger = new BitswapLedger { DataReceived = 1024 * 1024 } ;
3537 Assert . IsTrue ( ledger . DebtRatio < 1 ) ;
38+ Assert . IsTrue ( ledger . IsInDebt ) ;
3639 }
3740 }
3841}
You can’t perform that action at this time.
0 commit comments