Skip to content

Commit 451a378

Browse files
committed
Add Python source files
* And update .gitignore
1 parent cdf9589 commit 451a378

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

.DS_Store

-6 KB
Binary file not shown.

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.DS_store
12
# Byte-compiled / optimized / DLL files
23
__pycache__/
34
*.py[cod]

sources/calc.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'''
2+
A simple addition function.
3+
'''
4+
def add(a, b):
5+
return a + b

sources/test_calc.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import calc
2+
import unittest
3+
4+
class TestAdd(unittest.TestCase):
5+
"""
6+
Test the add function from the calc library
7+
"""
8+
9+
def test_add_integers(self):
10+
"""
11+
Test that the addition of two integers returns the correct total
12+
"""
13+
result = calc.add(1, 2)
14+
self.assertEqual(result, 3)
15+
16+
def test_add_floats(self):
17+
"""
18+
Test that the addition of two floats returns the correct result
19+
"""
20+
result = calc.add(10.5, 2)
21+
self.assertEqual(result, 12.5)
22+
23+
def test_add_strings(self):
24+
"""
25+
Test the addition of two strings returns the two string as one
26+
concatenated string
27+
"""
28+
result = calc.add('abc', 'def')
29+
self.assertEqual(result, 'abcdef')
30+
31+
32+
if __name__ == '__main__':
33+
unittest.main()

0 commit comments

Comments
 (0)