Commit 7b198222 authored by Savici, Andrei T's avatar Savici, Andrei T
Browse files

Fixed tests. Made sure you cannot use singular matrix for goniometer. There is...

Fixed tests. Made sure you cannot use singular matrix for goniometer. There is no check if it's a real rotation matrix. Fixes #2870
parent b6a1b63f
......@@ -72,7 +72,7 @@ namespace DataObjects
m_InverseGoniometerMatrix(goniometer),
m_RunNumber(0)
{
m_InverseGoniometerMatrix.Invert();
if(fabs(m_InverseGoniometerMatrix.Invert())<1e-8) throw std::invalid_argument("Goniometer matrix must non-singular.");
this->setDetectorID(m_DetectorID);
this->setWavelength(m_Wavelength);
}
......@@ -382,7 +382,7 @@ namespace DataObjects
this->m_GoniometerMatrix = goniometerMatrix;
// Calc the inverse rotation matrix
m_InverseGoniometerMatrix = m_GoniometerMatrix;
m_InverseGoniometerMatrix.Invert();
if(fabs(m_InverseGoniometerMatrix.Invert())<1e-8) throw std::invalid_argument("Goniometer matrix must non-singular.");
}
......
......@@ -48,6 +48,27 @@ public:
TS_ASSERT_EQUALS(p.getInstrument(), inst)
}
void test_constructorHKLGon()
{
Matrix<double> mats(3,3),mat(3,3);
for (int x=0; x<3; x++)
for (int y=0; y<3; y++)
mats[x][y]=1.0*x+1.0*y;
mat[0][0]=1.0;mat[1][2]=1.0;mat[2][1]=1.0;
// detector IDs start at 10000
TS_ASSERT_THROWS_ANYTHING(Peak ps(inst, 10000, 2.0, V3D(1,2,3),mats );)
TS_ASSERT_THROWS_NOTHING(Peak p(inst, 10000, 2.0, V3D(1,2,3),mat );)
Peak p(inst, 10000, 2.0, V3D(1,2,3),mat );
TS_ASSERT_DELTA(p.getH(), 1.0, 1e-5)
TS_ASSERT_DELTA(p.getK(), 2.0, 1e-5)
TS_ASSERT_DELTA(p.getL(), 3.0, 1e-5)
TS_ASSERT_EQUALS(p.getDetectorID(), 10000)
TS_ASSERT_EQUALS(p.getDetector()->getID(), 10000)
TS_ASSERT_EQUALS(p.getInstrument(), inst)
TS_ASSERT_EQUALS( p.getGoniometerMatrix(), mat);
}
void test_copyConstructor()
{
Peak p(inst, 10102, 2.0);
......@@ -101,13 +122,15 @@ public:
void test_GoniometerMatrix()
{
Peak p(inst, 10000, 2.0);
Matrix<double> mat(3,3);
Matrix<double> mats(3,3),mat(3,3);
for (int x=0; x<3; x++)
for (int y=0; y<3; y++)
mat[x][y]=x+y;
p.setGoniometerMatrix(mat);
mats[x][y]=1.0*x+1.0*y;
TS_ASSERT_THROWS_ANYTHING(p.setGoniometerMatrix(mats)); //matrix is singular
TS_ASSERT_EQUALS( p.getGoniometerMatrix(), mats);
mat[0][0]=1.0;mat[1][2]=1.0;mat[2][1]=1.0;
TS_ASSERT_THROWS_NOTHING(p.setGoniometerMatrix(mat)); //matrix is not singular
TS_ASSERT_EQUALS( p.getGoniometerMatrix(), mat);
// Matrix must be 3x3
Matrix<double> mat2(4,3);
TS_ASSERT_THROWS_ANYTHING( p.setGoniometerMatrix(mat2) );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment