Add Python source files

* And update .gitignore
This commit is contained in:
Giles Gaskell
2017-11-28 17:30:45 +11:00
parent cdf9589681
commit 451a3785a2
4 changed files with 39 additions and 0 deletions

BIN
.DS_Store vendored

Binary file not shown.

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
.DS_store
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

5
sources/calc.py Normal file
View File

@@ -0,0 +1,5 @@
'''
A simple addition function.
'''
def add(a, b):
return a + b

33
sources/test_calc.py Normal file
View 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()