2 import MagneticDipoleDipoleInteraction_ConstantIdenticalDipoles
as Potential
4 def test_constructor_get_parameters():
9 orientation = Vector3DReal(1, 0, 0)
11 with pytest.raises(TypeError):
12 Potential([1], orientation)
14 with pytest.raises(TypeError):
15 Potential(1, [1, 0, 0])
18 with pytest.raises(ValueError):
19 Potential(-1, orientation)
21 with pytest.raises(ValueError):
22 Potential(1, orientation * 2)
25 pot = Potential(2.5, orientation)
28 assert isinstance(pot.getPrefactor(), float)
29 assert pot.getPrefactor() == 2.5
31 assert pot.getOrientation() == orientation
34 assert pot.getOrientation() == Vector3DReal(1, 0, 0)
37 def test_getPotential():
43 orientation = Vector3DReal(0, 1, 0)
44 pot = Potential(prefactor, orientation)
48 ret *= 3 * orientation.dot(r.getNormalized()) ** 2 - 1
49 ret /= r.getLength() ** 3
54 with pytest.raises(TypeError):
56 with pytest.raises(TypeError):
59 r = Vector3DReal(0, 0, 0)
60 with pytest.raises(ValueError):
63 for i
in range(0, 100):
64 r = Vector3DReal(-0.1 + i, i * 0.1, 2 * i)
66 assert pot.getPotential(r) == pytest.approx(expected(r))