@@ -191,25 +191,63 @@ def test_get_package_info(monkeypatch, inputs, expected):
191191 assert actual_metadata == expected
192192
193193
194- params_mu = [
195- # C1: user didn't specify density or packing fraction
196- ({"sample_composition" : "H2O" , "energy" : 10000 , "density" : None , "packing_fraction" : 1 }, 0.5330 ),
197- # C2: user specified packing fraction only
198- ({"sample_composition" : "H2O" , "energy" : 10000 , "density" : None , "packing_fraction" : 0.5 }, 0.2665 ),
199- # C3: user specified density only
200- ({"sample_composition" : "H2O" , "energy" : 10000 , "density" : 0.997 , "packing_fraction" : 1 }, 0.5330 ),
201- ({"sample_composition" : "H2O" , "energy" : 10000 , "density" : 0.4985 , "packing_fraction" : 1 }, 0.2665 ),
202- # C4: user specified a standard density and a packing fraction
203- ({"sample_composition" : "H2O" , "energy" : 10000 , "density" : 0.997 , "packing_fraction" : 0.5 }, 0.2665 ),
204- ]
205-
206-
207- @pytest .mark .parametrize ("inputs, expected" , params_mu )
208- def test_compute_mu_using_xraydb (inputs , expected ):
194+ @pytest .mark .parametrize (
195+ "inputs, expected_mu" ,
196+ [
197+ # Test whether the function returns the correct mu
198+ ( # C1: No density or packing fraction provided, expect to compute mu based on standard density
199+ {
200+ "sample_composition" : "H2O" ,
201+ "energy" : 10000 ,
202+ "density" : None ,
203+ "packing_fraction" : 1 ,
204+ },
205+ 0.5330 ,
206+ ),
207+ ( # C2: Packing fraction (=0.5) provided only, expect to return half of mu based on standard density
208+ {
209+ "sample_composition" : "H2O" ,
210+ "energy" : 10000 ,
211+ "density" : None ,
212+ "packing_fraction" : 0.5 ,
213+ },
214+ 0.2665 ,
215+ ),
216+ ( # C3: Density provided only, expect to compute mu based on density
217+ # 1. Standard density provided, expect to return the same mu as C1
218+ {
219+ "sample_composition" : "H2O" ,
220+ "energy" : 10000 ,
221+ "density" : 0.997 ,
222+ "packing_fraction" : 1 ,
223+ },
224+ 0.5330 ,
225+ ),
226+ ( # 2. Lower density for H2O (half of standard), expect to return half of mu based on standard density
227+ {
228+ "sample_composition" : "H2O" ,
229+ "energy" : 10000 ,
230+ "density" : 0.4985 ,
231+ "packing_fraction" : 1 ,
232+ },
233+ 0.2665 ,
234+ ),
235+ ( # C4: Both standard density and packing fraction are provided, expect to compute the same mu as C2
236+ {
237+ "sample_composition" : "H2O" ,
238+ "energy" : 10000 ,
239+ "density" : 0.997 ,
240+ "packing_fraction" : 0.5 ,
241+ },
242+ 0.2665 ,
243+ ),
244+ ],
245+ )
246+ def test_compute_mu_using_xraydb (inputs , expected_mu ):
209247 actual_mu = compute_mu_using_xraydb (
210248 inputs ["sample_composition" ],
211249 inputs ["energy" ],
212250 density = inputs ["density" ],
213251 packing_fraction = inputs ["packing_fraction" ],
214252 )
215- assert actual_mu == pytest .approx (expected , rel = 0.01 , abs = 0.1 )
253+ assert actual_mu == pytest .approx (expected_mu , rel = 0.01 , abs = 0.1 )
0 commit comments