Skip to content

Commit 12fb86c

Browse files
authored
Refactor addition function and add unit tests
1 parent 1be1dbe commit 12fb86c

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

test_add.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
# sum of numbers
2-
def addition(a,b):
3-
return a+b
4-
def test_addition_basic(a,b):
5-
assert addition(2,3)==5
6-
assert addition(-1,1)==0
7-
assert addition(0,0)==0
8-
if __name__=="__main__":
9-
print(addition(2,3))
2+
def addition(a, b):
3+
"""Return the sum of a and b."""
4+
return a + b
5+
6+
import unittest
7+
8+
class TestAddition(unittest.TestCase):
9+
def test_basic(self):
10+
self.assertEqual(addition(2, 3), 5)
11+
self.assertEqual(addition(-1, 1), 0)
12+
self.assertEqual(addition(0, 0), 0)
13+
14+
if __name__ == "__main__":
15+
# Run the tests
16+
unittest.main()
17+
1018

1119

1220

0 commit comments

Comments
 (0)