Skip to content

Commit

Permalink
Error analysis tutorial: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
biermanncarl committed May 25, 2021
1 parent f319828 commit 2ed75e5
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
2 changes: 2 additions & 0 deletions testsuite/scripts/tutorials/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ add_custom_target(
${TUTORIALS_DIR} DEPENDS tutorials_python)

tutorial_test(FILE test_lennard_jones.py)
tutorial_test(FILE test_error_analysis_part1.py)
tutorial_test(FILE test_error_analysis_part2.py)
tutorial_test(FILE test_charged_system.py)
tutorial_test(FILE test_lattice_boltzmann_part2.py)
tutorial_test(FILE test_lattice_boltzmann_part3.py SUFFIX rouse)
Expand Down
36 changes: 36 additions & 0 deletions testsuite/scripts/tutorials/test_error_analysis_part1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright (C) 2021 The ESPResSo project
#
# This file is part of ESPResSo.
#
# ESPResSo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ESPResSo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import unittest as ut
import importlib_wrapper
import numpy as np

tutorial, skipIfMissingFeatures = importlib_wrapper.configure_and_import(
filepath="@TUTORIALS_DIR@/error_analysis/error_analysis_part1.py",
gpu=False,
random_seeds=True)

@skipIfMissingFeatures
class Tutorial(ut.TestCase):

def test(self):
self.assertAlmostEqual(tutorial.fit_params[2],0.024,delta=0.002)
self.assertAlmostEqual(tutorial.avg,13.35,delta=0.1)


if __name__ == "__main__":
ut.main()
39 changes: 39 additions & 0 deletions testsuite/scripts/tutorials/test_error_analysis_part2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright (C) 2021 The ESPResSo project
#
# This file is part of ESPResSo.
#
# ESPResSo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ESPResSo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import unittest as ut
import importlib_wrapper
import numpy as np

tutorial, skipIfMissingFeatures = importlib_wrapper.configure_and_import(
filepath="@TUTORIALS_DIR@/error_analysis/error_analysis_part2.py",
gpu=False,
random_seeds=True)

@skipIfMissingFeatures
class Tutorial(ut.TestCase):

def test(self):
self.assertAlmostEqual(tutorial.sem,0.025,delta=0.002)
self.assertAlmostEqual(tutorial.N_eff,7700,delta=500)
self.assertAlmostEqual(tutorial.tau_int,6.6,delta=0.4)
# the point of the following value in the tutorial is that it is very inaccurate, thus the high tolerance
self.assertAlmostEqual(tutorial.sem_2,0.37,delta=0.08)


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

0 comments on commit 2ed75e5

Please sign in to comment.