Skip to content

Commit

Permalink
Increase code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbbeyer committed Jun 13, 2024
1 parent 580d96a commit 13bc722
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
3 changes: 0 additions & 3 deletions pyMBE.py
Original file line number Diff line number Diff line change
Expand Up @@ -1924,9 +1924,6 @@ def generate_random_points_in_a_sphere(self, center, radius, n_samples, on_surfa
Returns:
samples(`list`): Coordinates of the sample points inside the hypersphere.
Note:
- Algorithm from: https://baezortega.github.io/2018/10/14/hypersphere-sampling/
"""
# initial values
center=np.array(center)
Expand Down
14 changes: 14 additions & 0 deletions testsuite/calculate_net_charge_unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
espresso_system=espresso_system,
use_default_bond=True,)

# Check the case where the returned charge has a dimension
charge_map=pmb.calculate_net_charge(molecule_name=molecule_name,
espresso_system=espresso_system)

Expand All @@ -91,6 +92,19 @@
8: 0.0*pmb.units.Quantity(1,'reduced_charge'),
9: 0.0*pmb.units.Quantity(1,'reduced_charge')})

# Check the case where the returned charge is dimensionless
charge_map=pmb.calculate_net_charge(molecule_name=molecule_name,
espresso_system=espresso_system,
dimensionless=True)

# Check mean charge
np.testing.assert_equal(charge_map["mean"], 2.0)
# Check molecule charge map
np.testing.assert_equal(charge_map["molecules"],{0: 2.0, 1: 2.0})
# Check residue charge map
np.testing.assert_equal(charge_map["residues"],{0: 1.0, 1: 1.0, 2: 0.0, 3: 0.0, 4: 0.0, 5: 1.0, 6: 1.0, 7: 0.0, 8: 0.0, 9: 0.0})


print("*** Unit test passed ***")
print("*** Unit test: check that calculate_net_charge raises a ValueError if one provides the name of an object that is not a molecule ***")
input_parameters={"molecule_name":"R1",
Expand Down
17 changes: 17 additions & 0 deletions testsuite/generate_coordinates_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,21 @@ def test_arrays_less_equal(arr1, arr2, rtol=1e-7, atol=1e-7):
test_arrays_less_equal(np.linalg.norm(samples-np.asarray(center), axis=1), outer_radius)
test_arrays_less_equal(inner_radius, np.linalg.norm(samples-np.asarray(center), axis=1))
print("*** Unit test passed ***")
print("*** Check that the function raises a ValueError if the user provides a negative radius ***")
np.testing.assert_raises(ValueError,
pmb.generate_coordinates_outside_sphere,
center=center,
radius=-1.0,
max_dist=5.0,
n_samples=1)
print("*** Unit test passed ***")
print("*** Check that the function raises a ValueError if the user provides a larger inner radius than outer radius ***")
np.testing.assert_raises(ValueError,
pmb.generate_coordinates_outside_sphere,
center=center,
radius=10.0,
max_dist=5.0,
n_samples=1)
print("*** Unit test passed ***")

print("*** All unit tests passed ***\n")

0 comments on commit 13bc722

Please sign in to comment.