def setUp(self): from sas.models.LorentzModel import LorentzModel self.model= LorentzModel()
class TestLorentz(unittest.TestCase): """ Unit tests for Lorentz function F(x) = scale/( 1 + (x*L)^2 ) + bkd The model has three parameters: L = screen Length scale = scale factor bkd = incoherent background """ def _func(self, I0 , L, bgd, qval): return I0/(1.0 + (qval*L)*(qval*L)) + bgd def setUp(self): from sas.models.LorentzModel import LorentzModel self.model= LorentzModel() def test1D(self): self.model.setParam('scale', 100.0) self.model.setParam('Length', 50.0) self.model.setParam('background', 1.0) self.assertEqual(self.model.run(0.0), 101.0) self.assertEqual(self.model.run(2.0), self._func(100.0, 50.0, 1.0, 2.0)) self.assertEqual(self.model.runXY(2.0), self._func(100.0, 50.0, 1.0, 2.0)) def test2D(self): self.model.setParam('scale', 100.0) self.model.setParam('Length', 50.0) self.model.setParam('background', 1.0) #value = self._func(100.0, 50.0, 1.0, 1.0)*self._func(100.0, 50.0, 1.0, 2.0) value = self._func(100.0, 50.0, 1.0, math.sqrt(5.0)) self.assertEqual(self.model.runXY([1.0,2.0]), value) def test2Dphi(self): self.model.setParam('scale', 100.0) self.model.setParam('Length', 50.0) self.model.setParam('background', 1.0) x = 1.0 y = 2.0 r = math.sqrt(x**2 + y**2) phi = math.atan2(y, x) value = self._func(100.0, 50.0, 1.0, x)*self._func(100.0, 50.0, 1.0, y) self.assertAlmostEquals(self.model.run([r, phi]), value,1)