diff --git a/printNumbers/functions/__pycache__/__init__.cpython-38.pyc b/printNumbers/functions/__pycache__/__init__.cpython-38.pyc new file mode 100644 index 0000000..64a9d4c Binary files /dev/null and b/printNumbers/functions/__pycache__/__init__.cpython-38.pyc differ diff --git a/printNumbers/functions/__pycache__/fibonacci.cpython-38.pyc b/printNumbers/functions/__pycache__/fibonacci.cpython-38.pyc new file mode 100644 index 0000000..f718957 Binary files /dev/null and b/printNumbers/functions/__pycache__/fibonacci.cpython-38.pyc differ diff --git a/printNumbers/functions/__pycache__/sumN.cpython-38.pyc b/printNumbers/functions/__pycache__/sumN.cpython-38.pyc new file mode 100644 index 0000000..811fb62 Binary files /dev/null and b/printNumbers/functions/__pycache__/sumN.cpython-38.pyc differ diff --git a/printNumbers/functions/sumN.py b/printNumbers/functions/sumN.py new file mode 100755 index 0000000..c940fe3 --- /dev/null +++ b/printNumbers/functions/sumN.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# +# sumN.py +# +# This file is part of printNumbers. +# +# Copyright (C) 2017 G. Trensch, Simulation & Datalab Neuroscience, JSC, FZ Juelich +# +# printNumbers is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# printNumbers is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with printNumbers. If not, see . + +import numpy as np + +def sumN(n): + ''' + :param n: Operand + :return: sum from 1 to n + ''' + return(np.sum(range(0,n+1))) diff --git a/printNumbers/unittests/test_sumN.py b/printNumbers/unittests/test_sumN.py new file mode 100755 index 0000000..6470121 --- /dev/null +++ b/printNumbers/unittests/test_sumN.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# +# test_sumN.py +# +# This file is part of PrintNumbers. +# +# Copyright (C) 2017 G. Trensch, Simulation & Datalab Neuroscience, JSC, FZ Juelich +# +# PrintNumbers is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# PrintNumbers is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with PrintNumbers. If not, see . + +# +# Unit tests: 'sumN'. +# + +import sys, os +sys.path.append(os.path.join(os.path.dirname(__file__), '..')) + +import unittest +from functions.sumN import * + +class TestsumN(unittest.TestCase): + + def test_value_1(self): + self.assertEqual(sumN(1), [1] ) + + def test_value_5(self): + self.assertEqual(sumN(5), [15]) + + def test_value_3(self): + self.assertEqual(sumN(3), [6]) + + +def suite(): + suite = unittest.makeSuite(TestsumN, 'test') + return suite + +def run(): + runner = unittest.TextTestRunner(verbosity = 2) + runner.run(suite()) + +if __name__ == "__main__": + run()