Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pySwarm code - tests. #31

Merged
merged 2 commits into from
Apr 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .privateWordDictionary
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Package for test externals package."""
1 change: 1 addition & 0 deletions grortir/test/externals/pyswarm/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Package for tests pyswarm."""
30 changes: 30 additions & 0 deletions grortir/test/externals/pyswarm/test_pyswarm.py
Original file line number Diff line number Diff line change
@@ -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