From f2aa4660161fd334cf2432655bbdf3f521f03786 Mon Sep 17 00:00:00 2001 From: Shuzhe Xiao Date: Mon, 1 Aug 2022 17:14:19 -0700 Subject: [PATCH 1/2] BUGFIX: 3-arg subtraction was not implemented The following change allows use of sub --- src/calc_test.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/calc_test.py b/src/calc_test.py index 2911910..8d09609 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 2968bef488824c3e55701276c21090aeef4a3ea8 Mon Sep 17 00:00:00 2001 From: Shuzhe Xiao Date: Mon, 1 Aug 2022 17:31:15 -0700 Subject: [PATCH 2/2] Add support for third argument in subtraction --- src/calc.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/calc.py b/src/calc.py index 2af3c17..2704b2d 100644 --- a/src/calc.py +++ b/src/calc.py @@ -9,12 +9,12 @@ 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