forked from npshub/mantid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AffineMatrixParameterTest.h
119 lines (92 loc) · 3.42 KB
/
AffineMatrixParameterTest.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#pragma once
#include "MantidDataObjects/AffineMatrixParameter.h"
#include "MantidGeometry/MDGeometry/MDTypes.h"
#include <cxxtest/TestSuite.h>
using namespace Mantid::DataObjects;
using namespace Mantid;
class AffineMatrixParameterTest : public CxxTest::TestSuite {
public:
void testConstruction() {
AffineMatrixParameter param(2, 3);
AffineMatrixType affineMatrix = param.getAffineMatrix();
std::pair<size_t, size_t> size = affineMatrix.size();
TS_ASSERT_EQUALS(size.first, 3);
TS_ASSERT_EQUALS(size.second, 4);
TS_ASSERT(!param.isValid()); // No call to setMatrix.
}
void testCopy() {
AffineMatrixParameter A(2, 3);
AffineMatrixParameter B(A);
AffineMatrixType expectedProduct = A.getAffineMatrix();
AffineMatrixType copyProduct = B.getAffineMatrix();
TS_ASSERT_EQUALS(expectedProduct, copyProduct);
TS_ASSERT_EQUALS(A.isValid(), B.isValid());
}
void testSetMatrix() {
AffineMatrixParameter param(3, 3);
AffineMatrixType transform(4, 4);
param.setMatrix(transform);
TS_ASSERT(param.isValid()); // Matrix is now set.
TS_ASSERT_EQUALS(transform, param.getAffineMatrix());
}
void testSetMatrixThrowsIfOutDimsNotEqual() {
AffineMatrixParameter param(1, 3);
AffineMatrixType transform(4, 4);
TS_ASSERT_THROWS(param.setMatrix(transform), const std::runtime_error &);
}
void testSetMatrixThrowsIfInDimsNotEqual() {
AffineMatrixParameter param(3, 1);
AffineMatrixType transform(4, 4);
TS_ASSERT_THROWS(param.setMatrix(transform), const std::runtime_error &);
}
void testAssign() {
AffineMatrixParameter A(4, 4);
AffineMatrixParameter B(4, 4);
B = A;
AffineMatrixType AProduct = A.getAffineMatrix();
AffineMatrixType BProduct = B.getAffineMatrix();
TS_ASSERT_EQUALS(AProduct, BProduct);
TS_ASSERT_EQUALS(A.isValid(), B.isValid());
}
void testClone() {
AffineMatrixParameter A(2, 3);
AffineMatrixParameter *B = A.clone();
AffineMatrixType AProduct = A.getAffineMatrix();
AffineMatrixType BProduct = B->getAffineMatrix();
TS_ASSERT_EQUALS(AProduct, BProduct);
TS_ASSERT_EQUALS(A.isValid(), B->isValid());
delete B;
}
void testAssignmentThrowsIfOutDimsNotEqual() {
AffineMatrixParameter A(2, 4);
AffineMatrixParameter B(4, 4);
TS_ASSERT_THROWS(B = A, const std::runtime_error &);
}
void testAssignementThrowsIfInDimsNotEqual() {
AffineMatrixParameter A(4, 2);
AffineMatrixParameter B(4, 4);
TS_ASSERT_THROWS(B = A, const std::runtime_error &);
}
void testToXMLString() {
AffineMatrixParameter param(3, 3);
AffineMatrixType transform(4, 4);
int count = 0;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
transform[i][j] = static_cast<coord_t>(count);
count++;
}
}
param.setMatrix(transform);
TSM_ASSERT_EQUALS("Serialization of CoordTransform has not worked correctly.",
"<Parameter><Type>AffineMatrixParameter</"
"Type><Value>0,1,2,3;4,5,6,7;8,9,10,11;12,13,14,15</Value></Parameter>",
param.toXMLString());
}
};