Skip to content
Snippets Groups Projects
Commit 54bd7687 authored by Owen Arnold's avatar Owen Arnold
Browse files

refs #13989. Measurement type expanded.

Need some concept of verification, not just a tuple of types.
parent 141fb549
No related branches found
No related tags found
No related merge requests found
......@@ -49,7 +49,7 @@ public:
/// Clone
virtual ICatalogInfo *clone() const = 0;
/// Transform's the archive path based on operating system used.
std::string transformArchivePath(const std::string &path) const;
virtual std::string transformArchivePath(const std::string &path) const;
/// virtual destructor
virtual ~ICatalogInfo();
......
......@@ -47,6 +47,7 @@ set ( SRC_FILES
src/Indirect/Stretch.cpp
src/MantidEV.cpp
src/MantidEVWorker.cpp
src/Measurement.cpp
src/MultiDatasetFit/MDFAddWorkspaceDialog.cpp
src/MultiDatasetFit/MDFDataController.cpp
src/MultiDatasetFit/MDFDatasetPlotData.cpp
......@@ -164,6 +165,7 @@ set ( INC_FILES
inc/MantidQtCustomInterfaces/Indirect/Stretch.h
inc/MantidQtCustomInterfaces/MantidEV.h
inc/MantidQtCustomInterfaces/MantidEVWorker.h
inc/MantidQtCustomInterfaces/Measurement.h
inc/MantidQtCustomInterfaces/MultiDatasetFit/MDFAddWorkspaceDialog.h
inc/MantidQtCustomInterfaces/MultiDatasetFit/MDFDataController.h
inc/MantidQtCustomInterfaces/MultiDatasetFit/MDFDatasetPlotData.h
......@@ -406,6 +408,7 @@ set ( TEST_FILES
EnggDiffractionPresenterTest.h
IO_MuonGroupingTest.h
ImageROIPresenterTest.h
MeasurementTest.h
MuonAnalysisHelperTest.h
ParseKeyValueStringTest.h
ReflGenerateNotebookTest.h
......
#ifndef MANTIDQT_CUSTOMINTERFACES_MEASUREMENT_H_
#define MANTIDQT_CUSTOMINTERFACES_MEASUREMENT_H_
#include "MantidQtCustomInterfaces/DllConfig.h"
#include <String>
namespace MantidQt {
namespace CustomInterfaces {
/** Measurement : Immutable measurement type
Copyright &copy; 2015 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
National Laboratory & European Spallation Source
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class MANTIDQT_CUSTOMINTERFACES_DLL Measurement {
public:
/// Constructor
Measurement(const std::string &measurementId, const std::string &subId,
const std::string &label, const std::string &type);
/// Constructional method
static Measurement InvalidMeasurement();
/// Copy constructor
Measurement(const Measurement &other);
/// Destructor
~Measurement();
bool isUseable() const;
std::string id() const;
std::string subId() const;
std::string type() const;
std::string label() const;
private:
/// Constructor
Measurement();
const std::string m_measurementId;
const std::string m_subId;
const std::string m_label;
const std::string m_type;
bool m_valid;
/// Not assignable
Measurement &operator=(const Measurement &);
};
} // namespace CustomInterfaces
} // namespace MantidQt
#endif /* MANTIDQT_CUSTOMINTERFACES_MEASUREMENT_H_ */
......@@ -2,20 +2,12 @@
#define MANTIDQT_CUSTOMINTERFACES_REFLMEASUREMENTSOURCE_H_
#include "MantidQtCustomInterfaces/DllConfig.h"
#include "MantidQtCustomInterfaces/Measurement.h"
#include <string>
namespace MantidQt {
namespace CustomInterfaces {
/**
* Measurement block
*/
struct Measurement {
std::string measurementId;
std::string subId;
std::string label;
std::string type;
};
/** ReflMeasurementSource : Repository pattern abstracting data mapping from
domain. Specifically for accessing
......@@ -44,8 +36,9 @@ struct Measurement {
*/
class MANTIDQT_CUSTOMINTERFACES_DLL ReflMeasurementSource {
public:
/// Get the measurement somehow using location
virtual Measurement obtain(const std::string &location) const = 0;
/// Get the measurement somehow using location, or fuzzy path
virtual Measurement obtain(const std::string &definedPath,
const std::string &fuzzyName) const = 0;
/// Virtual destructor
virtual ReflMeasurementSource *clone() const = 0;
/// Destructor
......
#include "MantidQtCustomInterfaces/Measurement.h"
namespace MantidQt {
namespace CustomInterfaces {
/**
* Constructor
* @param measurementId
* @param subId
* @param label
* @param type
*/
Measurement::Measurement(const std::string &measurementId,
const std::string &subId, const std::string &label,
const std::string &type)
: m_measurementId(measurementId), m_subId(subId), m_label(label),
m_type(type), m_valid(true) {
if (m_measurementId.empty()) {
m_valid = false;
} else if (m_subId.empty()) {
m_valid = false;
} else if (m_label.empty()) {
m_valid = false;
} else if (m_type.empty()) {
m_valid = false;
}
}
/**
* Constructor making an invalid Measurement
*/
Measurement::Measurement() : m_valid(false) {}
/**
* Copy constructor
* @param other
*/
Measurement::Measurement(const Measurement &other)
: m_measurementId(other.m_measurementId), m_subId(other.m_subId),
m_label(other.m_label), m_type(other.m_type), m_valid(other.m_valid) {}
/// Destructor
Measurement::~Measurement() {}
/**
* InvalidMeasurement static creational method
* @return Invalid measurement
*/
Measurement Measurement::InvalidMeasurement() { return Measurement(); }
bool Measurement::isUseable() const { return m_valid; }
std::string Measurement::id() const { return m_measurementId; }
std::string Measurement::subId() const { return m_subId; }
std::string Measurement::label() const { return m_label; }
std::string Measurement::type() const { return m_type; }
} // namespace CustomInterfaces
} // namespace Mantid
......@@ -40,11 +40,11 @@ MantidQt::CustomInterfaces::ReflMeasureTransferStrategy::transferRuns(
for (auto it = searchResults.begin(); it != searchResults.end(); ++it) {
const auto location = it->second.location;
const auto run = it->first;
const auto fuzzyName = it->first;
const auto loadPath = m_catInfo->transformArchivePath(location);
const auto definedPath = m_catInfo->transformArchivePath(location);
Measurement metaData = m_measurementSource->obtain(loadPath);
Measurement metaData = m_measurementSource->obtain(definedPath, fuzzyName);
/*
const Poco::File filePath(loadPath);
if (filePath.exists() && filePath.isFile()) {
......
#ifndef MANTIDQT_CUSTOMINTERFACES_MEASUREMENTTEST_H_
#define MANTIDQT_CUSTOMINTERFACES_MEASUREMENTTEST_H_
#include <cxxtest/TestSuite.h>
#include "MantidQtCustomInterfaces/Measurement.h"
using namespace MantidQt::CustomInterfaces;
class MeasurementTest : 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 MeasurementTest *createSuite() { return new MeasurementTest(); }
static void destroySuite(MeasurementTest *suite) { delete suite; }
void test_invalid_construction_via_constructional_method() {
auto measure = Measurement::InvalidMeasurement();
TS_ASSERT(!measure.isUseable());
}
void test_valid_construction_via_constructor() {
const std::string measurementId = "a";
const std::string measurementSubId = "s";
const std::string measurementLabel = "l";
const std::string measurementType = "t";
Measurement measurement(measurementId, measurementSubId, measurementLabel,
measurementType);
TS_ASSERT(measurement.isUseable());
TS_ASSERT_EQUALS(measurementId, measurement.id());
TS_ASSERT_EQUALS(measurementSubId, measurement.subId());
TS_ASSERT_EQUALS(measurementLabel, measurement.label());
TS_ASSERT_EQUALS(measurementType, measurement.type());
}
void test_invalid_construction_when_measurementId_empty() {
Measurement measurement("", "measurementSubId", "measurementLabel",
"measurementType");
TS_ASSERT(!measurement.isUseable());
}
void test_invalid_construction_when_measurementSubId_empty() {
Measurement measurement("measurementId", "", "measurementLabel",
"measurementType");
TS_ASSERT(!measurement.isUseable());
}
void test_invalid_construction_when_label_empty() {
Measurement measurement("measurementId", "measurementSubId", "",
"measurementType");
TS_ASSERT(!measurement.isUseable());
}
void test_invalid_construction_when_type_empty() {
Measurement measurement("measurementId", "measurementSubId",
"measurementLabel", "");
TS_ASSERT(!measurement.isUseable());
}
};
#endif /* MANTIDQT_CUSTOMINTERFACES_MEASUREMENTTEST_H_ */
......@@ -91,6 +91,7 @@ public:
MOCK_CONST_METHOD0(macPrefix, const std::string());
MOCK_CONST_METHOD0(linuxPrefix, const std::string());
MOCK_CONST_METHOD0(clone, ICatalogInfo *());
MOCK_CONST_METHOD1(transformArchivePath, std::string(const std::string &));
virtual ~MockICatalogInfo() {}
};
......
......@@ -7,20 +7,20 @@
#include "MantidQtCustomInterfaces/ReflMeasurementSource.h"
#include <memory>
#include <gmock/gmock.h>
#include <utility>
using namespace testing;
using namespace MantidQt::CustomInterfaces;
class MockReflMeasurementSource
: public MantidQt::CustomInterfaces::ReflMeasurementSource {
public:
MOCK_CONST_METHOD1(
obtain, MantidQt::CustomInterfaces::Measurement(const std::string &));
MOCK_CONST_METHOD2(obtain, MantidQt::CustomInterfaces::Measurement(
const std::string &, const std::string &));
MOCK_CONST_METHOD0(clone, MockReflMeasurementSource *());
~MockReflMeasurementSource() {}
};
using MantidQt::CustomInterfaces::ReflMeasureTransferStrategy;
class ReflMeasureTransferStrategyTest : public CxxTest::TestSuite {
public:
// This pair of boilerplate methods prevent the suite being created statically
......@@ -32,6 +32,40 @@ public:
delete suite;
}
void test_obtain_single_measurement() {
SearchResultMap data;
data.insert(std::make_pair<std::string, SearchResult>(
"111", SearchResult("descr", "location")));
auto mockMeasurementSource = new MockReflMeasurementSource;
// We expect that we are going to fetch the measurement data for every
// search result.
EXPECT_CALL(*mockMeasurementSource, obtain(_, _))
.Times(Exactly(data.size()))
.WillRepeatedly(Return(Measurement("a", "s_a", "l", "t")));
auto mockCatInfo = new MockICatalogInfo;
// We expect that every location will be translated/transformed to make it
// os specific
EXPECT_CALL(*mockCatInfo, transformArchivePath(_))
.Times(Exactly(data.size()))
.WillRepeatedly(Return(std::string()));
MockProgressBase progress;
EXPECT_CALL(progress, doReport(_)).Times(Exactly(data.size()));
ReflMeasureTransferStrategy strategy(
std::move(std::unique_ptr<MockICatalogInfo>(mockCatInfo)),
std::move(
std::unique_ptr<MockReflMeasurementSource>(mockMeasurementSource)));
strategy.transferRuns(data, progress);
TS_ASSERT(Mock::VerifyAndClear(mockCatInfo));
TS_ASSERT(Mock::VerifyAndClear(mockMeasurementSource));
}
void test_clone() {
// Sub component ICatalogInfo will be cloned
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment