From 451a3785a221ad9e988048fe28cd4f7c7ee8efa3 Mon Sep 17 00:00:00 2001 From: Giles Gaskell Date: Tue, 28 Nov 2017 17:30:45 +1100 Subject: [PATCH] Add Python source files * And update .gitignore --- .DS_Store | Bin 6148 -> 0 bytes .gitignore | 1 + sources/calc.py | 5 +++++ sources/test_calc.py | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+) delete mode 100644 .DS_Store create mode 100644 sources/calc.py create mode 100644 sources/test_calc.py diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 963ba9d4ba24be2f83614f3307ce1964131d7fc6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKOHRW;4E3}{6v3iPmUD%2f}sj0=mkIt;!{E@HQna`?AdTG?!bl>2jF>Zm4umY zQH5;Dev`31PF|!qCL*`kR&$~m5lx|tqZ62nu%9)Nk?x!U9iK5@mQB4*;%wt^8Q^y} zrW>lLdb&&ApL*)1D5`B+61`uRuOIDCPTf>{JnQ@9v}1atTY9DyJ-}`<^?pSR>b_k} zP&bL_)z3y`?&FAB+{XqscMm=9p#Im(C+ZKpz1oR4Qy1wb#(*(k3>*Xl=-DjOQ$e%F zfH7bU>=@whgNHH(#ZEAOI$+`m0OVh@C|L6>!8u+rD0YJIK%ArkCDrMO;UpdVUgLsd zCn)LUbog*u+3AGhVs)JFV>r1WXx11o28Ilb<#NXT|7!pIKTNVKW55{rR}8pGu`CvN zB<-!q!*Q?m&}%3Q$900c6f9yZMl84Db7&OodtLy8Vkd|li2Vpe8q632f6Bl&UISiX diff --git a/.gitignore b/.gitignore index 113294a..0bb8ddd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.DS_store # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/sources/calc.py b/sources/calc.py new file mode 100644 index 0000000..d1cbd6c --- /dev/null +++ b/sources/calc.py @@ -0,0 +1,5 @@ +''' +A simple addition function. +''' +def add(a, b): + return a + b diff --git a/sources/test_calc.py b/sources/test_calc.py new file mode 100644 index 0000000..02f41f8 --- /dev/null +++ b/sources/test_calc.py @@ -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()