Newer
Older
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
// 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
// SPDX - License - Identifier: GPL - 3.0 +
#ifndef LOAD_ENVIRONMENTEST_H_
#define LOAD_ENVIRONMENTEST_H_
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/FileFinder.h"
#include "MantidAPI/FrameworkManager.h"
#include "MantidAPI/Sample.h"
#include "MantidDataHandling/LoadInstrument.h"
#include "MantidDataHandling/LoadBinaryStl.h"
#include "MantidDataHandling/LoadSampleEnvironment.h"
#include "MantidGeometry/Objects/MeshObject.h"
#include <cxxtest/TestSuite.h>
using namespace Mantid;
using namespace Mantid::API;
using namespace Mantid::DataHandling;
using namespace Mantid::Geometry;
class LoadSampleEnvironmentTest : public CxxTest::TestSuite {
public:
static LoadSampleEnvironmentTest *createSuite() {
return new LoadSampleEnvironmentTest();
}
static void destroySuite(LoadSampleEnvironmentTest *suite) { delete suite; }
void testInit() {
LoadSampleEnvironment alg;
TS_ASSERT_THROWS_NOTHING(alg.initialize());
TS_ASSERT(alg.isInitialized());
TSM_ASSERT_EQUALS("should be 7 properties here", 7,
(size_t)(alg.getProperties().size()));
}
void testTranslate() {
LoadSampleEnvironment alg;
alg.initialize();
alg.setProperty("TranslationVector","5,5,15");
boost::shared_ptr<MeshObject> environmentMesh = nullptr;
environmentMesh = loadCube();
alg.translate(environmentMesh);
auto translatedVertices = environmentMesh->getVertices();
double arrayToMatch[] = {0,0,0,10,10,0,10,0,0,0,10,0,10,0,30,10,10,30,0,10,30,0,0,30};
std::vector<double> vectorToMatch = std::vector<double>(std::begin(arrayToMatch),std::end(arrayToMatch));
TS_ASSERT(translatedVertices == vectorToMatch);
}
void testRotate(){
LoadSampleEnvironment alg;
alg.initialize();
alg.setProperty("rotationMatrix","0,-1,0,1,0,0,0,0,1");
boost::shared_ptr<MeshObject> environmentMesh = nullptr;
environmentMesh = loadCube();
alg.rotate(environmentMesh);
auto rotatedVertices = environmentMesh->getVertices();
double arrayToMatch[] = {5,-5,-15,-5,5,-15,5,5,-15,-5,-5,-15,5,5,15,-5,5,15,-5,-5,15,5,-5,15};
std::vector<double> vectorToMatch = std::vector<double>(std::begin(arrayToMatch),std::end(arrayToMatch));
TS_ASSERT(rotatedVertices == vectorToMatch);
}
std::unique_ptr<MeshObject> loadCube(){
std::string path = FileFinder::Instance().getFullPath("cubeBin.stl");
auto loader = LoadBinaryStl(path);
auto cube = loader.readStl();
return cube;
}
};
#endif /* LOAD_ENVIRONMENTTEST_H_ */