Skip to content

Commit d1d653e

Browse files
committed
Implemented a test for the new get_random_neighbor method
1 parent c6917bd commit d1d653e

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

test/test_searchspace.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,16 @@ def test_neighbors_hamming():
246246
(3, 4, 'string_1'),
247247
]
248248

249+
# test the neighbors
249250
__test_neighbors(test_config, expected_neighbors, "Hamming")
250251

252+
# test the random neighbor function
253+
neighbors = simple_searchspace.get_neighbors(test_config, "Hamming")
254+
for i in range(10):
255+
random_neighbor = simple_searchspace.get_random_neighbor(test_config, "Hamming")
256+
assert random_neighbor in neighbors
257+
assert random_neighbor != test_config
258+
251259

252260
def test_neighbors_strictlyadjacent():
253261
"""Test whether the strictly adjacent neighbors are as expected."""
@@ -259,8 +267,16 @@ def test_neighbors_strictlyadjacent():
259267
(1.5, 5.5, 'string_2'),
260268
]
261269

270+
# test the neighbors
262271
__test_neighbors(test_config, expected_neighbors, "strictly-adjacent")
263272

273+
# test the random neighbor function
274+
neighbors = simple_searchspace.get_neighbors(test_config, "strictly-adjacent")
275+
for i in range(10):
276+
random_neighbor = simple_searchspace.get_random_neighbor(test_config, "strictly-adjacent")
277+
assert random_neighbor in neighbors
278+
assert random_neighbor != test_config
279+
264280

265281
def test_neighbors_adjacent():
266282
"""Test whether the adjacent neighbors are as expected."""
@@ -272,8 +288,16 @@ def test_neighbors_adjacent():
272288
(1.5, 5.5, 'string_2'),
273289
]
274290

291+
# test the neighbors
275292
__test_neighbors(test_config, expected_neighbors, "adjacent")
276293

294+
# test the random neighbor function
295+
neighbors = simple_searchspace.get_neighbors(test_config, "adjacent")
296+
for i in range(10):
297+
random_neighbor = simple_searchspace.get_random_neighbor(test_config, "adjacent")
298+
assert random_neighbor in neighbors
299+
assert random_neighbor != test_config
300+
277301

278302
def test_neighbors_fictious():
279303
"""Test whether the neighbors are as expected for a fictious parameter configuration (i.e. not existing in the search space due to restrictions)."""

0 commit comments

Comments
 (0)