Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test criteria for the charged_system-2 tutorial #3239

Merged
merged 10 commits into from
Oct 18, 2019
2 changes: 1 addition & 1 deletion doc/sphinx/analysis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ which the observable should take into account.

The current value of an observable can be obtained using its calculate()-method::

print(par_pos.calculate())
print(part_pos.calculate())

.. _Available observables:

Expand Down
17 changes: 17 additions & 0 deletions testsuite/scripts/tutorials/test_02-charged_system-2.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import unittest as ut
import importlib_wrapper
import numpy as np

tutorial, skipIfMissingFeatures = importlib_wrapper.configure_and_import(
"@TUTORIALS_DIR@/02-charged_system/02-charged_system-2.py",
Expand All @@ -27,6 +28,22 @@
class Tutorial(ut.TestCase):
system = tutorial.system

def test_distribution(self):
"""
checks if the particle distribution is within the box and
the mean of the distribution matches with a reference value
"""
avg = 0
for i in range(1, 3):
pos = np.flatnonzero(tutorial.res[:, i] > 0)
self.assertGreater(tutorial.res[pos[0], 0], tutorial.wall_margin)
self.assertLess(tutorial.res[pos[-1], 0],
tutorial.box_z - tutorial.wall_margin)

avg += np.mean(tutorial.res[pos, i])
avg *= 0.5
self.assertAlmostEqual(avg, 0.0148, delta=5e-4)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the origin of the magic number? Can you place the calculation in the script or refer to a source where it is published?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the mean particle density per bin of the histogram which i originally planned to compare against each bin value, which is not possible without sufficient sampling. I just noticed that this mean value is constant anyways, which is only fluctuating because i neglected the 0s. I will remove this comparison since it does not give any insight into the system.



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