[89108a0] | 1 | |
---|
| 2 | import unittest |
---|
| 3 | from sans.calculator.sld_calculator import SldCalculator |
---|
| 4 | _SCALE = 1e-6 |
---|
| 5 | |
---|
| 6 | |
---|
| 7 | class TestH2O(unittest.TestCase): |
---|
| 8 | """ |
---|
| 9 | Sld calculator test for H2O |
---|
| 10 | """ |
---|
| 11 | |
---|
| 12 | def setUp(self): |
---|
| 13 | """Inititialze variables""" |
---|
| 14 | # the calculator default value for wavelength is 6 |
---|
| 15 | self.calculator = SldCalculator() |
---|
| 16 | user_formula = "H2O" |
---|
| 17 | self.calculator.set_value(user_formula=user_formula, |
---|
| 18 | density=1.0, wavelength=6.0) |
---|
| 19 | def test_neutron_sld(self): |
---|
| 20 | """ |
---|
| 21 | check the output of the neutron sld calculator |
---|
| 22 | """ |
---|
| 23 | #Compute incoherence , absorption, and incoherence |
---|
| 24 | coh, abs, incoh = self.calculator.calculate_neutron_sld() |
---|
| 25 | #Compute absortion imaginary part id available |
---|
| 26 | coh_im = self.calculator.calculate_coherence_im() |
---|
| 27 | self.assertAlmostEquals(coh * _SCALE, -5.6e-7, 1) |
---|
| 28 | self.assertAlmostEquals(coh_im * _SCALE, 0) |
---|
| 29 | |
---|
| 30 | def test_absorption(self): |
---|
| 31 | """ |
---|
| 32 | test absorption result |
---|
| 33 | """ |
---|
| 34 | #Compute incoherence , absorption, and incoherence |
---|
| 35 | coh, abs, incoh = self.calculator.calculate_neutron_sld() |
---|
| 36 | #test absorption value |
---|
| 37 | self.assertAlmostEquals(abs, 0.0741, 2) |
---|
| 38 | |
---|
| 39 | def test_incoherence(self): |
---|
| 40 | """ |
---|
| 41 | test incoherence |
---|
| 42 | """ |
---|
| 43 | #Compute incoherence , absorption, and incoherence |
---|
| 44 | coh, abs, incoh = self.calculator.calculate_neutron_sld() |
---|
| 45 | self.assertAlmostEquals(incoh, 5.62) |
---|
| 46 | |
---|
| 47 | def test_cu_xray(self): |
---|
| 48 | """ |
---|
| 49 | test Cu sld |
---|
| 50 | """ |
---|
| 51 | #Compute x-ray sld of Cu |
---|
| 52 | cu_reel, cu_im = self.calculator.calculate_xray_sld("Cu") |
---|
| 53 | #test Cu sld |
---|
| 54 | self.assertAlmostEquals(cu_reel * _SCALE, 9.46e-6, 1) |
---|
| 55 | self.assertAlmostEquals(cu_im * _SCALE, 3.01e-8) |
---|
| 56 | |
---|
| 57 | def test_mo_xray(self): |
---|
| 58 | """ |
---|
| 59 | test Mo sld |
---|
| 60 | """ |
---|
| 61 | #Compute x-ray sld of Mo |
---|
| 62 | mo_reel, mo_im = self.calculator.calculate_xray_sld("Mo") |
---|
| 63 | #test Mo sld |
---|
| 64 | self.assertAlmostEquals(mo_reel * _SCALE, 9.43e-6) |
---|
| 65 | self.assertAlmostEquals(mo_im * _SCALE, 5.65e-7,1) |
---|
| 66 | |
---|
| 67 | def test_length(self): |
---|
| 68 | """ |
---|
| 69 | test length |
---|
| 70 | """ |
---|
| 71 | #Compute incoherence , absorption, and incoherence |
---|
| 72 | coh, abs, incoh = self.calculator.calculate_neutron_sld() |
---|
| 73 | #Compute neutron 1/e length |
---|
| 74 | length = self.calculator.calculate_length() |
---|
| 75 | #Test length |
---|
| 76 | self.assertAlmostEquals(length, 0.17755) |
---|
| 77 | |
---|
| 78 | class TestD2O(unittest.TestCase): |
---|
| 79 | """ |
---|
| 80 | Sld calculator test for D2O |
---|
| 81 | """ |
---|
| 82 | |
---|
| 83 | def setUp(self): |
---|
| 84 | """Inititialze variables""" |
---|
| 85 | # the calculator default value for wavelength is 6 |
---|
| 86 | self.calculator = SldCalculator() |
---|
| 87 | user_formula = "D2O" |
---|
| 88 | self.calculator.set_value(user_formula=user_formula, |
---|
| 89 | density=1.1, wavelength=6.0) |
---|
| 90 | def test_neutron_sld(self): |
---|
| 91 | """ |
---|
| 92 | check the output of the neutron sld calculator |
---|
| 93 | """ |
---|
| 94 | #Compute incoherence , absorption, and incoherence |
---|
| 95 | coh, abs, incoh = self.calculator.calculate_neutron_sld() |
---|
| 96 | #Compute absortion imaginary part id available |
---|
| 97 | coh_im = self.calculator.calculate_coherence_im() |
---|
| 98 | self.assertAlmostEquals(coh * _SCALE, 6.33e-6, 1) |
---|
| 99 | self.assertAlmostEquals(coh_im * _SCALE, 0) |
---|
| 100 | |
---|
| 101 | def test_absorption(self): |
---|
| 102 | """ |
---|
| 103 | test absorption result |
---|
| 104 | """ |
---|
| 105 | #Compute incoherence , absorption, and incoherence |
---|
| 106 | coh, abs, incoh = self.calculator.calculate_neutron_sld() |
---|
| 107 | #test absorption value |
---|
| 108 | self.assertAlmostEquals(abs, 1.35e-4, 2) |
---|
| 109 | |
---|
| 110 | def test_incoherence(self): |
---|
| 111 | """ |
---|
| 112 | test incoherence |
---|
| 113 | """ |
---|
| 114 | #Compute incoherence , absorption, and incoherence |
---|
| 115 | coh, abs, incoh = self.calculator.calculate_neutron_sld() |
---|
| 116 | self.assertAlmostEquals(incoh, 0.138, 2) |
---|
| 117 | |
---|
| 118 | def test_cu_xray(self): |
---|
| 119 | """ |
---|
| 120 | test Cu sld |
---|
| 121 | """ |
---|
| 122 | #Compute x-ray sld of Cu |
---|
| 123 | cu_reel, cu_im = self.calculator.calculate_xray_sld("Cu") |
---|
| 124 | #test Cu sld |
---|
| 125 | self.assertAlmostEquals(cu_reel * _SCALE, 9.36e-6, 1) |
---|
| 126 | self.assertAlmostEquals(cu_im * _SCALE, 2.98e-8) |
---|
| 127 | |
---|
| 128 | def test_mo_xray(self): |
---|
| 129 | """ |
---|
| 130 | test Mo sld |
---|
| 131 | """ |
---|
| 132 | #Compute x-ray sld of Mo |
---|
| 133 | mo_reel, mo_im = self.calculator.calculate_xray_sld("Mo") |
---|
| 134 | #test Mo sld |
---|
| 135 | self.assertAlmostEquals(mo_reel * _SCALE, 9.33e-6) |
---|
| 136 | self.assertAlmostEquals(mo_im * _SCALE, 5.59e-9,1) |
---|
| 137 | |
---|
| 138 | def test_length(self): |
---|
| 139 | """ |
---|
| 140 | test length |
---|
| 141 | """ |
---|
| 142 | #Compute incoherence , absorption, and incoherence |
---|
| 143 | coh, abs, incoh = self.calculator.calculate_neutron_sld() |
---|
| 144 | #Compute neutron 1/e length |
---|
| 145 | length = self.calculator.calculate_length() |
---|
| 146 | #Test length |
---|
| 147 | self.assertAlmostEquals(length, 1.549) |
---|
| 148 | |
---|
| 149 | class TestCd(unittest.TestCase): |
---|
| 150 | """ |
---|
| 151 | Sld calculator test for Cd |
---|
| 152 | """ |
---|
| 153 | |
---|
| 154 | def setUp(self): |
---|
| 155 | """Inititialze variables""" |
---|
| 156 | # the calculator default value for wavelength is 6 |
---|
| 157 | self.calculator = SldCalculator() |
---|
| 158 | user_formula = "Cd" |
---|
| 159 | self.calculator.set_value(user_formula=user_formula, |
---|
| 160 | density=4.0, wavelength=6.0) |
---|
| 161 | def test_neutron_sld(self): |
---|
| 162 | """ |
---|
| 163 | check the output of the neutron sld calculator |
---|
| 164 | """ |
---|
| 165 | #Compute incoherence , absorption, and incoherence |
---|
| 166 | coh, abs, incoh = self.calculator.calculate_neutron_sld() |
---|
| 167 | #Compute absortion imaginary part id available |
---|
| 168 | coh_im = self.calculator.calculate_coherence_im() |
---|
| 169 | self.assertAlmostEquals(coh * _SCALE, 1.04e-6, 1) |
---|
| 170 | self.assertAlmostEquals(coh_im * _SCALE, -1.5e-7, 1) |
---|
| 171 | |
---|
| 172 | def test_absorption(self): |
---|
| 173 | """ |
---|
| 174 | test absorption result |
---|
| 175 | """ |
---|
| 176 | #Compute incoherence , absorption, and incoherence |
---|
| 177 | coh, abs, incoh = self.calculator.calculate_neutron_sld() |
---|
| 178 | #test absorption value |
---|
| 179 | self.assertAlmostEquals(abs, 180.0, 1) |
---|
| 180 | |
---|
| 181 | def test_incoherence(self): |
---|
| 182 | """ |
---|
| 183 | test incoherence |
---|
| 184 | """ |
---|
| 185 | #Compute incoherence , absorption, and incoherence |
---|
| 186 | coh, abs, incoh = self.calculator.calculate_neutron_sld() |
---|
| 187 | self.assertAlmostEquals(incoh, 0.0754, 2) |
---|
| 188 | |
---|
| 189 | def test_cu_xray(self): |
---|
| 190 | """ |
---|
| 191 | test Cu sld |
---|
| 192 | """ |
---|
| 193 | #Compute x-ray sld of Cu |
---|
| 194 | cu_reel, cu_im = self.calculator.calculate_xray_sld("Cu") |
---|
| 195 | #test Cu sld |
---|
| 196 | self.assertAlmostEquals(cu_reel * _SCALE, 2.89e-5, 1) |
---|
| 197 | self.assertAlmostEquals(cu_im * _SCALE, 2.81e-6) |
---|
| 198 | |
---|
| 199 | def test_mo_xray(self): |
---|
| 200 | """ |
---|
| 201 | test Mo sld |
---|
| 202 | """ |
---|
| 203 | #Compute x-ray sld of Mo |
---|
| 204 | mo_reel, mo_im = self.calculator.calculate_xray_sld("Mo") |
---|
| 205 | #test Mo sld |
---|
| 206 | self.assertAlmostEquals(mo_reel * _SCALE, 2.84e-5) |
---|
| 207 | self.assertAlmostEquals(mo_im * _SCALE, 7.26e-7,1) |
---|
| 208 | |
---|
| 209 | def test_length(self): |
---|
| 210 | """ |
---|
| 211 | test length |
---|
| 212 | """ |
---|
| 213 | #Compute incoherence , absorption, and incoherence |
---|
| 214 | coh, abs, incoh = self.calculator.calculate_neutron_sld() |
---|
| 215 | #Compute neutron 1/e length |
---|
| 216 | length = self.calculator.calculate_length() |
---|
| 217 | #Test length |
---|
| 218 | self.assertAlmostEquals(length, 0.005551) |
---|
| 219 | |
---|
| 220 | if __name__ == '__main__': |
---|
| 221 | unittest.main() |
---|