Skip to content

Commit 48f428f

Browse files
committed
Added tests
1 parent 8a5f0b5 commit 48f428f

File tree

2 files changed

+126
-0
lines changed

2 files changed

+126
-0
lines changed

.gitlab-ci.yml

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#image: pypy:latest
2+
image: python:latest
3+
4+
stages:
5+
- dependencies
6+
- build
7+
- test
8+
- tooling
9+
10+
variables:
11+
GIT_DEPTH: "1"
12+
PYTHONUSERBASE: "${CI_PROJECT_DIR}/python_user_packages"
13+
14+
dependencies:
15+
tags:
16+
- shared
17+
stage: dependencies
18+
before_script:
19+
- export EXECUTABLE_DEPENDENCIES_DIR=${PYTHONUSERBASE}/bin
20+
- export PATH="$PATH:$EXECUTABLE_DEPENDENCIES_DIR" # don't move into `variables` any of them, it is unordered
21+
script:
22+
- pip3 install --user --upgrade --pre setuptools setuptools_scm
23+
- pip3 install --user --upgrade --pre git+https://github.com/pypa/pip.git git+https://github.com/pypa/wheel.git
24+
- pip3 install --user --upgrade --pre coverage git+https://github.com/coveralls-clients/coveralls-python.git@eba54e4d19e40e3907e5fd516f68e8b4dc9e5a31 git+https://github.com/codecov/codecov-python.git@0743daa83647f12ff31b84d07113d2c24c27b924
25+
- pip3 install --upgrade --user --pre scikit-learn numpy scipy
26+
27+
cache:
28+
key: deps
29+
paths:
30+
- $PYTHONUSERBASE
31+
32+
build:
33+
tags:
34+
- shared
35+
stage: build
36+
37+
before_script:
38+
- export EXECUTABLE_DEPENDENCIES_DIR=${PYTHONUSERBASE}/bin
39+
- export PATH="$PATH:$EXECUTABLE_DEPENDENCIES_DIR" # don't move into `variables` any of them, it is unordered
40+
41+
script:
42+
- python3 setup.py bdist_wheel
43+
- mv ./dist/*.whl ./dist/evostra-0.CI-py3-none-any.whl
44+
- pip3 install --user --upgrade --pre ./dist/evostra-0.CI-py3-none-any.whl
45+
- coverage run --source=evostra ./tests/tests.py
46+
- coverage report -m
47+
- coveralls || true
48+
- codecov || true
49+
50+
cache:
51+
key: deps
52+
paths:
53+
- $PYTHONUSERBASE
54+
55+
artifacts:
56+
paths:
57+
- dist
58+
59+
sast:
60+
stage: tooling
61+
tags:
62+
- shared
63+
image: docker:latest
64+
variables:
65+
DOCKER_DRIVER: overlay2
66+
allow_failure: true
67+
services:
68+
- docker:dind
69+
script:
70+
- docker run --env SAST_CONFIDENCE_LEVEL=5 --volume "$PWD:/code" --volume /var/run/docker.sock:/var/run/docker.sock "registry.gitlab.com/gitlab-org/security-products/sast:latest" /app/bin/run /code
71+
artifacts:
72+
paths:
73+
- gl-sast-report.json
74+
75+
pages:
76+
stage: tooling
77+
tags:
78+
- shared
79+
image: alpine:latest
80+
allow_failure: true
81+
before_script:
82+
- apk update
83+
- apk add doxygen
84+
- apk add ttf-freefont graphviz
85+
script:
86+
- doxygen ./Doxyfile
87+
- mv ./docs/html ./public
88+
artifacts:
89+
paths:
90+
- public
91+
only:
92+
- master

tests/tests.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env python3
2+
import sys
3+
from pathlib import Path
4+
import unittest
5+
thisDir=Path(__file__).parent.absolute()
6+
sys.path.append(str(thisDir.parent))
7+
8+
import numpy as np
9+
from evostra import EvolutionStrategy
10+
11+
def modRosenbrockNP(X, a=1, b=100):
12+
return np.sqrt(np.power(a-X[0], 4) + b*np.power(X[1]-np.power(X[0], 2), 2))
13+
14+
def ackleyRosenbrockNp(X, a=20, b=0.2, c=2*np.pi):
15+
return np.real(a*(1-np.exp(-b*np.sqrt(modRosenbrockNP(X, a=0, b=a)/X.shape[0])))-np.exp(np.sum(np.cos(c*X), axis=0)/X.shape[0])+np.exp(1))
16+
17+
18+
bounds = np.array([[0, 10], [-10, 10]])
19+
initialPoint = np.array([0.7, 0.7])
20+
21+
def get_reward(weights):
22+
weights=np.array(weights)
23+
print(weights)
24+
res = ackleyRosenbrockNp(weights)
25+
print(res)
26+
return res
27+
28+
class OptimizersTests(unittest.TestCase):
29+
def testOptimizer(self):
30+
es = EvolutionStrategy(initialPoint, get_reward, population_size=20, sigma=0.1, learning_rate=0.03, decay=1., num_threads=1)
31+
es.run(100, print_step=1)
32+
33+
if __name__ == '__main__':
34+
unittest.main()

0 commit comments

Comments
 (0)