Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_init(input_length):
with pytest.raises(DimensionError):
Quaternion(tuple(range(input_length)))
def test_mul_rotation(r1, i1, r2, i2, expected, expected_i):
r1 = Rotation(r1)
r1.improper = i1
r2 = Rotation(r2)
r2.improper = i2
r = r1 * r2
assert isinstance(r, Rotation)
assert np.allclose(r.data, expected)
assert np.all(r.improper == expected_i)
import itertools
from orix.quaternion import Quaternion
from orix.quaternion.rotation import Rotation
from orix.vector import Vector3d
rotations = [
(0.707, 0., 0., 0.707),
(0.5, -0.5, -0.5, 0.5),
(0., 0., 0., 1.),
(1., 1., 1., 1.),
(
(0.5, -0.5, -0.5, 0.5),
(0., 0., 0., 1.),
),
Rotation([
(2, 4, 6, 8),
(-1, -2, -3, -4)
]),
np.array((4, 3, 2, 1))
]
quaternions = [
(0.881, 0.665, 0.123, 0.517),
(0.111, 0.222, 0.333, 0.444),
(
(1, 0, 0.5, 0),
(3, 1, -1, -2),
),
[
[[0.343, 0.343, 0, -0.333], [-7, -8, -9, -10],],
[[0.00001, -0.0001, 0.001, -0.01], [0, 0, 0, 0]]
Vector3d([[1, 2, 3], [-3, -2, -1]]),
[[0, 0, 0], [4, 4, 4]],
marks=pytest.mark.xfail(raises=ValueError)
),
([1, 2, 3], Scalar([4]), [4, 8, 12]),
([1, 2, 3], 0.5, [0.5, 1., 1.5]),
([1, 2, 3], [-1, 2], [[-1, -2, -3], [2, 4, 6]]),
([1, 2, 3], np.array([-1, 1]), [[-1, -2, -3], [1, 2, 3]]),
pytest.param([1, 2, 3], 'dracula', None, marks=pytest.mark.xfail),
], indirect=['vector'])
def test_mul(vector, other, expected):
s1 = vector * other
s2 = other * vector
assert np.allclose(s1.data, expected)
assert np.allclose(s1.data, s2.data)
([1, 2, 3], Vector3d([[1, 2, 3], [-3, -2, -1]]), [[0, 0, 0], [4, 4, 4]]),
([1, 2, 3], Scalar([4]), [-3, -2, -1]),
([1, 2, 3], 0.5, [0.5, 1.5, 2.5]),
([1, 2, 3], [-1, 2], [[2, 3, 4], [-1, 0, 1]]),
([1, 2, 3], np.array([-1, 1]), [[2, 3, 4], [0, 1, 2]]),
pytest.param([1, 2, 3], 'dracula', None, marks=pytest.mark.xfail),
], indirect=['vector'])
def test_sub(vector, other, expected):
s1 = vector - other
s2 = other - vector
assert np.allclose(s1.data, expected)
assert np.allclose(-s1.data, s2.data)
def vector(request):
return Vector3d(request.param)
def vector(request):
return Vector3d(request.param)
([5], Scalar([6]), 0),
pytest.param([3], 'larry', None, marks=pytest.mark.xfail),
], indirect=['scalar'])
def test_equality(scalar, other, expected):
eq = scalar == other
assert np.allclose(eq, expected)
def scalar(request):
return Scalar(request.param)
def something(request):
return Quaternion(request.param)