def test_buy_one_stock(self):
        p = Portfolio()
        p.buy("IBM", 100, 176.48)
        assert p.cost() == 17648.0


# to run this test
# python -m unittest test_port1
Пример #2
0
    def test_buy_two_stocks(self):
        p = Portfolio()
        p.buy("IBM", 100, 176.48)
        p.buy("HPQ", 100, 36.15)
        assert p.cost() == 21263.0


# to run this test
# python -m unittest test_port2
Пример #3
0
class PortfolioSellTest(unittest.TestCase):
    # The following setUp method is invoked before each test method
    def setUp(self):
        self.p = Portfolio()
        self.p.buy("MSFT", 100, 27.0)
        self.p.buy("DELL", 100, 17.0)
        self.p.buy("ORCL", 100, 34.0)
        
    def test_sell(self):
        self.p.sell("MSFT", 50)
        self.assertEqual(self.p.cost(),6450)
    
    def test_not_enough(self):
        with self.assertRaises(ValueError):
            self.p.sell("MSFT",200)
            
    def test_dont_own_it(self):
        with self.assertRaises(ValueError):
            self.p.sell("IBM",1)
 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.48)
     self.assertEqual(p.cost(), 17648.0)
Пример #6
0
 def test_bad_input(self):
     p = Portfolio()
     p.buy("IBM")
Пример #7
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)
Пример #8
0
 def test_buy_one_stock(self):
     p = Portfolio()
     p.buy("IBM", 100, 176.48)
     self.assertEqual(p.cost(), 17648.0)
 def test_bad_input(self):
     p = Portfolio()
     with self.assertRaises(TypeError):
         p.buy("IBM")
Пример #10
0
 def test_buy_one_stock(self):
     p = Portfolio()
     p.buy("IBM", 100, 176)      # this is wrong, to make the test fail!
     assert p.cost() == 17648.0
Пример #11
0
 def test_bad_input(self):
     p = Portfolio()
     with self.assertRaises(TypeError):
         p.buy("IBM")
Пример #12
0
def test_bad_input():
    p = Portfolio()
    with pytest.raises(TypeError):
        p.buy("IBM")
Пример #13
0
 def test_bad_input(self):
     p = Portfolio()
     p.buy("IBM")
Пример #14
0
 def test_buy_one_stock(self):
     p = Portfolio()
     p.buy("IBM", 100, 176.48)
     assert p.cost() == 17648.0
Пример #15
0
def test_bad_input():
    p = Portfolio()
    with pytest.raises(TypeError):
        p.buy("IBM")
Пример #16
0
 def test_buy_two_stocks(self):
     p = Portfolio()
     p.buy("IBM", 100, 176.48)
     p.buy("HPQ", 100, 36.15)
     assert p.cost() == 21263.0
Пример #17
0
# porttest3_broken.py
from portfolio1 import Portfolio

p = Portfolio()
print "Empty portfolio cost: %s, should be 0.0" % p.cost()
assert p.cost() == 0.0
p.buy("IBM", 100, 176.48)
print "With 100 IBM @ 176.48: %s, should be 17600.0" % p.cost()
assert p.cost() == 17600.0
p.buy("HPQ", 100, 36.15)
print "With 100 HPQ @ 36.15: %s, should be 21263.0" % p.cost()
assert p.cost() == 21263.0
Пример #18
0
# porttest3.py
from portfolio1 import Portfolio

p = Portfolio()
print "Empty portfolio cost: %s, should be 0.0" % p.cost()
assert p.cost() == 0.0
p.buy("IBM", 100, 176.48)
print "With 100 IBM @ 176.48: %s, should be 17648.0" % p.cost()
assert p.cost() == 17648.0
p.buy("HPQ", 100, 36.15)
print "With 100 HPQ @ 36.15: %s, should be 21263.0" % p.cost()
assert p.cost() == 21263.0
 def test_buy_one_stock(self):
     p = Portfolio()
     p.buy("IBM", 100, 176)  # this is wrong, to make the test fail!
     assert p.cost() == 17648.0