[96d19c6] | 1 | """ |
---|
| 2 | Unit tests for specific models |
---|
| 3 | @author: JHJ Cho / UTK |
---|
| 4 | """ |
---|
| 5 | |
---|
| 6 | import unittest |
---|
| 7 | |
---|
| 8 | class TestOnionExpShell1(unittest.TestCase): |
---|
| 9 | """ |
---|
| 10 | Unit tests for OnionExpShellModel |
---|
| 11 | """ |
---|
| 12 | def setUp(self): |
---|
| 13 | |
---|
| 14 | from sans.models.OnionExpShellModel import OnionExpShellModel |
---|
| 15 | from sans.models.CoreMultiShellModel import CoreMultiShellModel |
---|
| 16 | from sans.models.VesicleModel import VesicleModel |
---|
| 17 | |
---|
| 18 | # intit models and the multifactor |
---|
| 19 | self.model = OnionExpShellModel(1) |
---|
| 20 | self.model2 = OnionExpShellModel(1).model |
---|
| 21 | self.model3 = CoreMultiShellModel(1) |
---|
| 22 | self.model4 = VesicleModel() |
---|
| 23 | self.model5 = OnionExpShellModel(9) |
---|
| 24 | |
---|
| 25 | def test_compare_Exp0_flat(self): |
---|
| 26 | """ |
---|
| 27 | Check if Exp function with A_shell=0 gives the same value as Flat function |
---|
| 28 | """ |
---|
| 29 | print "\n*****Note: All tests (test_compare_Exp0_flat and test_compare_Expsmall_line) were passes since Sept. 18, 2010..." |
---|
| 30 | # Exp: func_shell = 2, Line: func_shell =1 , Flat: func_shell = 0. |
---|
| 31 | # A_shell = The coefficient of the exponential function: exp(A_shell*(r-ro)/thick_shell) |
---|
| 32 | # exp function by default |
---|
| 33 | # exp function crosses over to flat func at A_shell=0 |
---|
| 34 | self.model.setParam("A_shell1", 0) |
---|
| 35 | # set A_shell=1 |
---|
| 36 | self.model2.setParam("A_shell1", 1) |
---|
| 37 | # change the function to flat function |
---|
| 38 | self.model2.setParam("func_shell1", 0) |
---|
| 39 | #self.model2.setParam("sld_in_shell1", 1.7e-006) |
---|
| 40 | #self.model2.setParam("sld_out_shell1", 1.7e-006) |
---|
| 41 | |
---|
| 42 | # model3: set param values as same as the model2 |
---|
| 43 | self.model3.setParam("background", 0.0) |
---|
| 44 | self.model3.setParam("rad_core0", 200.0) |
---|
| 45 | self.model3.setParam("scale", 1.0) |
---|
| 46 | self.model3.setParam("sld_core0", 1.0e-006) |
---|
| 47 | self.model3.setParam("sld_shell1", 1.7e-006) |
---|
| 48 | self.model3.setParam("sld_solv", 6.4e-006) |
---|
| 49 | self.model3.setParam("thick_shell1", 50.0) |
---|
| 50 | |
---|
| 51 | #Compare exp(A=0) to flat (where A_shell is null) function |
---|
| 52 | self.assertEqual(self.model.run(0.1),self.model2.run(0.1)) |
---|
| 53 | self.assertAlmostEqual(self.model2.run(0.1),self.model3.run(0.1),10) |
---|
| 54 | |
---|
| 55 | |
---|
| 56 | |
---|
| 57 | def test_compare_Expsmall_line(self): |
---|
| 58 | """ |
---|
| 59 | Check if Exp function with A_shell-->0 gives the same value |
---|
| 60 | as a linear function |
---|
| 61 | """ |
---|
| 62 | # exp function crosses over to line func as A_shell-->0 |
---|
| 63 | self.model.setParam("A_shell1", 0.000001) |
---|
| 64 | self.model2.setParam("A_shell1", 1) |
---|
| 65 | # change the function to a line function |
---|
| 66 | self.model2.setParam("func_shell1", 1) |
---|
| 67 | |
---|
| 68 | #Compare exp(A=0.000001) to linear (where A_shell is null) function |
---|
| 69 | self.assertAlmostEqual(self.model.run(0.1),self.model2.run(0.1),4) |
---|
| 70 | |
---|
| 71 | def test_compare_time_linear_flat_functions(self): |
---|
| 72 | """ |
---|
| 73 | Compare the calculation time between func=1(linear) , and 2 (step). |
---|
| 74 | """ |
---|
| 75 | from time import time |
---|
| 76 | # using linear func |
---|
| 77 | self.model5.model.setParam("func_shell1", 1) |
---|
| 78 | #input |
---|
| 79 | input = [0.01,0.01] |
---|
| 80 | st = time() |
---|
| 81 | for iter in range(0,100000): |
---|
| 82 | self.model5.model.run(0.01) |
---|
| 83 | time_linear = time()-st |
---|
| 84 | |
---|
| 85 | # using flat function |
---|
| 86 | self.model5.model.setParam("func_shell1", 0) |
---|
| 87 | st = time() |
---|
| 88 | for iter in range(0,100000): |
---|
| 89 | self.model5.model.run(0.01) |
---|
| 90 | time_flat = time()-st |
---|
| 91 | |
---|
| 92 | print "time (linear) = %s, \n time (flat) = %s"% (time_linear,time_flat) |
---|
| 93 | |
---|
| 94 | #Compare time of the calculation: time_linear takes a bit longer |
---|
| 95 | # but they are not much different |
---|
| 96 | self.assertAlmostEqual(time_linear,time_flat,0) |
---|
| 97 | |
---|
| 98 | # this feature removed!!! |
---|
| 99 | """ |
---|
| 100 | def test_compare_Exp0_flat_vesicle(self): |
---|
| 101 | """ |
---|
| 102 | """ |
---|
| 103 | Check if Exp function with A_shell=0 gives the same value as Flat |
---|
| 104 | function of vesicle model when sld_solv=sld_core |
---|
| 105 | """ |
---|
| 106 | """ |
---|
| 107 | print "\n*****Note: All tests (test_compare_Exp0_flat and \ |
---|
| 108 | test_compare_Expsmall_line) were passes since Sept. 18, 2010..." |
---|
| 109 | # Exp: func_shell = 2, Line: func_shell =1 , Flat: func_shell = 0. |
---|
| 110 | # A_shell = The coefficient of the exponential function: exp(A_shell*(r-ro)/thick_shell) |
---|
| 111 | # exp function by default |
---|
| 112 | # exp function crosses over to flat func at A_shell=0 |
---|
| 113 | self.model.setParam("A_shell1", 0) |
---|
| 114 | # set A_shell=1 |
---|
| 115 | self.model2.setParam("A_shell1", 1) |
---|
| 116 | # change the function to flat function |
---|
| 117 | self.model2.setParam("func_shell1", 0) |
---|
| 118 | |
---|
| 119 | # model: set param values as same as the model2 |
---|
| 120 | self.model.setParam("background", 0.0) |
---|
| 121 | self.model.setParam("rad_core0", 100.0) |
---|
| 122 | self.model.setParam("scale", 1.0) |
---|
| 123 | self.model.setParam("sld_core0", 6.36e-006) |
---|
| 124 | self.model.setParam("sld_in_shell1", 5e-007) |
---|
| 125 | self.model.setParam("sld_solv", 6.36e-006) |
---|
| 126 | self.model.setParam("thick_shell1", 30.0) |
---|
| 127 | # model2: set param values as same as the model2 |
---|
| 128 | self.model2.setParam("background", 0.0) |
---|
| 129 | self.model2.setParam("rad_core0", 100.0) |
---|
| 130 | self.model2.setParam("scale", 1.0) |
---|
| 131 | self.model2.setParam("sld_core0", 6.36e-006) |
---|
| 132 | self.model2.setParam("sld_in_shell1", 5e-007) |
---|
| 133 | self.model2.setParam("sld_solv", 6.36e-006) |
---|
| 134 | self.model2.setParam("thick_shell1", 30.0) |
---|
| 135 | #Compare exp(A=0) to flat (where A_shell is null) function |
---|
| 136 | self.assertEqual(self.model.run(0.1),self.model4.run(0.1)) |
---|
| 137 | self.assertEqual(self.model2.run(0.1),self.model4.run(0.1)) |
---|
| 138 | #self.assertAlmostEqual(self.model2.run(0.1),self.model3.run(0.1),10) |
---|
| 139 | """ |
---|
| 140 | if __name__ == '__main__': |
---|
| 141 | unittest.main() |
---|