def test_better_cand(self): name = "test_experiment" param_def = { "x": MinMaxNumericParamDef(0, 1), "name": NominalParamDef(["A", "B", "C"]) } minimization = True exp = Experiment(name, param_def, minimization) cand = Candidate({"x": 1, "name": "B"}) cand2 = Candidate({"x": 0, "name": "A"}) cand_none = Candidate({"x": 0.5, "name": "C"}) cand.result = 1 cand2.result = 0 assert_true(exp.better_cand(cand2, cand)) assert_true(exp.better_cand(cand2, cand_none)) exp.minimization_problem = False assert_true(exp.better_cand(cand, cand2)) assert_false(exp.better_cand(cand2, cand))
def test_better_cand(self): cand = Candidate({"x": 1, "name": "B"}) cand2 = Candidate({"x": 0, "name": "A"}) cand_none = Candidate({"x": 0.5, "name": "C"}) cand_invalid = Candidate({"x": 0.5, "name": "D"}) cand.result = 1 cand2.result = 0 assert_true(self.exp.better_cand(cand2, cand)) assert_true(self.exp.better_cand(cand2, cand_none)) self.exp.minimization_problem = False assert_true(self.exp.better_cand(cand, cand2)) assert_false(self.exp.better_cand(cand2, cand)) assert_true(self.exp.better_cand(cand, None)) assert_false(self.exp.better_cand(None, cand)) assert_false(self.exp.better_cand(None, None)) with assert_raises(ValueError): self.exp.better_cand(cand, cand_invalid) with assert_raises(ValueError): self.exp.better_cand(cand_invalid, cand) with assert_raises(ValueError): self.exp.better_cand("fails", cand) with assert_raises(ValueError): self.exp.better_cand(cand, "fails")