# porttest1.py from portfolio.portfolio1 import Portfolio p = Portfolio() print(f"Empty portfolio cost: {p.cost()}") p.buy("IBM", 100, 176.48) print(f"With 100 IBM @ 176.48: {p.cost()}") p.buy("HPQ", 100, 36.15) print(f"With 100 HPQ @ 36.15: {p.cost()}")
# porttest3_broken.py from portfolio.portfolio1 import Portfolio p = Portfolio() print(f"Empty portfolio cost: {p.cost()}, should be 0.0") assert p.cost() == 0.0 p.buy("IBM", 100, 176.48) print(f"With 100 IBM @ 176.48: {p.cost()}, should be 17600.0") assert p.cost() == 17600.0 p.buy("HPQ", 100, 36.15) print(f"With 100 HPQ @ 36.15: {p.cost()}, should be 21263.0") assert p.cost() == 21263.0
def test_bad_input(): p = Portfolio() p.buy("IBM")
def test_empty(): p = Portfolio() assert p.cost() == 0.0
def test_buy_one_stock(): p = Portfolio() p.buy("IBM", 100, 176.48) assert p.cost() == 17648.0
def test_buy_two_stocks(): p = Portfolio() p.buy("IBM", 100, 176.48) p.buy("HPQ", 100, 36.15) assert p.cost() == 21263.0
def test_empty(self): p = Portfolio() self.assertEqual(p.cost(), 0.0)
def test_buy_two_stocks(self): p = Portfolio() p.buy("IBM", 100, 176.48) p.buy("HPQ", 100, 36.15) self.assertEqual(p.cost(), 21263.0)
def test_buy_one_stock(self): p = Portfolio() p.buy("IBM", 100, 176.0) self.assertEqual(p.cost(), 17648.0)
def test_buy_one_stock(): p = Portfolio() p.buy("IBM", 100, 176) # this is wrong, to make the test fail! assert p.cost() == 17648.0
def test_bad_input(): p = Portfolio() with pytest.raises(TypeError): p.buy("IBM")