From cfa4ca4c5f9516b942f956e21be43ba9b3617005 Mon Sep 17 00:00:00 2001 From: Jose Robledo Date: Thu, 17 Nov 2022 12:14:55 +0100 Subject: [PATCH 1/2] added function --- printNumbers/functions/sumN.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 printNumbers/functions/sumN.py 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))) From 1047c19e3352c16644c0f65ca2442400891a63ba Mon Sep 17 00:00:00 2001 From: Jose Robledo Date: Thu, 17 Nov 2022 12:21:41 +0100 Subject: [PATCH 2/2] first tests sumN --- .../__pycache__/__init__.cpython-38.pyc | Bin 0 -> 182 bytes .../__pycache__/fibonacci.cpython-38.pyc | Bin 0 -> 655 bytes .../functions/__pycache__/sumN.cpython-38.pyc | Bin 0 -> 398 bytes printNumbers/unittests/test_sumN.py | 53 ++++++++++++++++++ 4 files changed, 53 insertions(+) create mode 100644 printNumbers/functions/__pycache__/__init__.cpython-38.pyc create mode 100644 printNumbers/functions/__pycache__/fibonacci.cpython-38.pyc create mode 100644 printNumbers/functions/__pycache__/sumN.cpython-38.pyc create mode 100755 printNumbers/unittests/test_sumN.py diff --git a/printNumbers/functions/__pycache__/__init__.cpython-38.pyc b/printNumbers/functions/__pycache__/__init__.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..64a9d4cb22ef6d07887054925c96549c23994efd GIT binary patch literal 182 zcmWIL<>g`k0`vVv$%@Pj439w^WWWgIH~?`m3y?@*2xib^^jpbL1QJFNzoPXs@^e%5 zv+|4blX6m1^7RWUOEU8F^n>%$O3D+9Qe9HZJoAE+GgI@DQ}qjqGV@CON^_G^i;DG2 z^D;|HQj1H9_4V}h(@OJ_OEUBGiuL2;Gl3HE@p=W7w>WHa^HWN5Qtd#Neg^ZsJqtMYmpTLYeRxlT;UABUdMLxSrxQvM>Ils5b z$zI~3LBr>*s$8vA9>6Qld*z3jX3%fHsApQ0RaL*isx_9{2nF?nnGv=8{vb~D62(Vt z^lX7ri{{LoXeA0gcV9|_hxqxGDykY)g`zRFa?^G>Lt{m&YUj{8EAm{dN3dePJ}+<1 zOiV}IA-5Y8Sdu~#1?)c^e3PFg= zuK*p2~P>`J%Rt>$yh;Rk#|~neg`yC;U-(9#43l z=lm$}WN|+t(qrs5%BDdj!va}s{MGfT#naYn(?cBu9fDuCzx_}8;&0P^f^ABHjS?8c hEigAJpJsz7p}0okH8FuHJy>elF7Rp4(qCEM40UoXluF$YWz2d@Bi4ct5-cobs1Q=O>m{X!nh*Jsq9P;)_#v<$@t1C8 z>R({OIT-pRzu10uocMMy=mX(pxGq04fbSISf>UroRv!{6P;3P=rnt)9V8#`jLf+Yu z0+W)Z;~&Z2BfBJPI|ID4K=sd{_z+(CN9xR;PWyr|_5~J3*s%~dUSna^UmA6Yn6jdd zMl8@7aUy~fwv{mr*(S=fhFjlcRMm8;{a)v+VfG7fpVXf_xpYR$2ZwIH(#lD{2}@_? z)Gfkef%;0XukEy~v@NytSlKX%X0EZ8(N-boI@EGBl8b1|P&r#mnll;sP18xvar$D~ n5_Iu^IL~HX8;#!}trOZ*`-~mxk. + +# +# 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()