Skip to content

Commit

Permalink
update todo and test file
Browse files Browse the repository at this point in the history
  • Loading branch information
ireaml committed Sep 6, 2023
1 parent f85c6a2 commit 1598b54
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
4 changes: 4 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
- [x] Update `tools.spherical_average` and `plotting.plot_on_site_potential` to handle different output files rather than just `LOCPOT`.
- [x] Format line length of docstrings to follow PEP conventions
- [x] Automatically publish version to pypi when a new release is made on GitHub
- [ ] Check which functions are not currently tested in `unit_tests.py` (for instance
`plot_field_at_point`, `plot_plane_field`, `energy_band_alignment_diagram` are not currently tested).
Can use matplotlib to compare figures as done [here](https://github.com/SMTG-UCL/ShakeNBreak/blob/develop/tests/test_plotting.py#L1038). Add tests for these functions
- [ ] Add [codecov](https://docs.codecov.com/docs#step-5-get-coverage-analysis-from-codecov) badge to README to see how many lines of code are tested
- [ ] Add linting workflow (similar to [this](https://github.com/SMTG-UCL/ShakeNBreak/blob/develop/.github/workflows/lint.yml))
- [ ] Update conda installation instructions (need to update current conda package, https://anaconda.org/hcc/macrodensity)
- [ ] Automatically get lattice vector from `POSCAR`` file, rather than taking it from user input
49 changes: 27 additions & 22 deletions tests/unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def tearDown(self):


class TestOtherReadingFunctions(unittest.TestCase):

def test_read_vasp_classic(self):
"""Test the function for reading CHGCAR/LOCPOT"""
chgcar = pkg_resources.resource_filename(
Expand Down Expand Up @@ -207,9 +208,30 @@ def test_ipr(self):
md.utils.inverse_participation_ratio(dens), 1.407e-5
)

def test_macroscopic_average(self):
"""Test the macroscopic averaging function"""
f = 2.0
fs = 100
x = np.arange(fs)
potential = [
np.sin(2 * np.pi * f * (i / float(fs))) for i in np.arange(fs)
]
macro = md.macroscopic_average(potential, 50, 1)
self.assertAlmostEqual(macro[20], 0.0)

def test_spherical_average(self):
"""Tests the spherical_average function"""
Locpot = pkg_resources.resource_filename(
__name__, path_join("../tests", "LOCPOT.test")
)
out = md.spherical_average(
cube_size=[2, 2, 2], cube_origin=[0.5, 0.5, 0.5], input_file=Locpot
)
self.assertAlmostEqual(out, (6.5579496029375, 1.8665165271901357e-05))


class TestGeometryFunctions(unittest.TestCase):
"""Test the functions that do geometry and trig"""
"""Test the functions that do geometry and trigonometry"""

def test_gradient_magnitude(self):
"""Test the function for returning the magnitude of gradient at a voxel"""
Expand All @@ -223,17 +245,6 @@ def test_gradient_magnitude(self):
self.assertEqual(magnitudes[1, 1, 1], 1.7320508075688772)
self.assertEqual(magnitudes[2, 2, 2], 6.9282032302755088)

def test_macroscopic_average(self):
"""Test the macroscopic averaging function"""
f = 2.0
fs = 100
x = np.arange(fs)
potential = [
np.sin(2 * np.pi * f * (i / float(fs))) for i in np.arange(fs)
]
macro = md.macroscopic_average(potential, 50, 1)
self.assertAlmostEqual(macro[20], 0.0)

def test_vector_2_abscissa(self):
"""Test the vector_2_abscissa function"""
abscissa = md.vector_2_abscissa([5, 6, 7], 10, 0.2, 0.2, 0.2)
Expand Down Expand Up @@ -278,6 +289,7 @@ def test_GCD_List(self):


class TestConvenienceFunctions(unittest.TestCase):

def test_bulk_interstitial_alignment(self):
"""Tests the bulk_interstitial_alignment function"""
Locpot = pkg_resources.resource_filename(
Expand Down Expand Up @@ -318,16 +330,9 @@ def test_moving_cube(self):
self.addCleanup(os.remove, "potential_variation.csv")
self.addCleanup(os.remove, "potential_variation.png")

def test_spherical_average(self):
"""Tests the spherical_average function"""
Locpot = pkg_resources.resource_filename(
__name__, path_join("../tests", "LOCPOT.test")
)
out = md.spherical_average(
cube_size=[2, 2, 2], cube_origin=[0.5, 0.5, 0.5], input_file=Locpot
)
self.assertAlmostEqual(out, (6.5579496029375, 1.8665165271901357e-05))

class TestPlottingFunctions(unittest.TestCase):

def test_plot_planar_average(self):
"""Tests the plot_planar_average function"""
locpot = pkg_resources.resource_filename(
Expand Down Expand Up @@ -412,7 +417,7 @@ def test_plot_planar_cube(self):
self.assertEqual(dfpot["Planar"].tolist()[-1], -0.581089179258661)
self.addCleanup(os.remove, "planar_average.csv")
self.addCleanup(os.remove, "planar_average.png")


if __name__ == "__main__":
unittest.main()

0 comments on commit 1598b54

Please sign in to comment.