more tests

This commit is contained in:
Martin Diehl 2020-05-16 13:44:07 +02:00
parent 19638168e6
commit 61ac40c259
2 changed files with 43 additions and 14 deletions

View File

@ -11,11 +11,6 @@ from damask import Lattice
n = 1000 n = 1000
@pytest.fixture
def default():
"""A set of n random rotations."""
return [Rotation.from_random() for r in range(n)]
@pytest.fixture @pytest.fixture
def reference_dir(reference_dir_base): def reference_dir(reference_dir_base):
"""Directory containing reference results.""" """Directory containing reference results."""
@ -28,10 +23,10 @@ class TestOrientation:
{'label':'green','RGB':[0,1,0],'direction':[0,1,1]}, {'label':'green','RGB':[0,1,0],'direction':[0,1,1]},
{'label':'blue', 'RGB':[0,0,1],'direction':[1,1,1]}]) {'label':'blue', 'RGB':[0,0,1],'direction':[1,1,1]}])
@pytest.mark.parametrize('lattice',['fcc','bcc']) @pytest.mark.parametrize('lattice',['fcc','bcc'])
def test_IPF_cubic(self,default,color,lattice): def test_IPF_cubic(self,color,lattice):
cube = damask.Orientation(damask.Rotation(),lattice) cube = damask.Orientation(damask.Rotation(),lattice)
for direction in set(permutations(np.array(color['direction']))): for direction in set(permutations(np.array(color['direction']))):
assert np.allclose(cube.IPFcolor(direction),np.array(color['RGB'])) assert np.allclose(cube.IPFcolor(np.array(direction)),np.array(color['RGB']))
@pytest.mark.parametrize('lattice',Lattice.lattices) @pytest.mark.parametrize('lattice',Lattice.lattices)
def test_IPF(self,lattice): def test_IPF(self,lattice):

View File

@ -177,7 +177,7 @@ class TestRotation:
(Rotation.from_Rodrigues, np.array([1,0,0,-1])), (Rotation.from_Rodrigues, np.array([1,0,0,-1])),
(Rotation.from_Rodrigues, np.array([1,1,0,1])), (Rotation.from_Rodrigues, np.array([1,1,0,1])),
(Rotation.from_homochoric, np.array([2,2,2])) ]) (Rotation.from_homochoric, np.array([2,2,2])) ])
def test_invalid(self,function,invalid): def test_invalid_value(self,function,invalid):
with pytest.raises(ValueError): with pytest.raises(ValueError):
function(invalid) function(invalid)
@ -302,8 +302,42 @@ class TestRotation:
assert np.all(np.take_along_axis(np.take_along_axis(a,f,-1),b,-1) == a) assert np.all(np.take_along_axis(np.take_along_axis(a,f,-1),b,-1) == a)
@pytest.mark.parametrize('x',[np.random.rand(3), @pytest.mark.parametrize('data',[np.random.rand(3),
np.random.rand(3,3)]) np.random.rand(3,3),
def test_rotation_identity(self,x): np.random.rand(3,3,3,3)])
def test_rotate_identity(self,data):
R = Rotation() R = Rotation()
assert np.allclose(x,R*x) assert np.allclose(data,R*data)
@pytest.mark.parametrize('data',[np.random.rand(3),
np.random.rand(3,3),
np.random.rand(3,3,3,3)])
def test_rotate_360deg(self,data):
phi_1 = np.random.random() * np.pi
phi_2 = 2*np.pi - phi_1
R_1 = Rotation.from_Eulers(np.array([phi_1,0.,0.]))
R_2 = Rotation.from_Eulers(np.array([0.,0.,phi_2]))
assert np.allclose(data,R_2*(R_1*data))
@pytest.mark.parametrize('data',[np.random.rand(3),
np.random.rand(3,3),
np.random.rand(3,3,3,3)])
def test_rotate_inverse(self,data):
R = Rotation.from_random()
assert np.allclose(data,R.inversed()*(R*data))
@pytest.mark.parametrize('data',[np.random.rand(4),
np.random.rand(3,2),
np.random.rand(3,2,3,3)])
def test_rotate_invalid_shape(self,data):
R = Rotation.from_random()
with pytest.raises(ValueError):
R*data
@pytest.mark.parametrize('data',['does_not_work',
(1,2),
5])
def test_rotate_invalid_type(self,data):
R = Rotation.from_random()
with pytest.raises(TypeError):
R*data