Skip to content

Commit

Permalink
Merge pull request #31 from qbahn/feature/addPySwarmTests
Browse files Browse the repository at this point in the history
Add pySwarm code - tests.
  • Loading branch information
wojtekPi committed Apr 11, 2016
2 parents 8ebc534 + a33f288 commit 3758950
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .privateWordDictionary
Expand Up @@ -7,6 +7,8 @@ docstring
OK
tuple
pyswarm
PSO
tisimst
github
https
PSO
1 change: 1 addition & 0 deletions grortir/test/externals/__init__.py
@@ -0,0 +1 @@
"""Package for test externals package."""
1 change: 1 addition & 0 deletions grortir/test/externals/pyswarm/__init__.py
@@ -0,0 +1 @@
"""Package for tests pyswarm."""
30 changes: 30 additions & 0 deletions grortir/test/externals/pyswarm/test_pyswarm.py
@@ -0,0 +1,30 @@
"""Tests for pyswarm."""
from unittest import TestCase
from grortir.externals.pyswarm.pso import pso


class TestPso(TestCase):
"""Class for tests pyswarm."""

def test_run_simple_pso(self):
"""Test running library."""
lower_bound = [-3, -1]
upper_bound = [2, 6]

x_opt, f_opt = pso(myfunc, lower_bound, upper_bound)
self.assertIsNotNone(x_opt)
self.assertIsNotNone(f_opt)


def myfunc(input_vector):
"""Simple function for tests.
Args:
input_vector (list): input vector
Returns:
object : value of function
"""
x_1 = input_vector[0]
x_2 = input_vector[1]
return x_1 ** 4 - 2 * x_2 * x_1 ** 2 + x_2 ** 2 + x_1 ** 2 - 2 * x_1 + 5

0 comments on commit 3758950

Please sign in to comment.