Commit 588d8056 authored by Robert Applin's avatar Robert Applin
Browse files

Refs #28842. Update tests.

parent 6c907055
......@@ -149,6 +149,7 @@ public:
EXPECT_CALL(*m_model, extractSingleTube()).Times(1);
EXPECT_CALL(*m_model, WSName()).Times(1).WillOnce(Return("test"));
EXPECT_CALL(*m_pane, addSpectrum("test")).Times(1);
EXPECT_CALL(*m_pane, updateEstimateAfterExtraction()).Times(1);
m_presenter->extractSingleTube();
}
......
......@@ -17,6 +17,8 @@
#include "MantidTestHelpers/WorkspaceCreationHelper.h"
#include "MantidAPI/FrameworkManager.h"
#include "MantidAPI/FunctionFactory.h"
#include "MantidAPI/IFunction.h"
#include "MantidAPI/MatrixWorkspace_fwd.h"
#include "MantidGeometry/Instrument.h"
#include "MantidKernel/WarningSuppressions.h"
......@@ -45,6 +47,8 @@ public:
MOCK_METHOD0(getCurrentWS, std::string());
MOCK_METHOD0(clearCurrentWS, void());
MOCK_METHOD0(doFit, void());
MOCK_METHOD0(updateEstimateAfterExtraction, void());
MOCK_METHOD0(updateEstimate, void());
MOCK_METHOD1(addSpectrum, void(const std::string &name));
// at runtime the cast is done, so mock it ourselves
void addFunction(IFunction_sptr func) override {
......@@ -69,13 +73,14 @@ public:
};
~MockPlotFitAnalysisPaneView(){};
MOCK_METHOD1(observeFitButton, void(Observer *listener));
MOCK_METHOD1(observeUpdateEstimateButton, void(Observer *listener));
MOCK_METHOD0(getRange, std::pair<double, double>());
MOCK_METHOD0(getFunction, Mantid::API::IFunction_sptr());
MOCK_METHOD1(addSpectrum, void(const std::string &name));
MOCK_METHOD1(addFitSpectrum, void(const std::string &name));
MOCK_METHOD1(addFunction, void(Mantid::API::IFunction_sptr));
MOCK_METHOD1(updateFunction, void(const Mantid::API::IFunction_sptr));
MOCK_METHOD1(fitWarning, void(const std::string &message));
MOCK_METHOD1(displayWarning, void(const std::string &message));
MOCK_METHOD0(getQWidget, QWidget *());
MOCK_METHOD2(setupPlotFitSplitter,
......@@ -87,18 +92,36 @@ public:
class MockPlotFitAnalysisPaneModel
: public MantidQt::MantidWidgets::PlotFitAnalysisPaneModel {
public:
MockPlotFitAnalysisPaneModel() { m_count = 0; };
MockPlotFitAnalysisPaneModel() {
m_fitCount = 0;
m_estimateCount = 0;
};
~MockPlotFitAnalysisPaneModel(){};
IFunction_sptr doFit(const std::string &wsName,
const std::pair<double, double> &range,
const IFunction_sptr func) override {
m_count += 1;
m_fitCount += 1;
(void)wsName;
(void)range;
return func;
};
int getCount() { return m_count; };
IFunction_sptr
calculateEstimate(const std::string &workspaceName,
const std::pair<double, double> &range) override {
(void)workspaceName;
(void)range;
m_estimateCount += 1;
return FunctionFactory::Instance().createFunction("Gaussian");
};
bool hasEstimate() const override { return m_estimateCount > 0; };
int getFitCount() { return m_fitCount; };
int getEstimateCount() { return m_estimateCount; };
private:
int m_count;
int m_fitCount;
int m_estimateCount;
};
......@@ -44,6 +44,8 @@ public:
m_view = new NiceMock<MockPlotFitAnalysisPaneView>();
m_model = new MockPlotFitAnalysisPaneModel();
m_presenter = new PlotFitAnalysisPanePresenter(m_view, m_model);
m_workspaceName = "test";
m_range = std::make_pair(0.0, 1.0);
}
void tearDown() override {
......@@ -54,10 +56,9 @@ public:
}
void test_doFit() {
std::string name = "test";
// set name via addSpectrum
EXPECT_CALL(*m_view, addSpectrum(name)).Times(1);
m_presenter->addSpectrum(name);
EXPECT_CALL(*m_view, addSpectrum(m_workspaceName)).Times(1);
m_presenter->addSpectrum(m_workspaceName);
// set up rest of test
IFunction_sptr function =
......@@ -65,32 +66,54 @@ public:
"name = FlatBackground");
EXPECT_CALL(*m_view, getFunction()).Times(1).WillOnce(Return(function));
std::pair<double, double> range = std::make_pair(0.0, 1.0);
EXPECT_CALL(*m_view, getRange()).Times(1).WillOnce(Return(range));
EXPECT_CALL(*m_view, getRange()).Times(1).WillOnce(Return(m_range));
EXPECT_CALL(*m_view, updateFunction(function));
m_presenter->doFit();
TS_ASSERT_EQUALS(m_model->getCount(), 1);
TS_ASSERT_EQUALS(m_model->getFitCount(), 1);
}
void test_addFunction() {
IFunction_sptr function =
Mantid::API::FunctionFactory::Instance().createInitialized(
"name = FlatBackground");
auto function = Mantid::API::FunctionFactory::Instance().createInitialized(
"name = FlatBackground");
EXPECT_CALL(*m_view, addFunction(function)).Times(1);
m_presenter->addFunction(function);
}
void test_addSpectrum() {
std::string name = "test";
EXPECT_CALL(*m_view, addSpectrum(name)).Times(1);
m_presenter->addSpectrum(name);
EXPECT_CALL(*m_view, addSpectrum(m_workspaceName)).Times(1);
m_presenter->addSpectrum(m_workspaceName);
}
void
test_that_calculateEstimate_is_not_called_when_the_current_workspace_name_is_blank() {
EXPECT_CALL(*m_view,
displayWarning(
"Could not update estimate: data has not been extracted."))
.Times(1);
m_presenter->updateEstimate();
TS_ASSERT_EQUALS(m_model->getEstimateCount(), 0);
TS_ASSERT(!m_model->hasEstimate());
}
void test_that_calculateEstimate_is_called_as_expected() {
EXPECT_CALL(*m_view, addSpectrum(m_workspaceName)).Times(1);
m_presenter->addSpectrum(m_workspaceName);
EXPECT_CALL(*m_view, getRange()).Times(1).WillOnce(Return(m_range));
m_presenter->updateEstimate();
TS_ASSERT_EQUALS(m_model->getEstimateCount(), 1);
TS_ASSERT(m_model->hasEstimate());
}
private:
NiceMock<MockPlotFitAnalysisPaneView> *m_view;
MockPlotFitAnalysisPaneModel *m_model;
PlotFitAnalysisPanePresenter *m_presenter;
std::string m_workspaceName;
std::pair<double, double> m_range;
};
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment