def setUp(self): from sas.models.DABModel import DABModel self.model= DABModel() self.scale = 10.0 self.length = 40.0 self.back = 1.0 self.model.setParam('scale', self.scale) self.model.setParam('length', self.length) self.model.setParam('background', self.back)
class TestDAB(unittest.TestCase): """ Unit tests for DAB function F(x) = scale/( 1 + (x*L)^2 )^(2) + bkd The model has three parameters: L = Correlation Length scale = scale factor bkd = incoherent background """ def _func(self, Izero, range, incoh, qval): return Izero* pow(range,3)/pow((1.0 + (qval*range)*(qval*range)),2) + incoh def setUp(self): from sas.models.DABModel import DABModel self.model= DABModel() self.scale = 10.0 self.length = 40.0 self.back = 1.0 self.model.setParam('scale', self.scale) self.model.setParam('length', self.length) self.model.setParam('background', self.back) def test1D(self): self.assertEqual(self.model.run(2.0), self._func(self.scale, self.length, self.back, 2.0)) self.assertEqual(self.model.runXY(2.0), self._func(self.scale, self.length, self.back, 2.0)) def test2D(self): #value = self._func(self.scale, self.length, self.back, 1.0)*self._func(self.scale, self.length, self.back, 2.0) value = self._func(self.scale, self.length, self.back, math.sqrt(5.0)) self.assertEqual(self.model.runXY([1.0,2.0]), value) def test2Dphi(self): x = 1.0 y = 2.0 r = math.sqrt(x**2 + y**2) phi = math.atan2(y, x) value = self._func(self.scale, self.length, self.back, x)*self._func(self.scale, self.length, self.back, y) self.assertAlmostEquals(self.model.run([x, y]), value,1)