summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoruvok2025-04-13 15:29:56 +0200
committeruvok2025-04-13 15:29:56 +0200
commit0ae387a8f433defc4af797692b7d1d247ce446ec (patch)
tree820470f717aa1ac5aa80023f7206e5580c8802c6
parent87065de467bd5cfc70e2b9a1d895fda76f308758 (diff)
Better exception
-rw-r--r--bla.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/bla.py b/bla.py
index c73c234..d6fbecc 100644
--- a/bla.py
+++ b/bla.py
@@ -11,7 +11,10 @@ class FIFOQueue:
def remove(self, amount):
remaining = amount
cost_basis = 0
+
while remaining > 0:
+ if not self.queue:
+ raise ValueError(f"Insufficient assets in queue to process sale of {amount}.")
quantity, price = self.queue[0]
if quantity > remaining:
cost_basis += remaining * price
@@ -21,6 +24,7 @@ class FIFOQueue:
cost_basis += quantity * price
remaining -= quantity
self.queue.popleft()
+
return cost_basis
def process_ledger(file_path):