more tests
This commit is contained in:
parent
19638168e6
commit
61ac40c259
|
@ -8,13 +8,8 @@ import damask
|
|||
from damask import Rotation
|
||||
from damask import Orientation
|
||||
from damask import Lattice
|
||||
|
||||
n = 1000
|
||||
|
||||
@pytest.fixture
|
||||
def default():
|
||||
"""A set of n random rotations."""
|
||||
return [Rotation.from_random() for r in range(n)]
|
||||
n = 1000
|
||||
|
||||
@pytest.fixture
|
||||
def reference_dir(reference_dir_base):
|
||||
|
@ -28,10 +23,10 @@ class TestOrientation:
|
|||
{'label':'green','RGB':[0,1,0],'direction':[0,1,1]},
|
||||
{'label':'blue', 'RGB':[0,0,1],'direction':[1,1,1]}])
|
||||
@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)
|
||||
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)
|
||||
def test_IPF(self,lattice):
|
||||
|
@ -57,7 +52,7 @@ class TestOrientation:
|
|||
reference = os.path.join(reference_dir,'{}_{}.txt'.format(lattice,model))
|
||||
ori = Orientation(Rotation(),lattice)
|
||||
eu = np.array([o.rotation.asEulers(degrees=True) for o in ori.relatedOrientations(model)])
|
||||
if update:
|
||||
if update:
|
||||
coords = np.array([(1,i+1) for i,x in enumerate(eu)])
|
||||
table = damask.Table(eu,{'Eulers':(3,)})
|
||||
table.add('pos',coords)
|
||||
|
|
|
@ -177,7 +177,7 @@ class TestRotation:
|
|||
(Rotation.from_Rodrigues, np.array([1,0,0,-1])),
|
||||
(Rotation.from_Rodrigues, np.array([1,1,0,1])),
|
||||
(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):
|
||||
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)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('x',[np.random.rand(3),
|
||||
np.random.rand(3,3)])
|
||||
def test_rotation_identity(self,x):
|
||||
@pytest.mark.parametrize('data',[np.random.rand(3),
|
||||
np.random.rand(3,3),
|
||||
np.random.rand(3,3,3,3)])
|
||||
def test_rotate_identity(self,data):
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue