diff --git a/.vscode/launch.json b/.vscode/launch.json index c6cff8f..84776a3 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,11 +4,13 @@ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ + { "name": "Python: Module", "type": "python", "request": "launch", - "module": "MDAF" + "module": "MDAF", + "args": ["plotfuncs('@Bukin2', features)"] }, { "name": "Python: Current File", diff --git a/.vscode/settings.json b/.vscode/settings.json index 7876636..705d4cc 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,8 +3,6 @@ "python.testing.pytestArgs": [ "tests" ], - "python.testing.unittestEnabled": false, - "python.testing.nosetestsEnabled": false, "python.testing.pytestEnabled": true, "python.testing.unittestArgs": [ "-v", @@ -13,5 +11,7 @@ "-p", "test_*.py" ], - "python.testing.cwd": "tests" + "python.testing.cwd": "", + "python.testing.nosetestsEnabled": false, + "python.testing.unittestEnabled": false } \ No newline at end of file diff --git a/MDAF/MDAF.py b/MDAF/MDAF.py index adcb6de..bd16981 100644 --- a/MDAF/MDAF.py +++ b/MDAF/MDAF.py @@ -269,5 +269,19 @@ def doe(heuristicpath, testfunctionpaths, args): #return the performance values return responses +def plotfuncs(funcpaths, features): + print ('help') + for i,funpath in enumerate(funcpaths): + if funpath.find('@') == 0: + funcpaths[i] = path.dirname(__file__) + '/TestFunctions/' + funpath[1:] + + funcnames = [path.splitext(path.basename(funcpath))[0] for funcpath in funcpaths] + representations = {} + + for idx,funpath in enumerate(funcpaths): + representations[funcnames[idx]] = representfunc(funpath) + + + # %% diff --git a/MDAF/TestFunctions/Ackley2.py b/MDAF/TestFunctions/Ackley2.py new file mode 100644 index 0000000..28b886b --- /dev/null +++ b/MDAF/TestFunctions/Ackley2.py @@ -0,0 +1,15 @@ +import math as m + +def main(args): + + ''' + #_# dimmensions: 2 + #_# upper: 32 + #_# lower: -32 + #_# minimum: [0, 0] + + >>> main([0, 0]) + -200.0 + + ''' + return -200 * m.e**(-0.02 * m.sqrt(args[0]**2 + args[1]**2)) \ No newline at end of file diff --git a/MDAF/TestFunctions/Keane.py b/MDAF/TestFunctions/Keane.py index a050f3a..8cb23fd 100644 --- a/MDAF/TestFunctions/Keane.py +++ b/MDAF/TestFunctions/Keane.py @@ -5,6 +5,9 @@ import math def main(args): ''' #_# dimmensions: 2 + #_# upper: 10 + #_# lower: 0 + #_# minimum: [0, 1.39325] ''' for x in args: if(x<0 | x>10): return 0 diff --git a/MDAF/TestFunctions/Leon.py b/MDAF/TestFunctions/Leon.py index 110c079..7df89d8 100644 --- a/MDAF/TestFunctions/Leon.py +++ b/MDAF/TestFunctions/Leon.py @@ -4,6 +4,9 @@ def main(args): ''' #_# dimmensions: 2 + #_# upper: 1.2 + #_# lower: -1.2 + #_# minimum: [1, 1] ''' for x in args: if x < -1.2 or x > 1.2: diff --git a/MDAF/TestFunctions/Matyas.py b/MDAF/TestFunctions/Matyas.py index 60daae3..e103a9a 100644 --- a/MDAF/TestFunctions/Matyas.py +++ b/MDAF/TestFunctions/Matyas.py @@ -5,7 +5,10 @@ def main(args): 0.26 - #_# dimmensions: 2 + #_# dimmensions: 2 + #_# upper: 10 + #_# lower: -10 + #_# minimum: [0, 0] ''' for x in args: if x < -10 or x > 10: diff --git a/MDAF/TestFunctions/McCormick.py b/MDAF/TestFunctions/McCormick.py index 1667c7a..19bc74d 100644 --- a/MDAF/TestFunctions/McCormick.py +++ b/MDAF/TestFunctions/McCormick.py @@ -1,10 +1,13 @@ import math def main(args): ''' - >>>main([-0.547, -1.547]) + >>> main([-0.547, -1.547]) 0 - #_# dimmensions: 2 + #_# dimmensions: 2 + #_# upper: [4, 3] + #_# lower: [-1.5, -3] + #_# minimum: [-0.547, -1.547] ''' for args[0] in args: diff --git a/MDAF/TestFunctions/Miele_Cantrell.py b/MDAF/TestFunctions/Miele_Cantrell.py index 773ecc3..d1e8c92 100644 --- a/MDAF/TestFunctions/Miele_Cantrell.py +++ b/MDAF/TestFunctions/Miele_Cantrell.py @@ -3,10 +3,14 @@ import math def main(args): ''' - >>>main([0, 1, 1, 1]) - 0 + >>> main([0, 1, 1, 1]) + 0.0 + + #_# dimmensions: 4 + #_# upper: 1 + #_# lower: -1 + #_# minimum: [0, 1, 1, 1] - #_# dimmensions: 4 ''' for x in args: if x < -1 or x > 1: diff --git a/MDAF/TestFunctions/Untitled.ipynb b/MDAF/TestFunctions/Untitled.ipynb deleted file mode 100644 index 7fec515..0000000 --- a/MDAF/TestFunctions/Untitled.ipynb +++ /dev/null @@ -1,6 +0,0 @@ -{ - "cells": [], - "metadata": {}, - "nbformat": 4, - "nbformat_minor": 4 -} diff --git a/MDAF/TestFunctions/__init__.py b/MDAF/TestFunctions/__init__.py index e69de29..78db003 100644 --- a/MDAF/TestFunctions/__init__.py +++ b/MDAF/TestFunctions/__init__.py @@ -0,0 +1,5 @@ +import pkgutil + +__path__ = pkgutil.extend_path(__path__, __name__) +for importer, modname, ispkg in pkgutil.walk_packages(path=__path__, prefix=__name__+'.'): + __import__(modname) \ No newline at end of file diff --git a/MDAF/TestFunctions/__pycache__/Brown.cpython-39.pyc b/MDAF/TestFunctions/__pycache__/Brown.cpython-39.pyc index 8b0a9ca..40dfc6a 100644 Binary files a/MDAF/TestFunctions/__pycache__/Brown.cpython-39.pyc and b/MDAF/TestFunctions/__pycache__/Brown.cpython-39.pyc differ diff --git a/MDAF/TestFunctions/__pycache__/Bukin6.cpython-39.pyc b/MDAF/TestFunctions/__pycache__/Bukin6.cpython-39.pyc index 427df38..6bcb241 100644 Binary files a/MDAF/TestFunctions/__pycache__/Bukin6.cpython-39.pyc and b/MDAF/TestFunctions/__pycache__/Bukin6.cpython-39.pyc differ diff --git a/MDAF/__pycache__/MDAF.cpython-39.pyc b/MDAF/__pycache__/MDAF.cpython-39.pyc index f27da99..de422b4 100644 Binary files a/MDAF/__pycache__/MDAF.cpython-39.pyc and b/MDAF/__pycache__/MDAF.cpython-39.pyc differ diff --git a/tests/__pycache__/test_flows.cpython-39-pytest-6.2.4.pyc b/tests/__pycache__/test_flows.cpython-39-pytest-6.2.4.pyc index 1635b6a..c8c49ab 100644 Binary files a/tests/__pycache__/test_flows.cpython-39-pytest-6.2.4.pyc and b/tests/__pycache__/test_flows.cpython-39-pytest-6.2.4.pyc differ diff --git a/tests/__pycache__/test_funcs.cpython-39-pytest-6.2.4.pyc b/tests/__pycache__/test_funcs.cpython-39-pytest-6.2.4.pyc new file mode 100644 index 0000000..6dd62ea Binary files /dev/null and b/tests/__pycache__/test_funcs.cpython-39-pytest-6.2.4.pyc differ diff --git a/tests/__pycache__/test_unit.cpython-39-pytest-6.2.4.pyc b/tests/__pycache__/test_unit.cpython-39-pytest-6.2.4.pyc new file mode 100644 index 0000000..cc80d30 Binary files /dev/null and b/tests/__pycache__/test_unit.cpython-39-pytest-6.2.4.pyc differ diff --git a/tests/deprecated_funcs.py b/tests/deprecated_funcs.py new file mode 100644 index 0000000..4e24c58 --- /dev/null +++ b/tests/deprecated_funcs.py @@ -0,0 +1,21 @@ +import unittest +import os +import importlib.util as utl + +from MDAF.TestFunctions import * +import doctest + + +# Testing the test function representation workflow +def load_tests(loader, tests, ignore): + fullpath = 'MDAF/TestFunctions' + for func in os.scandir(fullpath): + name = str(func.name) + if(name.find('.py') and name.find('.old') == -1 and func.is_file() and name.find('__init__.py')==-1): + spec = utl.spec_from_file_location(name[-3], fullpath+'/'+name) + funcmodule = utl.module_from_spec(spec) + spec.loader.exec_module(funcmodule) + + tests.addTests(doctest.DocTestSuite(funcmodule)) + return tests + diff --git a/tests/deprecated_unit.py b/tests/deprecated_unit.py new file mode 100644 index 0000000..bb97e64 --- /dev/null +++ b/tests/deprecated_unit.py @@ -0,0 +1,53 @@ +import unittest +import doctest +import os + +def load_tests(loader, tests, ignore): + fullpath = 'MDAF/TestFunctions' + testlist = [] + for func in os.scandir(fullpath): + name = str(func.name) + if(name.find('.py') and name.find('.old') == -1 and func.is_file()): + spec = importlib.util.spec_from_file_location(name, fullpath) + funcmodule = importlib.util.module_from_spec(spec) + spec.loader.exec_module(funcmodule) + + tests.addTests(doctest.DocTestSuite(funcmodule)) + return tests + +if __name__ == '__main__': + runner = unittest.TextTestRunner() + runner.run(load_tests()) + + + + +import unittest +import os + + +from MDAF.TestFunctions import * +import doctest + + +#target = __import__("MDAF.py") + +# Testing the test function representation workflow +def load_tests(loader, tests, ignore): + + fullpath = 'MDAF/TestFunctions' + testlist = [] + for func in os.scandir(fullpath): + name = str(func.name) + if(name.find('.py') and name.find('.old') == -1 and func.is_file()): + curtest = doctest.DocTestSuite(os.path.relpath('../'+func.path[:-3]+'.main.__module__')) + testlist.append(curtest) + tests.addTests(testlist) + + tests.addTests(doctest.DocTestSuite(Ackley2.main.__module__)) + for t in tests: return t + +# run the suite +suite = load_tests(loader, tests, ignore) +runner = unittest.TextTestRunner() +runner.run(suite) \ No newline at end of file diff --git a/tests/test_flows.py b/tests/test_flows.py index 7ff674d..88f0c2d 100644 --- a/tests/test_flows.py +++ b/tests/test_flows.py @@ -4,6 +4,7 @@ import os from MDAF.MDAF import representfunc from MDAF.MDAF import installFalcoo from MDAF.MDAF import doe +from MDAF.TestFunctions import * #target = __import__("MDAF.py") @@ -32,11 +33,12 @@ class Test_representfunc(unittest.TestCase): Test that the function can calculate the representation and write to the function docstring """ funcpath = '@Bukin2.py' + funcverify = 'MDAF/TestFunctions/Bukin2.py' #funcpath_backup = 'tests/Bukin2.py.old' results = representfunc(funcpath, forced = True) - with open(funcpath,"r") as file: + with open(funcverify,"r") as file: content = file.read() reprCheck = bool(content.find('#_# Represented: 1'))