source: sasview/sansmodels/src/sans/models/test/utest_nonshape.py @ d56a520

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since d56a520 was f03b027, checked in by Gervaise Alina <gervyh@…>, 17 years ago
  • Property mode set to 100644
File size: 2.8 KB
Line 
1"""
2    Unit tests for non shape based model (Task 8.2.1)
3    These tests are part of the requirements
4"""
5
6import unittest, time, math
7
8# Disable "missing docstring" complaint
9# pylint: disable-msg=C0111
10# Disable "too many methods" complaint
11# pylint: disable-msg=R0904
12# Disable "could be a function" complaint
13# pylint: disable-msg=R0201
14
15 
16class TestGuinier(unittest.TestCase):
17    """
18        Unit tests for Guinier function
19       
20        F(x) = exp[ [A] + [B]*Q**2 ]
21       
22        The model has two parameters: A and B
23    """
24    def _func(self, a, b, x):
25        return math.exp(a+b*x**2)
26   
27    def setUp(self):
28        from GuinierModel import GuinierModel
29        self.model= GuinierModel()
30       
31    def test1D(self):
32        self.model.setParam('A', 2.0)
33        self.model.setParam('B', 1.0)
34       
35        self.assertEqual(self.model.run(0.0), math.exp(2.0))
36        self.assertEqual(self.model.run(2.0), math.exp(2.0+1.0*(2.0)**2))
37       
38    def test2D(self):
39        self.model.setParam('A', 2.0)
40        self.model.setParam('B', 1.0)
41       
42        value = self._func(2.0, 1.0, 1.0)*self._func(2.0, 1.0, 2.0)
43        self.assertEqual(self.model.runXY([0.0,0.0]), math.exp(2.0)*math.exp(2.0))
44        self.assertEqual(self.model.runXY([1.0,2.0]), value)
45       
46    def test2Dphi(self):
47        self.model.setParam('A', 2.0)
48        self.model.setParam('B', 1.0)
49       
50        x = 1.0
51        y = 2.0
52        r = math.sqrt(x**2 + y**2)
53        phi = math.atan2(y, x)
54       
55        value = self._func(2.0, 1.0, x)*self._func(2.0, 1.0, y)
56       
57        #self.assertEqual(self.model.run([r, phi]), value)
58        self.assertAlmostEquals(self.model.run([r, phi]), value,1)
59class TestPorod(unittest.TestCase):
60    """
61        Unit tests for Porod function
62       
63        F(x) = exp[ [C]/Q**4 ]
64       
65        The model has one parameter: C
66    """
67    def _func(self, c, x):
68        return math.exp(c/(x*x*x*x))
69   
70    def setUp(self):
71        from PorodModel import PorodModel
72        self.model= PorodModel()
73        self.model.setParam('c', 2.0)       
74       
75    def test1D(self):
76        value = self._func(2.0, 3.0)
77        self.assertEqual(self.model.run(3.0), value)
78       
79    def test2D(self):
80        value = self._func(2.0, 1.0)*self._func(2.0, 2.0)
81        self.assertEqual(self.model.runXY([1.0,2.0]), value)
82       
83    def test2Dphi(self):
84        x = 1.0
85        y = 2.0
86        r = math.sqrt(x**2 + y**2)
87        phi = math.atan2(y, x)
88       
89        value = self._func(2.0, 1.0)*self._func(2.0, 2.0)
90       
91        #self.assertEqual(self.model.run([r, phi]), value)
92        self.assertAlmostEquals(self.model.run([r, phi]), value,1)
93       
94if __name__ == '__main__':
95    unittest.main()
Note: See TracBrowser for help on using the repository browser.