Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ def multiply(self, a, b):

def divide(self, a, b):
"""Return the division of a by b.

Raises:
ValueError: If b is zero.
"""
if b == 0:
raise ValueError("Cannot divide by zero")
return a / b

def power_of(self, input, power):
return input ** power
4 changes: 4 additions & 0 deletions test_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,9 @@ def test_divide_by_zero(self):
with self.assertRaises(ValueError):
self.calc.divide(10, 0)

def test_power_of (self):
"""Test that dividing by zero raises a ValueError."""
self.assertEqual(self.calc.power_of(3, 2), 10)

if __name__ == '__main__':
unittest.main()