summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test_trade_queue.py35
-rw-r--r--trade_queue.py6
2 files changed, 41 insertions, 0 deletions
diff --git a/test_trade_queue.py b/test_trade_queue.py
index 958b830..3a72e4a 100644
--- a/test_trade_queue.py
+++ b/test_trade_queue.py
@@ -63,5 +63,40 @@ class TestFIFOQueue(unittest.TestCase):
with self.assertRaises(ValueError):
self.queue.remove(-5.0) # This should raise an exception
+ def test_get_remaining_amount_initial(self):
+ """
+ Test the remaining amount in the queue after adding trades.
+ """
+ self.assertEqual(self.queue.get_remaining_amount(), 60.0) # Total of all amounts: 10 + 20 + 30
+
+ def test_get_remaining_amount_after_removal(self):
+ """
+ Test the remaining amount after removing some assets.
+ """
+ self.queue.remove(15.0) # Remove 15 assets
+ self.assertEqual(self.queue.get_remaining_amount(), 45.0) # Remaining: 60 - 15
+
+ def test_get_remaining_amount_empty_queue(self):
+ """
+ Test the remaining amount in an empty queue.
+ """
+ empty_queue = FIFOQueue() # New empty queue
+ self.assertEqual(empty_queue.get_remaining_amount(), 0.0) # No trades in queue
+
+ def test_get_remaining_amount_partial_removal(self):
+ """
+ Test the remaining amount after partially consuming a trade.
+ """
+ self.queue.remove(5.0) # Remove 5 assets, leaving 5 in the first trade
+ self.assertEqual(self.queue.get_remaining_amount(), 55.0) # Remaining: 60 - 5
+
+ def test_get_remaining_amount_full_removal(self):
+ """
+ Test the remaining amount after removing all trades.
+ """
+ self.queue.remove(60.0) # Remove all assets
+ self.assertEqual(self.queue.get_remaining_amount(), 0.0) # Remaining: 0
+
+
if __name__ == "__main__":
unittest.main()
diff --git a/trade_queue.py b/trade_queue.py
index b8c594b..4dabc4d 100644
--- a/trade_queue.py
+++ b/trade_queue.py
@@ -46,3 +46,9 @@ class FIFOQueue:
self.queue.popleft()
return entries
+
+ def get_remaining_amount(self) -> float:
+ """
+ Calculate the total remaining amount in the queue.
+ """
+ return sum(trade.amount for trade in self.queue)