| Total Complexity | 3 |
| Total Lines | 34 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import time |
||
| 2 | import numpy as np |
||
| 3 | from hyperactive import Hyperactive |
||
| 4 | |||
| 5 | |||
| 6 | def objective_function(para): |
||
| 7 | score = -para["x1"] * para["x1"] |
||
| 8 | return score |
||
| 9 | |||
| 10 | |||
| 11 | search_space = { |
||
| 12 | "x1": list(np.arange(0, 100000, 1)), |
||
| 13 | } |
||
| 14 | |||
| 15 | |||
| 16 | def test_max_time_0(): |
||
| 17 | c_time1 = time.perf_counter() |
||
| 18 | hyper = Hyperactive() |
||
| 19 | hyper.add_search(objective_function, search_space, n_iter=1000000) |
||
| 20 | hyper.run(max_time=0.1) |
||
| 21 | diff_time1 = time.perf_counter() - c_time1 |
||
| 22 | |||
| 23 | assert diff_time1 < 1 |
||
| 24 | |||
| 25 | |||
| 26 | def test_max_time_1(): |
||
| 27 | c_time1 = time.perf_counter() |
||
| 28 | hyper = Hyperactive() |
||
| 29 | hyper.add_search(objective_function, search_space, n_iter=1000000) |
||
| 30 | hyper.run(max_time=1) |
||
| 31 | diff_time1 = time.perf_counter() - c_time1 |
||
| 32 | |||
| 33 | assert 0.3 < diff_time1 < 2 |
||
| 34 |