Skip to content

Commit

Permalink
#111 TradeRoutines: unit-tests were added for `CalculateLotsForDeal()…
Browse files Browse the repository at this point in the history
…` method
  • Loading branch information
Tim55667757 committed Dec 7, 2022
1 parent 82e3339 commit 345938e
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/test_TradeRoutines.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,30 @@ def test_SeparateByEqualPartsNegative(self):

for test in testData:
assert TradeRoutines.SeparateByEqualParts(elements=test[0], parts=test[1], union=test[2]) == test[3], "Incorrect output!"

def test_CalculateLotsForDealCheckType(self):
assert isinstance(TradeRoutines.CalculateLotsForDeal(currentPrice=0, maxCost=0, volumeInLot=0), int), "Not int type returned!"

def test_CalculateLotsForDealPositive(self):
testData = [
(1, 1, 1, 1), (2, 1, 1, 1), (2, 1, 2, 1), (1, 2, 1, 2), (3, 2, 1, 1), (3, 2, 3, 1),
(1234.56, 2000.01, 1, 1), (1234.56, 2000.01, 2, 1), (1234.56, 2500, 1, 2), (1234.56, 2500, 2, 1),
(1234, 2468, 1, 2), (1234, 2468, 2, 1),
(-1, 1, 1, 1), (-2, 1, 1, 1), (-2, 1, 2, 1), (-1, 2, 1, 2), (-3, 2, 1, 1), (-3, 2, 3, 1),
(-1234.56, 2000.01, 1, 1), (-1234.56, 2000.01, 2, 1), (-1234.56, 2500, 1, 2), (-1234.56, 2500, 2, 1),
(-1234, -2468, 1, 2), (-1234, 2468, 2, 1),
]

for test in testData:
assert TradeRoutines.CalculateLotsForDeal(currentPrice=test[0], maxCost=test[1], volumeInLot=test[2]) == test[3], "Incorrect output!"

def test_CalculateLotsForDealNegative(self):

testData = [
(0, 0, 0, 0), (0, 1, 0, 0), (-2, 0, 1, 1), (1, 0, 1, 1), (-1, -2, -1, 2), (-3, -2, -1, 1), (-3, 2, -3, 1),
("1234.56", 2000.01, 1, 0), (1234.56, "2000.01", 2, 0), (1234.56, 2500, "1", 0),
(1234.56, 2500, [], 0), (1234, {}, 1, 0), (None, 2468, 2, 0), (bool, 2468, 2, 0),
]

for test in testData:
assert TradeRoutines.CalculateLotsForDeal(currentPrice=test[0], maxCost=test[1], volumeInLot=test[2]) == test[3], "Incorrect output!"

0 comments on commit 345938e

Please # to comment.