()
| 70 | |
| 71 | |
| 72 | def test_register(): |
| 73 | PBOUNDS = {"p1": (0, 10), "p2": (1, 100)} |
| 74 | space = TargetSpace(target_func, PBOUNDS) |
| 75 | |
| 76 | assert len(space) == 0 |
| 77 | # registering with dict |
| 78 | space.register(params={"p1": 1, "p2": 2}, target=3) |
| 79 | assert len(space) == 1 |
| 80 | assert all(space.params[0] == np.array([1, 2])) |
| 81 | assert all(space.target == np.array([3])) |
| 82 | |
| 83 | # registering with dict out of order |
| 84 | space.register(params={"p2": 4, "p1": 5}, target=9) |
| 85 | assert len(space) == 2 |
| 86 | assert all(space.params[1] == np.array([5, 4])) |
| 87 | assert all(space.target == np.array([3, 9])) |
| 88 | |
| 89 | # registering with array |
| 90 | space.register(params=np.array([0, 1]), target=1) |
| 91 | assert len(space) == 3 |
| 92 | assert all(space.params[2] == np.array([0, 1])) |
| 93 | assert all(space.target == np.array([3, 9, 1])) |
| 94 | |
| 95 | with pytest.raises(NotUniqueError): |
| 96 | space.register(params={"p1": 1, "p2": 2}, target=3) |
| 97 | with pytest.raises(NotUniqueError): |
| 98 | space.register(params={"p1": 5, "p2": 4}, target=9) |
| 99 | |
| 100 | |
| 101 | def test_register_with_constraint(): |
nothing calls this directly
no test coverage detected