def __init__(self, func, names, bounds, constraints=[], popsize=10): def evalFunc(values): return defer.maybeDeferred(func, values) self.Nd = len(bounds) self.Np = self.Nd * popsize self.pm = MockParameterManager() if not callable(func): raise ValueError(sub("Object '{}' is not callable", func)) self.evalFunc = evalFunc self.counter = 0 self.running = None
def assertWithinTenPercent(self, x, xExpected): ratio = x / xExpected msg = sub("{} not within 10% of {}", x, xExpected) self.assertAlmostEqual(0.1*ratio, 0.1, 2, msg)
def assertWithinFivePercent(self, x, xExpected): ratio = x / xExpected msg = sub("{} not within 5% of {}", x, xExpected) self.assertAlmostEqual(0.2*ratio, 0.2, 2, msg)
def assertWithinOnePercent(self, x, xExpected): ratio = x / xExpected msg = sub("{} not within 1% of {}", x, xExpected) self.assertAlmostEqual(ratio, 1, 2, msg)
def assertItemsEqual(self, a, b): for ak, bk in zip(a, b): self.assertEqual(ak, bk, sub("{} != {}", a, b))