-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_correct_invalid.py
58 lines (52 loc) · 1.95 KB
/
test_correct_invalid.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import unittest
from configtune import TuningDeap, TuningBayes
import logging
logging.basicConfig(level=logging.INFO)
class TestEvaluateError(unittest.TestCase):
def setUp(self):
self.tuning_config = {
"population_size": 1,
"n_generations": 1,
"attributes": {
"name1": {
"type": "float",
"min": 0,
"max": 1,
"step": 0.1
},
"name2": {
"type": "bool"
},
"name3": {
"type": "int",
"min": 1,
"max": 5,
"step": 1
},
"name4": {
"type": "categorical",
"values": ["a", "b", "c"]
}
}
}
def test_minimize_error(self):
def eval_function(chromosomes):
raise Exception("test failure")
tune = TuningDeap(eval_function, self.tuning_config, minimize=True)
best_config, best_score = tune.run()
assert best_score == float("inf"), "wrong default value was returned. Should be inf was {}".format(best_score)
def test_maximize_error(self):
def eval_function(chromosomes):
raise Exception("test failure")
tune = TuningDeap(eval_function, self.tuning_config, minimize=False)
best_config, best_score = tune.run()
assert best_score == float("-inf"), "wrong default value was returned. Should be -inf was {}".format(best_score)
def test_bayes_no_maximize(self):
try:
def eval_function(chromosomes):
raise 1
tune = TuningBayes(eval_function, self.tuning_config, minimize=False, n_calls=2)
best_config, best_score = tune.run()
self.fail("Should not have allowed `minimize=False` to work")
except Exception:
pass