Skip to content

Commit

Permalink
Support three-argument subtraction (gh-training#8)
Browse files Browse the repository at this point in the history
Users have reported that 3-arg subtraction doesn't work
We forgot to implement it!
  • Loading branch information
mike-north authored Feb 18, 2021
1 parent 6a535e4 commit 39edddd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ def add(a, b):
"""
return a + b

def sub(a, b):
def sub(a, b, c = 0):
"""
Subtract some numbers
```py
sub(8, 3) # 5
```
"""
return a - b
return a - b - c
5 changes: 4 additions & 1 deletion src/calc_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ class TestStringMethods(unittest.TestCase):
def test_add_2arg(self):
# Make sure 3 + 4 = 7
self.assertEqual(add(3, 4), 7, 'adding three and four')

def test_sub_2arg(self):
# Make sure 4 - 3 = 1
self.assertEqual(sub(4, 3), 1, 'subtracting three from four')

def test_sub_3argument_variant(self):
self.assertEqual(sub(4, 3, 1), 0, 'subtracting one and three from four')

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

0 comments on commit 39edddd

Please sign in to comment.