Writing test code before refactoring
GitHub Copilot makes it incrediblly easy to modify code, but the suggested code is not always correct even if it looks good. Writing tests is very important before refactoring it. This is no different
Description
Example
def total_price(items):
return sum(item['price'] * item['quantity'] for item in items)def test_total_price():
items = [
{'price': 5, 'quantity': 2},
{'price': 3, 'quantity': 1}
]
assert total_price(items) == 13def total_price(items):
total = 0
for item in items:
total += item['price'] * item['quantity']
return totalExercise
Checklist for Further Learning
Last updated