Skip to content

Commit

Permalink
add tests for public API
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonBlanke committed Jun 17, 2024
1 parent 2f5f514 commit b10a409
Show file tree
Hide file tree
Showing 6 changed files with 258 additions and 0 deletions.
Empty file added tests/test_api/__init__.py
Empty file.
34 changes: 34 additions & 0 deletions tests/test_api/test_api_hyperactive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import pytest

from hyperactive import Hyperactive
from surfaces.test_functions import test_functions


test_functions_d = (
"test_function",
test_functions,
)


@pytest.mark.parametrize(*test_functions_d)
def test_all_functions(test_function):
try:
test_function_ = test_function()
except TypeError:
test_function_ = test_function(n_dim=3)

try:
search_space = test_function_.search_space(value_types="list")
except TypeError:
search_space = test_function_.search_space()

objective_function = test_function_.objective_function
n_iter = 5

hyper = Hyperactive()
hyper.add_search(
objective_function,
search_space,
n_iter=n_iter,
)
hyper.run()
36 changes: 36 additions & 0 deletions tests/test_api/test_input_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import pytest

from surfaces.test_functions import mathematical_functions, machine_learning_functions


mathematical_functions_d = (
"test_function",
mathematical_functions,
)


machine_learning_functions_d = (
"test_function",
machine_learning_functions,
)


@pytest.mark.parametrize(*mathematical_functions_d)
def test_(test_function):
try:
test_function_ = test_function()
except TypeError:
test_function_ = test_function(n_dim=2)

objective_function = test_function_.objective_function
search_space = test_function_.search_space(value_types="array")
n_iter = 20


@pytest.mark.parametrize(*machine_learning_functions_d)
def test_all_(test_function):
test_function_ = test_function()

objective_function = test_function_.objective_function
search_space = test_function_.search_space()
n_iter = 20
36 changes: 36 additions & 0 deletions tests/test_api/test_metric.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import pytest

from surfaces.test_functions import mathematical_functions, machine_learning_functions


mathematical_functions_d = (
"test_function",
mathematical_functions,
)


machine_learning_functions_d = (
"test_function",
machine_learning_functions,
)


@pytest.mark.parametrize(*mathematical_functions_d)
def test_(test_function):
try:
test_function_ = test_function()
except TypeError:
test_function_ = test_function(n_dim=2)

objective_function = test_function_.objective_function
search_space = test_function_.search_space(value_types="array")
n_iter = 20


@pytest.mark.parametrize(*machine_learning_functions_d)
def test_all_(test_function):
test_function_ = test_function()

objective_function = test_function_.objective_function
search_space = test_function_.search_space()
n_iter = 20
116 changes: 116 additions & 0 deletions tests/test_api/test_search_space.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import pytest
from gradient_free_optimizers import RandomSearchOptimizer
from hyperactive import Hyperactive


from surfaces.test_functions import (
machine_learning_functions,
)
from surfaces.test_functions.mathematical import (
mathematical_functions_1d,
mathematical_functions_2d,
mathematical_functions_nd,
)

mathematical_functions_1d = (
"test_function",
mathematical_functions_1d,
)

mathematical_functions_2d = (
"test_function",
mathematical_functions_2d,
)

mathematical_functions_nd = (
"test_function",
mathematical_functions_nd,
)


machine_learning_functions_d = (
"test_function",
machine_learning_functions,
)


@pytest.mark.parametrize(*mathematical_functions_1d)
def test_search_space_1d_0(test_function):
test_function_ = test_function()

objective_function = test_function_.objective_function
search_space = test_function_.search_space(min=-1, max=1, value_types="array")
n_iter = 20

opt = RandomSearchOptimizer(search_space)
opt.search(objective_function, n_iter=n_iter)


@pytest.mark.parametrize(*mathematical_functions_2d)
def test_search_space_2d_0(test_function):
print("\n test_function", test_function, "\n")
test_function_ = test_function()

objective_function = test_function_.objective_function
search_space = test_function_.search_space(min=-1, max=1, value_types="array")
n_iter = 20

opt = RandomSearchOptimizer(search_space)
opt.search(objective_function, n_iter=n_iter)


@pytest.mark.parametrize(*mathematical_functions_2d)
def test_search_space_2d_1(test_function):
test_function_ = test_function()

objective_function = test_function_.objective_function
search_space = test_function_.search_space(
min=[-1, -1], max=[1, 1], value_types="array"
)
n_iter = 20

opt = RandomSearchOptimizer(search_space)
opt.search(objective_function, n_iter=n_iter)


@pytest.mark.parametrize(*mathematical_functions_nd)
def test_search_space_nd_0(test_function):
test_function_ = test_function(n_dim=3)

objective_function = test_function_.objective_function
search_space = test_function_.search_space(min=-1, max=1, value_types="array")
n_iter = 20

opt = RandomSearchOptimizer(search_space)
opt.search(objective_function, n_iter=n_iter)


@pytest.mark.parametrize(*mathematical_functions_nd)
def test_search_space_nd_1(test_function):
test_function_ = test_function(n_dim=3)

objective_function = test_function_.objective_function
search_space = test_function_.search_space(
min=[-1, -1, -1], max=[1, 1, 1], value_types="array"
)
n_iter = 20

opt = RandomSearchOptimizer(search_space)
opt.search(objective_function, n_iter=n_iter)


@pytest.mark.parametrize(*machine_learning_functions_d)
def test_all_(test_function):
test_function_ = test_function()

objective_function = test_function_.objective_function
search_space = test_function_.search_space()
n_iter = 3

hyper = Hyperactive()
hyper.add_search(
objective_function,
search_space,
n_iter=n_iter,
)
hyper.run()
36 changes: 36 additions & 0 deletions tests/test_api/test_sleep.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import pytest

from surfaces.test_functions import mathematical_functions, machine_learning_functions


mathematical_functions_d = (
"test_function",
mathematical_functions,
)


machine_learning_functions_d = (
"test_function",
machine_learning_functions,
)


@pytest.mark.parametrize(*mathematical_functions_d)
def test_(test_function):
try:
test_function_ = test_function()
except TypeError:
test_function_ = test_function(n_dim=2)

objective_function = test_function_.objective_function
search_space = test_function_.search_space(value_types="array")
n_iter = 20


@pytest.mark.parametrize(*machine_learning_functions_d)
def test_all_(test_function):
test_function_ = test_function()

objective_function = test_function_.objective_function
search_space = test_function_.search_space()
n_iter = 20

0 comments on commit b10a409

Please sign in to comment.