From 4a15397b51a0701afc557d0f754e4e7e177ad644 Mon Sep 17 00:00:00 2001 From: amsks Date: Mon, 11 Dec 2023 13:28:23 +0100 Subject: [PATCH] enhancement: test for search space encoding --- test/test_search_space_encoding.py | 40 ++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 test/test_search_space_encoding.py diff --git a/test/test_search_space_encoding.py b/test/test_search_space_encoding.py new file mode 100644 index 00000000..5ce06175 --- /dev/null +++ b/test/test_search_space_encoding.py @@ -0,0 +1,40 @@ +import unittest + +from carl.context.search_space_encoding import search_space_to_config_space +from ConfigSpace import ConfigurationSpace +from omegaconf import DictConfig + + +class TestSearchSpacEncoding(unittest.TestCase): + def setUp(self): + self.test_space = None + self.test_space = ConfigurationSpace( + name="myspace", + space={ + "uniform_integer": (1, 10), + "uniform_float": (1.0, 10.0), + "categorical": ["a", "b", "c"], + "constant": 1337, + }, + ) + return super().setUp() + + def test_config_spaces(self): + try: + search_space_to_config_space(self.test_space) + except Exception as e: + print(f"Cannot encode search space -- {self.test_space}.") + raise e + + def test_dict_configs(self): + try: + dict_space = DictConfig({"hyperparameters": {}}) + + search_space_to_config_space(dict_space) + except Exception as e: + print(f"Cannot encode search space -- {dict_space}.") + raise e + + +if __name__ == "__main__": + unittest.main()