Skip to content

Commit

Permalink
test(holding): fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Caceresenzo committed Jun 4, 2024
1 parent adb32e4 commit cf4e663
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions tests/test_holdings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,30 @@
class HoldingTest(unittest.TestCase):

def test_market_price(self):
holding = bktest.Holding("AAPL", 15, 2)
holding = bktest.Holding("AAPL", 15, 2, None)

self.assertEqual(15*2, holding.market_price)
self.assertEqual(15 * 2, holding.market_price)

def test_merge(self):
holding = bktest.Holding("AAPL", 15, 2, False)
order = bktest.Order("AAPL", 30, 4)
holding = bktest.Holding("AAPL", 15, 2, 15 * 2, False)
order = bktest.Order("AAPL", 30, 4, 30 * 4)

expected_quantity = holding.quantity + order.quantity

expected_value = holding.value + order._value

holding.merge(order)

self.assertEqual(expected_quantity, holding.quantity)
self.assertEqual(expected_value, holding.value)
self.assertEqual(order.price, holding.price)
self.assertTrue(holding.up_to_date)

def test_str(self):
holding = bktest.Holding("AAPL", 15, 2, None)

self.assertEqual(str(holding), "AAPLx15@2")

def test_repr(self):
holding = bktest.Holding("AAPL", 15, 2, None)

self.assertEqual(repr(holding), "AAPLx15")

0 comments on commit cf4e663

Please sign in to comment.