forked from npshub/mantid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EigenConversionHelpersTest.h
54 lines (46 loc) · 1.93 KB
/
EigenConversionHelpersTest.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
// 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 <cxxtest/TestSuite.h>
#include "MantidKernel/EigenConversionHelpers.h"
using namespace Mantid::Kernel;
class EigenConversionHelpersTest : public CxxTest::TestSuite {
public:
// This pair of boilerplate methods prevent the suite being created statically
// This means the constructor isn't called when running other tests
static EigenConversionHelpersTest *createSuite() { return new EigenConversionHelpersTest(); }
static void destroySuite(EigenConversionHelpersTest *suite) { delete suite; }
void test_toV3D() {
const auto result = toV3D(Eigen::Vector3d(0.1, 0.2, 0.4));
TS_ASSERT_EQUALS(result[0], 0.1);
TS_ASSERT_EQUALS(result[1], 0.2);
TS_ASSERT_EQUALS(result[2], 0.4);
}
void test_toQuat() {
const Eigen::Vector3d start(0.1, 0.2, 0.4);
const Eigen::Vector3d end(0.2, -1.234, 10.1);
const auto rot = Eigen::Quaterniond::FromTwoVectors(start, end);
auto probe = toV3D(start);
toQuat(rot).rotate(probe);
const auto expected = toV3D(rot * start);
TS_ASSERT_DELTA(probe[0], expected[0], 1e-15);
TS_ASSERT_DELTA(probe[1], expected[1], 1e-15);
TS_ASSERT_DELTA(probe[2], expected[2], 1e-15);
}
void test_toVector3d() {
const auto result = toVector3d(V3D(0.1, 0.2, 0.4));
TS_ASSERT_EQUALS(result[0], 0.1);
TS_ASSERT_EQUALS(result[1], 0.2);
TS_ASSERT_EQUALS(result[2], 0.4);
}
void test_toQuaterniond() {
const Eigen::Vector3d start(0.1, 0.2, 0.4);
const Eigen::Vector3d end(0.2, -1.234, 10.1);
const auto rot = Eigen::Quaterniond::FromTwoVectors(start, end);
TS_ASSERT(toQuaterniond(toQuat(rot)).isApprox(rot, 1e-15));
}
};