Skip to content

Commit

Permalink
tests: Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Alexander Reinauer <[email protected]>
  • Loading branch information
jngrad and reinaual committed Mar 26, 2021
1 parent 5b28694 commit b069c6a
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 51 deletions.
3 changes: 0 additions & 3 deletions testsuite/python/dawaanr-and-bh-gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ def test(self):
self.system.actors.add(bh_gpu)
self.system.integrator.run(steps=0, recalc_forces=True)

bhgpu_f = []
bhgpu_t = []

bhgpu_f = np.copy(self.system.part[:].f)
bhgpu_t = np.copy(self.system.part[:].torque_lab)
bhgpu_e = self.system.analysis.energy()["total"]
Expand Down
10 changes: 5 additions & 5 deletions testsuite/python/field_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from itertools import product

import unittest as ut
import unittest_decorators as utx
import numpy as np
import itertools

import espressomd
from espressomd import constraints
Expand Down Expand Up @@ -167,7 +167,7 @@ def test_potential_field(self):
with self.assertRaisesRegex(RuntimeError, 'Parameter particle_scales is read-only'):
F.particle_scales = {0: 0.0}

for i in product(*map(range, 3 * [10])):
for i in itertools.product(*map(range, 3 * [10])):
x = (h * i)
f_val = F.call_method("_eval_field", x=x)
np.testing.assert_allclose(f_val, self.potential(x), rtol=1e-3)
Expand All @@ -194,7 +194,7 @@ def test_electric_potential_field(self):

self.system.constraints.add(F)

for i in product(*map(range, 3 * [10])):
for i in itertools.product(*map(range, 3 * [10])):
x = (h * i)
f_val = F.call_method("_eval_field", x=x)
np.testing.assert_allclose(f_val, self.potential(x), rtol=1e-3)
Expand Down Expand Up @@ -226,7 +226,7 @@ def test_force_field(self):
with self.assertRaisesRegex(RuntimeError, 'Parameter particle_scales is read-only'):
F.particle_scales = {0: 0.0}

for i in product(*map(range, 3 * [10])):
for i in itertools.product(*map(range, 3 * [10])):
x = (h * i)
f_val = np.array(F.call_method("_eval_field", x=x))
np.testing.assert_allclose(f_val, self.force(x))
Expand All @@ -252,7 +252,7 @@ def test_flow_field(self):
with self.assertRaisesRegex(RuntimeError, 'Parameter gamma is read-only'):
F.gamma = 2.0

for i in product(*map(range, 3 * [10])):
for i in itertools.product(*map(range, 3 * [10])):
x = (h * i)
f_val = np.array(F.call_method("_eval_field", x=x))
np.testing.assert_allclose(f_val, self.force(x))
Expand Down
4 changes: 2 additions & 2 deletions testsuite/python/interactions_bonded.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def setUp(self):
self.system.cell_system.skin = 0.4
self.system.time_step = .2

self.system.part.add(id=0, pos=self.start_pos, type=0)
self.system.part.add(id=1, pos=self.start_pos, type=0)
self.system.part.add(pos=self.start_pos, type=0)
self.system.part.add(pos=self.start_pos, type=0)

def tearDown(self):
self.system.part.clear()
Expand Down
4 changes: 2 additions & 2 deletions testsuite/python/interactions_bonded_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
class ParticleProperties(ut.TestCase):
system = espressomd.System(box_l=[20.0, 20.0, 20.0])

# Particle id to work on
system.part.add(id=17, pos=(0, 0, 0))
# Particle to work on
system.part.add(pos=(0, 0, 0))

def bondsMatch(self, inType, outBond, inParams, outParams, msg_long):
"""Check, if the bond type set and gotten back as well as the bond
Expand Down
5 changes: 1 addition & 4 deletions testsuite/python/interactions_dihedral.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,7 @@ def setUp(self):
self.system.cell_system.skin = 0.4
self.system.time_step = .1

self.system.part.add(pos=self.start_pos, type=0)
self.system.part.add(pos=self.start_pos, type=0)
self.system.part.add(pos=self.start_pos, type=0)
self.system.part.add(pos=self.start_pos, type=0)
self.system.part.add(pos=4 * [self.start_pos], type=4 * [0])

def tearDown(self):
self.system.part.clear()
Expand Down
10 changes: 5 additions & 5 deletions testsuite/python/lb_boundary.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import espressomd.lb
import espressomd.shapes
import espressomd.lbboundaries
from itertools import product
import itertools


class LBBoundariesBase:
Expand Down Expand Up @@ -79,17 +79,17 @@ def test_clear(self):
def check_boundary_flags(self, boundarynumbers):
rng = range(20)

for i in product(range(0, 5), rng, rng):
for i in itertools.product(range(0, 5), rng, rng):
self.assertEqual(self.lbf[i].boundary, boundarynumbers[0])

for i in product(range(5, 15), rng, rng):
for i in itertools.product(range(5, 15), rng, rng):
self.assertEqual(self.lbf[i].boundary, boundarynumbers[1])

for i in product(range(15, 20), rng, rng):
for i in itertools.product(range(15, 20), rng, rng):
self.assertEqual(self.lbf[i].boundary, boundarynumbers[2])

self.system.lbboundaries.clear()
for i in product(rng, rng, rng):
for i in itertools.product(rng, rng, rng):
self.assertEqual(self.lbf[i].boundary, 0)

def test_boundary_flags(self):
Expand Down
4 changes: 2 additions & 2 deletions testsuite/python/lb_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import numpy as np
import espressomd
import espressomd.lb
from itertools import product
import itertools


@utx.skipIfMissingFeatures(["EXTERNAL_FORCES"])
Expand Down Expand Up @@ -67,7 +67,7 @@ def switch_test(self, GPU=False):
system.actors.add(lb_fluid_2)
system.thermostat.set_lb(LB_fluid=lb_fluid_2, gamma=friction_2)

for pid in product(range(5), range(5), range(5)):
for pid in itertools.product(range(5), repeat=3):
np.testing.assert_allclose(
np.copy(lb_fluid_2[pid].velocity), np.zeros((3,)))

Expand Down
2 changes: 1 addition & 1 deletion testsuite/python/mmm1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_energy(self):
def test_with_analytical_result(self, prefactor=1.0, accuracy=1e-4):
self.system.part.clear()
p = self.system.part.add(pos=[0, 0, 0], q=1)
_ = self.system.part.add(pos=[0, 0, 1], q=1)
self.system.part.add(pos=[0, 0, 1], q=1)

self.system.integrator.run(steps=0)
f_measured = p.f
Expand Down
5 changes: 2 additions & 3 deletions testsuite/python/pair_criteria.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ class PairCriteria(ut.TestCase):
es.bonded_inter.add(f1)
f2 = FeneBond(k=1, d_r_max=0.05)
es.bonded_inter.add(f2)
es.part.add(pos=(0, 0, 0))
es.part.add(pos=(0.91, 0, 0))
p1, p2 = es.part[:]
p1 = es.part.add(pos=(0, 0, 0))
p2 = es.part.add(pos=(0.91, 0, 0))
epsilon = 1E-8

def test_distance_crit_periodic(self):
Expand Down
9 changes: 3 additions & 6 deletions testsuite/python/rdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,9 @@ def test_mixed(self):
def test_rdf_interface(self):
# test setters and getters
s = self.s
s.part.add(pos=[0, 0, 0], type=0)
s.part.add(pos=[0, 0, 0], type=1)
s.part.add(pos=[0, 0, 0], type=0)
s.part.add(pos=[0, 0, 0], type=1)
pids1 = [s.part[:].id[0]]
pids2 = [s.part[:].id[1]]
s.part.add(pos=4 * [(0, 0, 0)], type=[0, 1, 0, 1])
pids1 = s.part[:].id[0::2]
pids2 = s.part[:].id[1::2]
observable = espressomd.observables.RDF(ids1=pids1, ids2=pids2,
min_r=1, max_r=2, n_r_bins=3)
# check pids
Expand Down
25 changes: 11 additions & 14 deletions testsuite/python/rotation_per_particle.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import unittest_decorators as utx
import espressomd
import numpy as np
import itertools


@utx.skipIfMissingFeatures("ROTATION")
Expand All @@ -36,17 +37,15 @@ def test_langevin(self):
thermalized"""
s = self.s
s.thermostat.set_langevin(gamma=1, kT=1, seed=42)
for x in (False, True):
for y in (False, True):
for z in (False, True):
s.part.clear()
p = s.part.add(pos=(0, 0, 0), rotation=(x, y, z),
quat=(1, 0, 0, 0), omega_body=(0, 0, 0),
torque_lab=(0, 0, 0))
s.integrator.run(500)
self.validate(p, x, 0)
self.validate(p, y, 1)
self.validate(p, z, 2)
for rot_x, rot_y, rot_z in itertools.product((False, True), repeat=3):
p = s.part.add(pos=(0, 0, 0), rotation=(rot_x, rot_y, rot_z),
quat=(1, 0, 0, 0), omega_body=(0, 0, 0),
torque_lab=(0, 0, 0))
s.integrator.run(500)
self.validate(p, rot_x, 0)
self.validate(p, rot_y, 1)
self.validate(p, rot_z, 2)
s.part.clear()

def validate(self, p, rotate, coord):
if rotate:
Expand All @@ -72,9 +71,7 @@ def test_axes_changes(self):
rot[direction] = 1
p.rotation = rot

s.integrator.run(30)

s.integrator.run(100)
s.integrator.run(130)

# Check other axes:
for axis in [1, 0, 0], [0, 1, 0], [0, 0, 1]:
Expand Down
7 changes: 3 additions & 4 deletions testsuite/python/rotational_inertia.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,10 @@ def test_stability(self):

tol = 4E-3
# Anisotropic inertial moment. Stable axes correspond to J[1] and J[2].
# The unstable axis corresponds to J[0]. These values relation is J[1]
# < J[0] < J[2].
J = np.array([5, 0.5, 18.5])
# The unstable axis corresponds to J[0]. These values relation is
# J[1] < J[0] < J[2].
p.rinertia = [5, 0.5, 18.5]

p.rinertia = J[:]
# Validation of J[1] stability
# ----------------------------
self.system.time_step = 0.0006
Expand Down

0 comments on commit b069c6a

Please sign in to comment.