Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added printNumbers/__pycache__/docopt.cpython-39.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
31 changes: 31 additions & 0 deletions printNumbers/functions/gamma.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
#
# gamma.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 <http://www.gnu.org/licenses/>.

import math

def Gamma(n):
'''
:param n: Operand
:return: Gamma(n)=(n-1)!
'''
return(math.gamma(n))

#To check if the comment shows up later
5 changes: 4 additions & 1 deletion printNumbers/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
CONST_VERSION = 'V1.0'
CONST_VERSION_STRING = '+ + PrintNumbers ' + CONST_VERSION + ' (Software Development in Science) + +'
CONST_DEF_OPERAND_VAL = 10
CONST_MAX_OPERAND_VAL = 20
CONST_MAX_OPERAND_VAL = 22
CONST_FUNC_CODE_FIBONACCI = 0
CONST_FUNC_CODE_FACTORIAL = 1
CONST_FUNC_CODE_GAMMA = 2

class Parameters(object):

Expand All @@ -43,6 +44,8 @@ def __setParameters(self, cmdLineArgs):
self.functionIndex = CONST_FUNC_CODE_FIBONACCI
elif cmdLineArgs['--factorial']:
self.functionIndex = CONST_FUNC_CODE_FACTORIAL
elif cmdLineArgs['--gamma']:
self.functionIndex = CONST_FUNC_CODE_GAMMA

@property
def operand(self):
Expand Down
7 changes: 6 additions & 1 deletion printNumbers/printNumbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,27 @@
"""
Usage:
printNumbers.py -h --help
printNumbers.py [--fibonacci|--factorial] <operand>
printNumbers.py [--fibonacci|--factorial|--gamma] <operand>

Options:
-h --help Print usage.
--fibonacci Print the fibonacci sequence.
--factorial Print the factorial.
--gamma Print the Gamma function.
"""

from docopt import docopt
from parameters import *
from functions.fibonacci import *
from functions.factorial import *
from functions.gamma import *

#
# FUNCTION TABLE
#
functionTable = { CONST_FUNC_CODE_FIBONACCI : FibonacciSequence,
CONST_FUNC_CODE_FACTORIAL : Factorial,
CONST_FUNC_CODE_GAMMA : Gamma
}

#
Expand All @@ -67,3 +70,5 @@
print('fib(' + str(params.operand) + ') =', result)
elif params.functionIndex == CONST_FUNC_CODE_FACTORIAL:
print(str(params.operand) + '! =', str(result))
elif params.functionIndex == CONST_FUNC_CODE_GAMMA:
print('Gamma(' + str(params.operand) + ') = ', result)
5 changes: 4 additions & 1 deletion printNumbers/unittests/test_factorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ def test_value_2(self):

def test_value_20(self):
self.assertEqual(Factorial(20), 2432902008176640000)


def test_jane(self):
self.assertEqual(Factorial(5),3)

def suite():
suite = unittest.makeSuite(TestFactorial, 'test')
Expand All @@ -54,3 +56,4 @@ def run():

if __name__ == "__main__":
run()

53 changes: 53 additions & 0 deletions printNumbers/unittests/test_gamma.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# -*- coding: utf-8 -*-
#
# test_gamma.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 <http://www.gnu.org/licenses/>.

#
# Unit tests: 'gamma'.
#

import sys, os
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

import unittest
from functions.gamma import *

class TestGamma(unittest.TestCase):

def test_value_1(self):
self.assertEqual(Gamma(1), 1)

def test_value_2(self):
self.assertEqual(Gamma(2), 1)

def test_value_21(self):
self.assertEqual(Gamma(21), 2432902008176640000)


def suite():
suite = unittest.makeSuite(TestGamma, 'test')
return suite

def run():
runner = unittest.TextTestRunner(verbosity = 2)
runner.run(suite())

if __name__ == "__main__":
run()