-
Notifications
You must be signed in to change notification settings - Fork 122
/
PoldiPeakCollectionTest.h
131 lines (100 loc) · 4.2 KB
/
PoldiPeakCollectionTest.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
120
121
122
123
124
125
126
127
128
129
130
131
#ifndef MANTID_SINQ_POLDIPEAKCOLLECTIONTEST_H
#define MANTID_SINQ_POLDIPEAKCOLLECTIONTEST_H
#include <cxxtest/TestSuite.h>
#include "MantidSINQ/PoldiUtilities/PoldiPeakCollection.h"
#include "MantidSINQ/PoldiUtilities/PoldiPeak.h"
#include "MantidSINQ/PoldiUtilities/UncertainValueIO.h"
#include "MantidDataObjects/TableWorkspace.h"
#include "MantidAPI/TableRow.h"
#include "MantidAPI/WorkspaceFactory.h"
#include <stdexcept>
using namespace Mantid::Poldi;
using namespace Mantid::API;
using namespace Mantid::DataObjects;
class PoldiPeakCollectionTest;
class TestablePoldiPeakCollection : public PoldiPeakCollection
{
friend class PoldiPeakCollectionTest;
TestablePoldiPeakCollection() :
PoldiPeakCollection()
{
}
TestablePoldiPeakCollection(TableWorkspace_sptr workspace) :
PoldiPeakCollection(workspace)
{
}
};
class PoldiPeakCollectionTest : 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 PoldiPeakCollectionTest *createSuite() { return new PoldiPeakCollectionTest(); }
static void destroySuite( PoldiPeakCollectionTest *suite ) { delete suite; }
PoldiPeakCollectionTest()
{
m_dummyData = boost::dynamic_pointer_cast<TableWorkspace>(WorkspaceFactory::Instance().createTable());
m_dummyData->addColumn("str", "HKL");
m_dummyData->addColumn("str", "d");
m_dummyData->addColumn("str", "Q");
m_dummyData->addColumn("str", "Intensity");
m_dummyData->addColumn("str", "FWHM (rel.)");
TableRow first = m_dummyData->appendRow();
first << "1 0 0" << "0.5 +/- 0.001" << "12.566370 +/- 0.001000" << "2000 +/- 3" << "0.5 +/- 0.02";
TableRow second = m_dummyData->appendRow();
second << "1 1 0" << "0.8 +/- 0.004" << "7.853981 +/- 0.001000" << "200 +/- 14" << "0.9 +/- 0.1";
}
void testConstruction()
{
TS_ASSERT_THROWS_NOTHING(PoldiPeakCollection newCollection);
TS_ASSERT_THROWS_NOTHING(PoldiPeakCollection fromTable(m_dummyData));
}
void testTableImportExport()
{
PoldiPeakCollection fromTable(m_dummyData);
TS_ASSERT_EQUALS(fromTable.peakCount(), 2);
PoldiPeak_sptr first = fromTable.peak(0);
TS_ASSERT_EQUALS(first->d(), 0.5);
TS_ASSERT_EQUALS(first->d().error(), 0.001);
TS_ASSERT_EQUALS(first->q(), 2.0 * M_PI / 0.5);
TS_ASSERT_EQUALS(first->fwhm(PoldiPeak::Relative), 0.5);
TS_ASSERT_EQUALS(first->fwhm(PoldiPeak::AbsoluteD), 0.25);
TableWorkspace_sptr exported = fromTable.asTableWorkspace();
TS_ASSERT_EQUALS(exported->columnCount(), 5);
TS_ASSERT_EQUALS(exported->rowCount(), 2);
TableRow secondRowReference = m_dummyData->getRow(1);
TableRow secondRow = exported->getRow(1);
// HKL strings compare directly
TS_ASSERT_EQUALS(secondRow.cell<std::string>(0), secondRowReference.cell<std::string>(0));
// The other values not necessarily (string conversion of UncertainValue)
for(size_t i = 1; i < exported->columnCount(); ++i) {
TS_ASSERT_DELTA(UncertainValueIO::fromString(secondRow.cell<std::string>(i)).value(), UncertainValueIO::fromString(secondRowReference.cell<std::string>(i)).value(), 1e-6);
}
}
void testAddPeak()
{
PoldiPeakCollection peaks;
peaks.addPeak(PoldiPeak::create(2.0));
TS_ASSERT_EQUALS(peaks.peakCount(), 1);
}
void testPeakAccess()
{
PoldiPeakCollection peaks;
PoldiPeak_sptr newPeak = PoldiPeak::create(2.0);
peaks.addPeak(newPeak);
PoldiPeak_sptr peak = peaks.peak(0);
TS_ASSERT_EQUALS(peak, newPeak);
TS_ASSERT_THROWS(peaks.peak(1), std::range_error);
TS_ASSERT_THROWS(peaks.peak(-2), std::range_error);
}
void testColumnCheckConsistency()
{
TestablePoldiPeakCollection peaks;
TableWorkspace_sptr newTable(new TableWorkspace());
peaks.prepareTable(newTable);
TS_ASSERT(peaks.checkColumns(newTable));
}
private:
TableWorkspace_sptr m_dummyData;
};
#endif // MANTID_SINQ_POLDIPEAKCOLLECTIONTEST_H