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

Test assertions in search (#27) #40

Merged
merged 2 commits into from
Oct 3, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions tests/utils/search/test_gridsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def test_search_max_best_options_return_type(self):
maximum_best_score, maximum_best_options = self.g.search(maximum=True)
self.assertIsInstance(maximum_best_options, dict)


class MethodReturnValues(Base):

def test_search_greater_values(self):
Expand All @@ -70,4 +69,15 @@ def test_generate_grid(self):
"""Tests if generate_grid function returns expected value."""
self.assertEqual(self.g_mini.generate_grid(),
[{'c1': 1, 'c2': 6, 'k': 5, 'w': 0.9, 'p': 0},
{'c1': 2, 'c2': 6, 'k': 5, 'w': 0.9, 'p': 0}])
{'c1': 2, 'c2': 6, 'k': 5, 'w': 0.9, 'p': 0}])

class Instantiation(Base):

def test_optimizer_type_fail(self):
"""Tests that :code:`optimizer` of type :code:`string` raises
:code:`TypeError`"""
bad_optimizer = 'LocalBestPSO' # a string instead of a class object
with self.assertRaises(TypeError):
g = GridSearch(bad_optimizer, self.n_particles, self.dimensions,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I think I understand what you mean earlier. I guess this is the way to go when initializing objects.

self.options, self.objective_func, self.iters,
bounds=None, velocity_clamp=None)
21 changes: 21 additions & 0 deletions tests/utils/search/test_randomsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,24 @@ def test_generate_grid_param_mapping(self):
self.assertGreaterEqual(j, self.options[i][0])
self.assertLessEqual(j, self.options[i][1])

class Instantiation(Base):

def test_optimizer_type_fail(self):
"""Test that :code:`optimizer` of type :code:`string` raises
:code:`TypeError`"""
bad_optimizer = 'LocalBestPSO' # a string instead of a class object
with self.assertRaises(TypeError):
g = RandomSearch(bad_optimizer, self.n_particles, self.dimensions,
self.options, self.objective_func, self.iters,
self.n_selection_iters, bounds=None,
velocity_clamp=None)

def test_n_selection_iters_type_fail(self):
"""Test that :code:`n_selection_iters` of type :code:`float` raises
:code:`TypeError`"""
bad_n_selection_iters = 100.0 # should be an int
with self.assertRaises(TypeError):
g = RandomSearch(self.optimizer, self.n_particles, self.dimensions,
self.options, self.objective_func, self.iters,
bad_n_selection_iters, self.bounds,
velocity_clamp=None)