From 6ebb9991fb92f888e8952ce246a77fb340659e39 Mon Sep 17 00:00:00 2001 From: Patrick Driscoll Date: Fri, 7 Oct 2022 10:06:08 -0700 Subject: [PATCH 1/3] BUGFIX: 3-arg subtraction was not implemented. The following change allows use of sub like ```py sub(5, 4, 1) #0 ``` --- src/calc_test.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/calc_test.py b/src/calc_test.py index 2911910..e6638c8 100644 --- a/src/calc_test.py +++ b/src/calc_test.py @@ -17,6 +17,8 @@ def test_sub_2arg(self): # Make sure 4 - 3 = 1 self.assertEqual(sub(4, 3), 1, 'subtracting three from four') + def test_sub_3arg(self): + self.assertEqual(sub(4, 3, 1), 0, 'subtracting three and one from four') if __name__ == '__main__': unittest.main() From 1794d68c5649f92b60ac7580c917a96345777793 Mon Sep 17 00:00:00 2001 From: Patrick Ryan Driscoll <9221695+prdriscoll@users.noreply.github.com> Date: Fri, 7 Oct 2022 10:24:37 -0700 Subject: [PATCH 2/3] Add support for third arg in subtraction --- src/calc.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/calc.py b/src/calc.py index 2af3c17..8f044fb 100644 --- a/src/calc.py +++ b/src/calc.py @@ -9,12 +9,13 @@ def add(a, b, third_operand = 0): """ return a + b + third_operand -def sub(a, b): +def sub(a, b, c = 0): """ Subtract some numbers ```py sub(8, 3) # 5 + sub(8, 3, 10) # -5 ``` """ - return a - b + return a - b -c From 6458d2eb94ee8d48fb1f994e899037f216a586ee Mon Sep 17 00:00:00 2001 From: Patrick Ryan Driscoll <9221695+prdriscoll@users.noreply.github.com> Date: Fri, 7 Oct 2022 10:43:40 -0700 Subject: [PATCH 3/3] Apply suggestions from code review --- src/calc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/calc.py b/src/calc.py index 8f044fb..56399d7 100644 --- a/src/calc.py +++ b/src/calc.py @@ -9,7 +9,7 @@ def add(a, b, third_operand = 0): """ return a + b + third_operand -def sub(a, b, c = 0): +def sub(a, b, x = 0): """ Subtract some numbers @@ -18,4 +18,4 @@ def sub(a, b, c = 0): sub(8, 3, 10) # -5 ``` """ - return a - b -c + return a - b - x