From 1271e8c32412a8f94d85fcf6e726660cb13284a3 Mon Sep 17 00:00:00 2001
From: PhilipCarlsson <75789974+PhilipCarlsson@users.noreply.github.com>
Date: Thu, 17 Nov 2022 12:53:17 +0100
Subject: [PATCH 1/5] Add files via upload
---
printNumbers/unittests/runTestSuite.py | 2 +
printNumbers/unittests/test_square.py | 56 ++++++++++++++++++++++++++
2 files changed, 58 insertions(+)
create mode 100644 printNumbers/unittests/test_square.py
diff --git a/printNumbers/unittests/runTestSuite.py b/printNumbers/unittests/runTestSuite.py
index f3dca23..c375a8b 100755
--- a/printNumbers/unittests/runTestSuite.py
+++ b/printNumbers/unittests/runTestSuite.py
@@ -27,6 +27,7 @@
import test_factorial
import test_fibonacci
+import test_square
def suite():
@@ -34,6 +35,7 @@ def suite():
suite.addTest(test_factorial.suite())
suite.addTest(test_fibonacci.suite())
+ suite.addTest(test_square.suite())
return suite
diff --git a/printNumbers/unittests/test_square.py b/printNumbers/unittests/test_square.py
new file mode 100644
index 0000000..b1b4c88
--- /dev/null
+++ b/printNumbers/unittests/test_square.py
@@ -0,0 +1,56 @@
+# -*- coding: utf-8 -*-
+#
+# test_square.py
+#
+# This file is part of PrintNumbers.
+#
+# Copyright (C) 2022 P. Carlsson, IEK8, 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: 'square'.
+#
+
+import sys, os
+sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
+
+import unittest
+from functions.square import *
+
+class TestSquare(unittest.TestCase):
+
+ def test_value_0(self):
+ self.assertEqual(Square(0), 0)
+
+ def test_value_1(self):
+ self.assertEqual(Square(1), 1)
+
+ def test_value_2(self):
+ self.assertEqual(Square(2), 4)
+
+ def test_value_20(self):
+ self.assertEqual(Square(20), 400)
+
+
+def suite():
+ suite = unittest.makeSuite(TestSquare, 'test')
+ return suite
+
+def run():
+ runner = unittest.TextTestRunner(verbosity = 2)
+ runner.run(suite())
+
+if __name__ == "__main__":
+ run()
From 221f19c3c33d7b90be76fe78f2790ce54a4cc97b Mon Sep 17 00:00:00 2001
From: PhilipCarlsson <75789974+PhilipCarlsson@users.noreply.github.com>
Date: Thu, 17 Nov 2022 12:53:53 +0100
Subject: [PATCH 2/5] Add files via upload
---
printNumbers/functions/parameters.py | 76 ++++++++++++++++++++++++++
printNumbers/functions/printNumbers.py | 76 ++++++++++++++++++++++++++
printNumbers/functions/square.py | 28 ++++++++++
3 files changed, 180 insertions(+)
create mode 100644 printNumbers/functions/parameters.py
create mode 100644 printNumbers/functions/printNumbers.py
create mode 100644 printNumbers/functions/square.py
diff --git a/printNumbers/functions/parameters.py b/printNumbers/functions/parameters.py
new file mode 100644
index 0000000..54a7b8b
--- /dev/null
+++ b/printNumbers/functions/parameters.py
@@ -0,0 +1,76 @@
+# -*- coding: utf-8 -*-
+#
+# parameters.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 .
+
+#
+# Class to process and store program parameters.
+#
+
+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_FUNC_CODE_FIBONACCI = 0
+CONST_FUNC_CODE_FACTORIAL = 1
+CONST_FUNC_CODE_SQUARE = 2
+
+class Parameters(object):
+
+ def __init__(self, cmdLineArgs):
+ self.operand = CONST_DEF_OPERAND_VAL
+ self.functionIndex = CONST_FUNC_CODE_FIBONACCI
+ self.__setParameters(cmdLineArgs)
+
+ def __setParameters(self, cmdLineArgs):
+ self.operand = (int(cmdLineArgs['']))
+ if cmdLineArgs['--fibonacci']:
+ self.functionIndex = CONST_FUNC_CODE_FIBONACCI
+ elif cmdLineArgs['--factorial']:
+ self.functionIndex = CONST_FUNC_CODE_FACTORIAL
+ elif cmdLineArgs['--square']:
+ self.functionIndex = CONST_FUNC_CODE_SQUARE
+
+ @property
+ def operand(self):
+ return(self.__operand)
+
+ @operand.setter
+ def operand(self, n):
+ if n <= 0 or n > CONST_MAX_OPERAND_VAL:
+ print('Error: Operand out of range: 0 < <=', CONST_MAX_OPERAND_VAL)
+ print(' The default value ( n =', CONST_DEF_OPERAND_VAL, ') is used.')
+ print('')
+ n = CONST_DEF_OPERAND_VAL
+ self.__operand = n
+
+ @property
+ def functionIndex(self):
+ return(self.__functionIndex)
+
+ @functionIndex.setter
+ def functionIndex(self, value):
+ self.__functionIndex = value
+
+ def PrintParameters(self):
+ print('Following Parameters are in use:')
+ print('--------------------------------')
+ print('Function Code: ', self.functionIndex)
+ print('Operand value: ' + str(self.operand))
+ print('')
diff --git a/printNumbers/functions/printNumbers.py b/printNumbers/functions/printNumbers.py
new file mode 100644
index 0000000..18cfe1b
--- /dev/null
+++ b/printNumbers/functions/printNumbers.py
@@ -0,0 +1,76 @@
+#! /bin/env python
+# -*- coding: utf-8 -*-
+#
+# printNumbers.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 .
+
+#
+# Software Development in Science Workshop
+# Python GitHub project example
+#
+
+"""
+Usage:
+ printNumbers.py -h --help
+ printNumbers.py [--fibonacci|--factorial|--square]
+
+Options:
+ -h --help Print usage.
+ --fibonacci Print the fibonacci sequence.
+ --factorial Print the factorial.
+ --square Print the square of the operand.
+"""
+
+from docopt import docopt
+from parameters import *
+from functions.fibonacci import *
+from functions.factorial import *
+from functions.square import *
+
+
+#
+# FUNCTION TABLE
+#
+functionTable = { CONST_FUNC_CODE_FIBONACCI : FibonacciSequence,
+ CONST_FUNC_CODE_FACTORIAL : Factorial,
+ CONST_FUNC_CODE_SQUARE : Square,
+ }
+
+#
+# MAIN ENTRY
+#
+if __name__ == '__main__':
+ print('')
+ print(CONST_VERSION_STRING)
+ print('')
+
+ # Process command line arguments.
+ params = Parameters(docopt(__doc__, version = CONST_VERSION))
+ params.PrintParameters()
+
+ # Call corresponding function with from .
+ result = functionTable[params.functionIndex](params.operand)
+
+ # Print results depending on the executed function.
+ if params.functionIndex == CONST_FUNC_CODE_FIBONACCI:
+ 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_SQUARE:
+ print(str(params.operand) + ' squared is ', str(result))
diff --git a/printNumbers/functions/square.py b/printNumbers/functions/square.py
new file mode 100644
index 0000000..acdcf1e
--- /dev/null
+++ b/printNumbers/functions/square.py
@@ -0,0 +1,28 @@
+# -*- coding: utf-8 -*-
+#
+# square.py
+#
+# This file is part of printNumbers.
+#
+# Copyright (C) 2022 P. Carlsson, IEK-8, 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 .
+
+def Square(n):
+ '''
+ :param n: Operand
+ :return: n*n
+ '''
+
+ return (n*n)
From 4d651c645364bd5f1dc3a9d43263598a8ff8378e Mon Sep 17 00:00:00 2001
From: PhilipCarlsson <75789974+PhilipCarlsson@users.noreply.github.com>
Date: Thu, 17 Nov 2022 11:54:17 +0000
Subject: [PATCH 3/5] Delete parameters.py
---
printNumbers/functions/parameters.py | 76 ----------------------------
1 file changed, 76 deletions(-)
delete mode 100644 printNumbers/functions/parameters.py
diff --git a/printNumbers/functions/parameters.py b/printNumbers/functions/parameters.py
deleted file mode 100644
index 54a7b8b..0000000
--- a/printNumbers/functions/parameters.py
+++ /dev/null
@@ -1,76 +0,0 @@
-# -*- coding: utf-8 -*-
-#
-# parameters.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 .
-
-#
-# Class to process and store program parameters.
-#
-
-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_FUNC_CODE_FIBONACCI = 0
-CONST_FUNC_CODE_FACTORIAL = 1
-CONST_FUNC_CODE_SQUARE = 2
-
-class Parameters(object):
-
- def __init__(self, cmdLineArgs):
- self.operand = CONST_DEF_OPERAND_VAL
- self.functionIndex = CONST_FUNC_CODE_FIBONACCI
- self.__setParameters(cmdLineArgs)
-
- def __setParameters(self, cmdLineArgs):
- self.operand = (int(cmdLineArgs['']))
- if cmdLineArgs['--fibonacci']:
- self.functionIndex = CONST_FUNC_CODE_FIBONACCI
- elif cmdLineArgs['--factorial']:
- self.functionIndex = CONST_FUNC_CODE_FACTORIAL
- elif cmdLineArgs['--square']:
- self.functionIndex = CONST_FUNC_CODE_SQUARE
-
- @property
- def operand(self):
- return(self.__operand)
-
- @operand.setter
- def operand(self, n):
- if n <= 0 or n > CONST_MAX_OPERAND_VAL:
- print('Error: Operand out of range: 0 < <=', CONST_MAX_OPERAND_VAL)
- print(' The default value ( n =', CONST_DEF_OPERAND_VAL, ') is used.')
- print('')
- n = CONST_DEF_OPERAND_VAL
- self.__operand = n
-
- @property
- def functionIndex(self):
- return(self.__functionIndex)
-
- @functionIndex.setter
- def functionIndex(self, value):
- self.__functionIndex = value
-
- def PrintParameters(self):
- print('Following Parameters are in use:')
- print('--------------------------------')
- print('Function Code: ', self.functionIndex)
- print('Operand value: ' + str(self.operand))
- print('')
From 27f00357ba0b55c4e9d90eef12d62f74630f144a Mon Sep 17 00:00:00 2001
From: PhilipCarlsson <75789974+PhilipCarlsson@users.noreply.github.com>
Date: Thu, 17 Nov 2022 11:54:44 +0000
Subject: [PATCH 4/5] Delete printNumbers.py
---
printNumbers/functions/printNumbers.py | 76 --------------------------
1 file changed, 76 deletions(-)
delete mode 100644 printNumbers/functions/printNumbers.py
diff --git a/printNumbers/functions/printNumbers.py b/printNumbers/functions/printNumbers.py
deleted file mode 100644
index 18cfe1b..0000000
--- a/printNumbers/functions/printNumbers.py
+++ /dev/null
@@ -1,76 +0,0 @@
-#! /bin/env python
-# -*- coding: utf-8 -*-
-#
-# printNumbers.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 .
-
-#
-# Software Development in Science Workshop
-# Python GitHub project example
-#
-
-"""
-Usage:
- printNumbers.py -h --help
- printNumbers.py [--fibonacci|--factorial|--square]
-
-Options:
- -h --help Print usage.
- --fibonacci Print the fibonacci sequence.
- --factorial Print the factorial.
- --square Print the square of the operand.
-"""
-
-from docopt import docopt
-from parameters import *
-from functions.fibonacci import *
-from functions.factorial import *
-from functions.square import *
-
-
-#
-# FUNCTION TABLE
-#
-functionTable = { CONST_FUNC_CODE_FIBONACCI : FibonacciSequence,
- CONST_FUNC_CODE_FACTORIAL : Factorial,
- CONST_FUNC_CODE_SQUARE : Square,
- }
-
-#
-# MAIN ENTRY
-#
-if __name__ == '__main__':
- print('')
- print(CONST_VERSION_STRING)
- print('')
-
- # Process command line arguments.
- params = Parameters(docopt(__doc__, version = CONST_VERSION))
- params.PrintParameters()
-
- # Call corresponding function with from .
- result = functionTable[params.functionIndex](params.operand)
-
- # Print results depending on the executed function.
- if params.functionIndex == CONST_FUNC_CODE_FIBONACCI:
- 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_SQUARE:
- print(str(params.operand) + ' squared is ', str(result))
From 9315f3e8a732db44f9214f9c5c829182b9b1b967 Mon Sep 17 00:00:00 2001
From: PhilipCarlsson <75789974+PhilipCarlsson@users.noreply.github.com>
Date: Thu, 17 Nov 2022 12:55:00 +0100
Subject: [PATCH 5/5] Add files via upload
---
printNumbers/parameters.py | 3 +++
printNumbers/printNumbers.py | 9 ++++++++-
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/printNumbers/parameters.py b/printNumbers/parameters.py
index aebe0c3..54a7b8b 100755
--- a/printNumbers/parameters.py
+++ b/printNumbers/parameters.py
@@ -29,6 +29,7 @@
CONST_MAX_OPERAND_VAL = 20
CONST_FUNC_CODE_FIBONACCI = 0
CONST_FUNC_CODE_FACTORIAL = 1
+CONST_FUNC_CODE_SQUARE = 2
class Parameters(object):
@@ -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['--square']:
+ self.functionIndex = CONST_FUNC_CODE_SQUARE
@property
def operand(self):
diff --git a/printNumbers/printNumbers.py b/printNumbers/printNumbers.py
index 9f9ef0e..18cfe1b 100755
--- a/printNumbers/printNumbers.py
+++ b/printNumbers/printNumbers.py
@@ -1,3 +1,4 @@
+#! /bin/env python
# -*- coding: utf-8 -*-
#
# printNumbers.py
@@ -27,24 +28,28 @@
"""
Usage:
printNumbers.py -h --help
- printNumbers.py [--fibonacci|--factorial]
+ printNumbers.py [--fibonacci|--factorial|--square]
Options:
-h --help Print usage.
--fibonacci Print the fibonacci sequence.
--factorial Print the factorial.
+ --square Print the square of the operand.
"""
from docopt import docopt
from parameters import *
from functions.fibonacci import *
from functions.factorial import *
+from functions.square import *
+
#
# FUNCTION TABLE
#
functionTable = { CONST_FUNC_CODE_FIBONACCI : FibonacciSequence,
CONST_FUNC_CODE_FACTORIAL : Factorial,
+ CONST_FUNC_CODE_SQUARE : Square,
}
#
@@ -67,3 +72,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_SQUARE:
+ print(str(params.operand) + ' squared is ', str(result))