~/cs2613/labs/L15parse_row, compute_cost, and update_dict so that the following tests pass.def test_cost():
d = parse_row(row)
cost = compute_cost (d)
assert cost == pytest.approx(3220.000,abs=0.00000001)
def test_d():
d = parse_row(row)
update_dict(d)
assert d == {'name': 'AA', 'shares': 75, 'price':32.2, 'date': (6, 11, 2007),
'account': 12345}
read_portfolioreport.py, and make sure they pass.def test_read():
portfolio = read_portfolio('Data/portfolio.csv')
assert portfolio == \
[('AA', 100, 32.2), ('IBM', 50, 91.1),
('CAT', 150, 83.44), ('MSFT', 200, 51.23),
('GE', 95, 40.37), ('MSFT', 50, 65.1), ('IBM', 100, 70.44)]
def test_total():
portfolio = read_portfolio('Data/portfolio.csv')
total = 0.0
for name, shares, price in portfolio:
total += shares*price
assert total == pytest.approx(44671.15,abs=0.001)
report2.py
Embed the following tests in report2.py, and make sure they pass.def test_read():
portfolio = read_portfolio('Data/portfolio.csv')
assert portfolio == \
[{'name': 'AA', 'shares': 100, 'price': 32.2}, {'name': 'IBM', 'shares': 50, 'price': 91.1},
{'name': 'CAT', 'shares': 150, 'price': 83.44}, {'name': 'MSFT', 'shares': 200, 'price': 51.23},
{'name': 'GE', 'shares': 95, 'price': 40.37}, {'name': 'MSFT', 'shares': 50, 'price': 65.1},
{'name': 'IBM', 'shares': 100, 'price': 70.44}]
def test_total():
portfolio = read_portfolio('Data/portfolio.csv')
total = 0.0
for s in portfolio:
total += s['shares']*s['price']
assert total == pytest.approx(44671.15,abs=0.001)
Exercise 2.13,2.14 Convert the given REPL examples to pytest tests. Use the same trick of converting prints to list appends we discussed in L15
Exercise 2.17. Build a script embedding tests as directed below.
list() to fix the following testdef test_items():
assert prices.items() == \
[('GOOG', 490.1), ('AA', 23.45), ('IBM', 91.1), ('MSFT', 34.23)]
- Question for your journal: what is `list()` being used for in this section?
- Embed the following tests and make sure they pass
def test_zip():
assert pricelist == \
[(490.1, 'GOOG'), (23.45, 'AA'), (91.1, 'IBM'), (34.23, 'MSFT')]
def test_min_max():
assert min(pricelist) == (23.45, 'AA')
assert max(pricelist) == (490.1, 'GOOG')