Skip to content

Commit

Permalink
Update tests to match new ref1d
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikjacobsenfys committed Jan 7, 2025
1 parent ca05ac0 commit aeebf5d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies = [
"easyscience>=1.2.0",
"scipp>=23.12.0",
"refnx>=0.1.15",
"refl1d>=0.8.14",
"refl1d",
"orsopy>=0.0.4",
"pint==0.23", # Only to ensure that unit is reported as dimensionless rather than empty string
"xhtml2pdf>=0.2.16"
Expand Down
5 changes: 3 additions & 2 deletions tests/sample/assemblies/test_surfactant_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def test_constain_solvent_roughness(self):

def test_dict_repr(self):
p = SurfactantLayer()

assert p._dict_repr == {
'EasySurfactantLayer': {
'head_layer': {
Expand All @@ -125,9 +126,9 @@ def test_dict_repr(self):
'material': {
'C32D64 in Air': {
'solvent_fraction': '0.000 dimensionless',
'sld': '8.297e-6 1/Å^2',
'sld': '8.292e-6 1/Å^2',
'isld': '0.000e-6 1/Å^2',
'material': {'C32D64': {'sld': '8.297e-6 1/Å^2', 'isld': '0.000e-6 1/Å^2'}},
'material': {'C32D64': {'sld': '8.292e-6 1/Å^2', 'isld': '0.000e-6 1/Å^2'}},
'solvent': {'Air': {'sld': '0.000e-6 1/Å^2', 'isld': '0.000e-6 1/Å^2'}},
}
},
Expand Down
16 changes: 8 additions & 8 deletions tests/sample/elements/layers/test_layer_area_per_molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_default(self):
assert p.roughness.value == 3.3
assert str(p.roughness.unit) == 'Å'
assert p.roughness.fixed is True
assert_almost_equal(p.material.sld, 2.2691419)
assert_almost_equal(p.material.sld, 2.268770124481328)
assert_almost_equal(p.material.isld, 0)
assert p.material.name == 'C10H18NO8P in D2O'
assert p.solvent.sld.value == 6.36
Expand Down Expand Up @@ -66,18 +66,18 @@ def test_from_pars_constraint(self):
)
assert p.molecular_formula == 'C8O10H12P'
assert p.area_per_molecule == 50
assert_almost_equal(p.material.sld, 0.31513666667)
assert_almost_equal(p.material.sld, 0.31494833333333333)
assert p.thickness.value == 12
assert p.roughness.value == 2
assert p.solvent.sld.value == -0.561
assert p.solvent.isld.value == 0
assert p.solvent_fraction == 0.5
p.area_per_molecule = 30
assert p.area_per_molecule == 30
assert_almost_equal(p.material.sld, 0.712227778)
assert_almost_equal(p.material.sld, 0.7119138888888887)
p.thickness.value = 10
assert p.thickness.value == 10
assert_almost_equal(p.material.sld, 0.910773333)
assert_almost_equal(p.material.sld, 0.9103966666666665)

def test_solvent_change(self):
h2o = Material(-0.561, 0, 'H2O')
Expand All @@ -93,7 +93,7 @@ def test_solvent_change(self):
assert p.molecular_formula == 'C8O10H12P'
assert p.area_per_molecule == 50
print(p.material)
assert_almost_equal(p.material.sld, 0.31513666667)
assert_almost_equal(p.material.sld, 0.31494833333333333)
assert p.thickness.value == 12
assert p.roughness.value == 2
assert p.solvent.sld.value == -0.561
Expand All @@ -103,7 +103,7 @@ def test_solvent_change(self):
p.solvent = d2o
assert p.molecular_formula == 'C8O10H12P'
assert p.area_per_molecule == 50
assert_almost_equal(p.material.sld, 3.7631366667)
assert_almost_equal(p.material.sld, 3.762948333333333)
assert p.thickness.value == 12
assert p.roughness.value == 2
assert p.solvent.sld.value == 6.335
Expand All @@ -123,7 +123,7 @@ def test_molecular_formula_change(self):
)
assert p.molecular_formula == 'C8O10H12P'
assert p.area_per_molecule == 50
assert_almost_equal(p.material.sld, 0.31513666667)
assert_almost_equal(p.material.sld, 0.31494833333333333)
assert p.thickness.value == 12
assert p.roughness.value == 2

Expand All @@ -134,7 +134,7 @@ def test_molecular_formula_change(self):
p.molecular_formula = 'C8O10D12P'
assert p.molecular_formula == 'C8O10D12P'
assert p.area_per_molecule == 50
assert_almost_equal(p.material.sld, 1.3566266666666666)
assert_almost_equal(p.material.sld, 1.3558483333333333)
assert p.thickness.value == 12
assert p.roughness.value == 2
assert p.solvent.sld.value == -0.561
Expand Down
10 changes: 5 additions & 5 deletions tests/sample/elements/materials/test_material_density.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,25 @@ def test_default(self):
def test_default_constraint(self):
p = MaterialDensity()
assert p.density.value == 2.33
assert_almost_equal(p.sld.value, 2.073705382)
assert_almost_equal(p.sld.value, 2.0737423003838087)
p.density.value = 2
assert_almost_equal(p.sld.value, 1.780004619)
assert_almost_equal(p.sld.value, 1.7800363093423253)

def test_from_pars(self):
p = MaterialDensity('Co', 8.9, 'Cobalt')
assert p.density.value == 8.9
assert_almost_equal(p.sld.value, 2.2645412328256)
assert_almost_equal(p.sld.value,2.264541463379026)
assert p.chemical_structure == 'Co'

def test_chemical_structure_change(self):
p = MaterialDensity('Co', 8.9, 'Cobolt')
assert p.density.value == 8.9
assert_almost_equal(p.sld.value, 2.2645412328256)
assert_almost_equal(p.sld.value, 2.264541463379026)
assert_almost_equal(p.isld.value, 0.0)
assert p.chemical_structure == 'Co'
p.chemical_structure = 'B'
assert p.density.value == 8.9
assert_almost_equal(p.sld.value, 4.820107844970)
assert_almost_equal(p.sld.value, 4.82010833570636)
assert_almost_equal(p.isld.value, -0.19098540517806603)
assert p.chemical_structure == 'B'

Expand Down
2 changes: 1 addition & 1 deletion tests/special/test_calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_neutron_scattering_length_B(self) -> None:

def test_molecular_weight(self) -> None:
a = molecular_weight('H2O')
assert_almost_equal(a, 18.01528)
assert_almost_equal(a, 18.015)

def test_area_per_molecule_to_sld(self) -> None:
a = area_per_molecule_to_scattering_length_density(2, 1, 0.5)
Expand Down

0 comments on commit aeebf5d

Please sign in to comment.