@@ -171,59 +171,61 @@ def test_get_package_info(monkeypatch, inputs, expected):
171171 "inputs, expected_mu" ,
172172 [
173173 # Test whether the function returns the correct mu
174- ( # C1: No density or packing fraction (only for known material), expect to get mu from database
174+ ( # C1: Composition, energy, and mass density provided, expect to get mu based on mass density
175+ # 1. Fully dense mass density
176+ {"sample_composition" : "quartz" , "energy" : 10 , "sample_mass_density" : 2.65 },
177+ 5.0368 ,
178+ ),
179+ ( # 2. Measured mass density
175180 {
176- "sample_composition" : "H2O" ,
177- "energy" : 10 ,
181+ "sample_composition" : "ZrO2" ,
182+ "energy" : 17.445 ,
183+ "sample_mass_density" : 1.009 ,
178184 },
179- 0.5330 ,
185+ 1.2522 ,
180186 ),
181- ( # C2: Packing fraction (=0.5) provided only (only for known material)
187+ ( # C2: Composition, energy, and packing fraction provided, expect to get mu based on packing fraction
188+ # Reuse pattern from C1.1 here
182189 {
183- "sample_composition" : "H2O " ,
190+ "sample_composition" : "quartz " ,
184191 "energy" : 10 ,
185192 "packing_fraction" : 0.5 ,
186193 },
187- 0.2665 ,
194+ 2.5184 ,
188195 ),
189- ( # C3: Density provided only, expect to compute mu based on it
190- # 1. Known material
196+ ],
197+ )
198+ def test_compute_mu_using_xraydb (inputs , expected_mu ):
199+ actual_mu = compute_mu_using_xraydb (** inputs )
200+ assert actual_mu == pytest .approx (expected_mu , rel = 1e-6 , abs = 1e-4 )
201+
202+
203+ @pytest .mark .parametrize (
204+ "inputs" ,
205+ [
206+ # Test when the function raises ValueError
207+ # C1: Both mass density and packing fraction are provided
208+ (
191209 {
192- "sample_composition" : "H2O " ,
210+ "sample_composition" : "quartz " ,
193211 "energy" : 10 ,
194- "density " : 0.987 ,
195- } ,
196- 0.5330 ,
212+ "sample_mass_density " : 2.65 ,
213+ "packing_fraction" : 1 ,
214+ }
197215 ),
198- ( # 2. Unknown material
199- {
200- "sample_composition" : "ZrO2" ,
201- "energy" : 17 ,
202- "density" : 1.009 ,
203- },
204- 1.252 ,
205- ),
206- ( # C4: Both density and packing fraction are provided, expect to compute mu based on both
207- # 1. Known material
216+ # C2: None of mass density or packing fraction are provided
217+ (
208218 {
209- "sample_composition" : "H2O " ,
219+ "sample_composition" : "quartz " ,
210220 "energy" : 10 ,
211- "density" : 0.997 ,
212- "packing_fraction" : 0.5 ,
213- },
214- 0.2665 ,
215- ),
216- ( # 2. Unknown material
217- {
218- "sample_composition" : "ZrO2" ,
219- "energy" : 17 ,
220- "density" : 1.009 ,
221- "packing_fraction" : 0.5 ,
222- },
223- 0.626 ,
221+ }
224222 ),
225223 ],
226224)
227- def test_compute_mu_using_xraydb (inputs , expected_mu ):
228- actual_mu = compute_mu_using_xraydb (** inputs )
229- assert actual_mu == pytest .approx (expected_mu , rel = 0.01 , abs = 0.1 )
225+ def test_compute_mu_using_xraydb_bad (inputs ):
226+ with pytest .raises (
227+ ValueError ,
228+ match = "You must specify either sample_mass_density or packing_fraction, but not both. "
229+ "Please rerun specifying only one." ,
230+ ):
231+ compute_mu_using_xraydb (** inputs )
0 commit comments