better use fixtures

This commit is contained in:
Martin Diehl 2019-11-24 06:29:00 +01:00
parent 2b392241f9
commit 928a5c2e55
1 changed files with 24 additions and 23 deletions

View File

@ -1,54 +1,55 @@
import pytest
import numpy as np import numpy as np
from damask import Rotation from damask import Rotation
n = 1000
@pytest.fixture
def default():
"""A set of n random rotations."""
return [Rotation.fromRandom() for r in range(n)]
class TestRotation: class TestRotation:
n = 1000
def test_Eulers(self): def test_Eulers(self,default):
for r in range(self.n): for rot in default:
rot = Rotation.fromRandom()
assert np.allclose(rot.asQuaternion(), assert np.allclose(rot.asQuaternion(),
Rotation.fromEulers(rot.asEulers()).asQuaternion()) Rotation.fromEulers(rot.asEulers()).asQuaternion())
def test_AxisAngle(self): def test_AxisAngle(self,default):
for r in range(self.n): for rot in default:
rot = Rotation.fromRandom()
assert np.allclose(rot.asEulers(), assert np.allclose(rot.asEulers(),
Rotation.fromAxisAngle(rot.asAxisAngle()).asEulers()) Rotation.fromAxisAngle(rot.asAxisAngle()).asEulers())
def test_Matrix(self): def test_Matrix(self,default):
for r in range(self.n): for rot in default:
rot = Rotation.fromRandom()
assert np.allclose(rot.asAxisAngle(), assert np.allclose(rot.asAxisAngle(),
Rotation.fromMatrix(rot.asMatrix()).asAxisAngle()) Rotation.fromMatrix(rot.asMatrix()).asAxisAngle())
def test_Rodriques(self): def test_Rodriques(self,default):
for r in range(self.n): for rot in default:
rot = Rotation.fromRandom()
assert np.allclose(rot.asMatrix(), assert np.allclose(rot.asMatrix(),
Rotation.fromRodrigues(rot.asRodrigues()).asMatrix()) Rotation.fromRodrigues(rot.asRodrigues()).asMatrix())
def test_Homochoric(self): def test_Homochoric(self,default):
for r in range(self.n): for rot in default:
rot = Rotation.fromRandom()
assert np.allclose(rot.asRodrigues(), assert np.allclose(rot.asRodrigues(),
Rotation.fromHomochoric(rot.asHomochoric()).asRodrigues()) Rotation.fromHomochoric(rot.asHomochoric()).asRodrigues())
def test_Cubochoric(self): def test_Cubochoric(self,default):
for r in range(self.n): for rot in default:
rot = Rotation.fromRandom()
assert np.allclose(rot.asHomochoric(), assert np.allclose(rot.asHomochoric(),
Rotation.fromCubochoric(rot.asCubochoric()).asHomochoric()) Rotation.fromCubochoric(rot.asCubochoric()).asHomochoric())
def test_Quaternion(self): def test_Quaternion(self,default):
for r in range(self.n): for rot in default:
rot = Rotation.fromRandom()
assert np.allclose(rot.asCubochoric(), assert np.allclose(rot.asCubochoric(),
Rotation.fromQuaternion(rot.asQuaternion()).asCubochoric()) Rotation.fromQuaternion(rot.asQuaternion()).asCubochoric())