summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test_trade_queue.py75
1 files changed, 50 insertions, 25 deletions
diff --git a/test_trade_queue.py b/test_trade_queue.py
index 9ce0410..0aaae65 100644
--- a/test_trade_queue.py
+++ b/test_trade_queue.py
@@ -22,56 +22,69 @@ class TestFIFOQueue(unittest.TestCase):
Test adding trades to the queue.
"""
tq = self.queue.get_copy()
- self.assertEqual(len(tq), 3) # There should be 3 trades in the queue
- self.assertEqual(tq[0].amount, 10.0) # Check the first trade's amount
- self.assertEqual(tq[1].date, "2025-04-15") # Check the second trade's date
+ # There should be 3 trades in the queue
+ self.assertEqual(len(tq), 3)
+ # Check the first trade's amount
+ self.assertEqual(tq[0].amount, 10.0)
+ # Check the second trade's date
+ self.assertEqual(tq[1].date, "2025-04-15")
def test_remove_exact_amount(self):
"""
Test removing an exact amount from the queue.
"""
trades = self.queue.remove_coins(10.0)
- self.assertEqual(len(trades), 1) # One trade should be returned
- self.assertEqual(trades[0].amount, 10.0) # Amount should match the request
+ # One trade should be returned
+ self.assertEqual(len(trades), 1)
+ # Amount should match the request
+ self.assertEqual(trades[0].amount, 10.0)
tq = self.queue.get_copy()
- self.assertEqual(len(tq), 2) # Two trades should remain in the queue
+ # Two trades should remain in the queue
+ self.assertEqual(len(tq), 2)
def test_remove_partial_trade(self):
"""
Test removing an amount that partially consumes a trade.
"""
trades = self.queue.remove_coins(5.0)
- self.assertEqual(len(trades), 1) # One partial trade should be returned
- self.assertEqual(trades[0].amount, 5.0) # Amount should match the request
+ # One partial trade should be returned
+ self.assertEqual(len(trades), 1)
+ # Amount should match the request
+ self.assertEqual(trades[0].amount, 5.0)
tq = self.queue.get_copy()
- self.assertEqual(tq[0].amount, 5.0) # Remaining trade amount should update
+ # Remaining trade amount should update
+ self.assertEqual(tq[0].amount, 5.0)
def test_remove_multiple_trades(self):
"""
Test removing an amount that spans multiple trades.
"""
trades = self.queue.remove_coins(25.0)
- self.assertEqual(len(trades), 2) # Two trades should be returned
+ # Two trades should be returned
+ self.assertEqual(len(trades), 2)
# The first trade should be fully consumed
self.assertEqual(trades[0].amount, 10.0)
# The second trade should be partially consumed
self.assertEqual(trades[1].amount, 15.0)
tq = self.queue.get_copy()
- self.assertEqual(tq[0].amount, 5.0) # Remaining trade in queue should update
+ # Remaining trade in queue should update
+ self.assertEqual(tq[0].amount, 5.0)
def test_remove_insufficient_amount(self):
"""
Test trying to remove more than is available in the queue.
"""
+ # This should raise an exception
with self.assertRaises(ValueError):
- self.queue.remove_coins(100.0) # This should raise an exception
+ self.queue.remove_coins(100.0)
def test_remove_negative_amount(self):
"""
Test trying to remove a negative amount.
"""
+ # This should raise an exception
with self.assertRaises(ValueError):
- self.queue.remove_coins(-5.0) # This should raise an exception
+ self.queue.remove_coins(-5.0)
def test_get_remaining_amount_initial(self):
"""
@@ -84,7 +97,8 @@ class TestFIFOQueue(unittest.TestCase):
"""
Test the remaining amount after removing some assets.
"""
- self.queue.remove_coins(15.0) # Remove 15 assets
+ # Remove 15 assets
+ self.queue.remove_coins(15.0)
# Remaining: 60 - 15
self.assertEqual(self.queue.get_remaining_amount(), 45.0)
@@ -92,33 +106,42 @@ class TestFIFOQueue(unittest.TestCase):
"""
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
+ # New empty queue
+ empty_queue = FIFOQueue()
+ # No trades in queue
+ self.assertEqual(empty_queue.get_remaining_amount(), 0.0)
def test_get_remaining_amount_partial_removal(self):
"""
Test the remaining amount after partially consuming a trade.
"""
- self.queue.remove_coins(5.0) # Remove 5 assets, leaving 5 in the first trade
- self.assertEqual(self.queue.get_remaining_amount(), 55.0) # Remaining: 60 - 5
+ # Remove 5 assets, leaving 5 in the first trade
+ self.queue.remove_coins(5.0)
+ # Remaining: 60 - 5
+ self.assertEqual(self.queue.get_remaining_amount(), 55.0)
def test_get_remaining_amount_full_removal(self):
"""
Test the remaining amount after removing all trades.
"""
- self.queue.remove_coins(60.0) # Remove all assets
- self.assertEqual(self.queue.get_remaining_amount(), 0.0) # Remaining: 0
+ # Remove all assets
+ self.queue.remove_coins(60.0)
+ # Remaining: 0
+ self.assertEqual(self.queue.get_remaining_amount(), 0.0)
def test_remove_partial_trade_correct_cost(self):
"""
Test removing a partial trade and ensure the correct cost is calculated.
"""
- trades = self.queue.remove_coins(4.0) # Remove 4 COIN from the first trade
- self.assertEqual(len(trades), 1) # Only one trade should be returned
+ # Remove 4 COIN from the first trade
+ trades = self.queue.remove_coins(4.0)
+ # Only one trade should be returned
+ self.assertEqual(len(trades), 1)
# Coin-cost needs to stay constant
self.assertEqual(trades[0].price_per_coin, 10)
- self.assertEqual(trades[0].amount, 4.0) # Check the removed amount
+ # Check the removed amount
+ self.assertEqual(trades[0].amount, 4.0)
# Total cost should be proportional: (100 * 5 / 10)
self.assertEqual(trades[0].total_cost, 40.0)
@@ -205,8 +228,10 @@ class TestFIFOQueueMatchTrades(unittest.TestCase):
matches = self.fifo_queue.match_trades()
self.assertEqual(len(matches), 1)
- self.assertEqual(matches[0][0].amount, Decimal(5)) # Buy trade amount
- self.assertEqual(matches[0][1].amount, Decimal(5)) # Sell trade amount
+ # Buy trade amount
+ self.assertEqual(matches[0][0].amount, Decimal(5))
+ # Sell trade amount
+ self.assertEqual(matches[0][1].amount, Decimal(5))
def test_error_single_buy_trade_invalid_order(self):
"""Test if a trade match fails if sell date is before buy date."""