Add Python source files
* And update .gitignore
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
.DS_store
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
|
5
sources/calc.py
Normal file
5
sources/calc.py
Normal file
@@ -0,0 +1,5 @@
|
||||
'''
|
||||
A simple addition function.
|
||||
'''
|
||||
def add(a, b):
|
||||
return a + b
|
33
sources/test_calc.py
Normal file
33
sources/test_calc.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import calc
|
||||
import unittest
|
||||
|
||||
class TestAdd(unittest.TestCase):
|
||||
"""
|
||||
Test the add function from the calc library
|
||||
"""
|
||||
|
||||
def test_add_integers(self):
|
||||
"""
|
||||
Test that the addition of two integers returns the correct total
|
||||
"""
|
||||
result = calc.add(1, 2)
|
||||
self.assertEqual(result, 3)
|
||||
|
||||
def test_add_floats(self):
|
||||
"""
|
||||
Test that the addition of two floats returns the correct result
|
||||
"""
|
||||
result = calc.add(10.5, 2)
|
||||
self.assertEqual(result, 12.5)
|
||||
|
||||
def test_add_strings(self):
|
||||
"""
|
||||
Test the addition of two strings returns the two string as one
|
||||
concatenated string
|
||||
"""
|
||||
result = calc.add('abc', 'def')
|
||||
self.assertEqual(result, 'abcdef')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Reference in New Issue
Block a user