forked from AmbaPant/mantid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
BroadcastWorkspaceTest.h
69 lines (56 loc) · 2.67 KB
/
BroadcastWorkspaceTest.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
// 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 "MantidAPI/FrameworkManager.h"
#include "MantidFrameworkTestHelpers/WorkspaceCreationHelper.h"
#include "MantidMPIAlgorithms/BroadcastWorkspace.h"
using namespace Mantid;
class BroadcastWorkspaceTest : public CxxTest::TestSuite {
public:
static BroadcastWorkspaceTest *createSuite() { return new BroadcastWorkspaceTest(); }
static void destroySuite(BroadcastWorkspaceTest *suite) { delete suite; }
BroadcastWorkspaceTest() {
// Create the Framework manager so that MPI gets initialized
API::FrameworkManager::Instance();
}
void testTheBasics() {
MPIAlgorithms::BroadcastWorkspace broadcaster;
TS_ASSERT_EQUALS(broadcaster.name(), "BroadcastWorkspace");
TS_ASSERT_EQUALS(broadcaster.version(), 1);
TS_ASSERT_EQUALS(broadcaster.category(), "MPI");
TS_ASSERT_THROWS_NOTHING(broadcaster.initialize());
TS_ASSERT(broadcaster.isInitialized());
}
void testRankValidator() {
MPIAlgorithms::BroadcastWorkspace broadcaster;
TS_ASSERT_THROWS_NOTHING(broadcaster.initialize());
TS_ASSERT_THROWS_NOTHING(broadcaster.setPropertyValue("OutputWorkspace", "blah"));
TS_ASSERT_THROWS(broadcaster.setProperty("BroadcasterRank", 1), const std::invalid_argument &);
}
void testExecute() {
MPIAlgorithms::BroadcastWorkspace broadcaster;
TS_ASSERT_THROWS_NOTHING(broadcaster.initialize());
// Create a small workspace
API::MatrixWorkspace_sptr inWS = WorkspaceCreationHelper::Create2DWorkspace154(1, 5);
TS_ASSERT_THROWS_NOTHING(broadcaster.setProperty("InputWorkspace", inWS));
TS_ASSERT_THROWS_NOTHING(broadcaster.setPropertyValue("OutputWorkspace", "blah"));
broadcaster.setChild(true); // Make a child algorithm to keep the result out of the ADS
TS_ASSERT(broadcaster.execute());
API::MatrixWorkspace_const_sptr outWS = broadcaster.getProperty("OutputWorkspace");
TS_ASSERT_EQUALS(inWS->size(), outWS->size());
for (int i = 0; i < 5; ++i) {
TS_ASSERT_EQUALS(inWS->readX(0)[i], outWS->readX(0)[i]);
TS_ASSERT_EQUALS(inWS->readY(0)[i], outWS->readY(0)[i]);
TS_ASSERT_EQUALS(inWS->readE(0)[i], outWS->readE(0)[i]);
}
// TS_ASSERT_EQUALS( inWS->getAxis(0)->unit()->unitID(),
// outWS->getAxis(0)->unit()->unitID() );
}
// TODO: Work out a way of testing under MPI because absent that the test is
// not very interesting
};