Skip to content
Snippets Groups Projects
Commit 11264bd0 authored by Gemma Guest's avatar Gemma Guest
Browse files

Add tests for polarization corrections enable/disabling

Re #22263
parent 2e669a20
Branches 22927_Fix_binary_op_not_saving_history_properly
No related tags found
No related merge requests found
......@@ -57,17 +57,16 @@ void ExperimentPresenter::onReductionResumed() { m_view->disableAll(); }
PolarizationCorrections ExperimentPresenter::polarizationCorrectionsFromView() {
auto const correctionType = polarizationCorrectionTypeFromString(
m_view->getPolarizationCorrectionType());
auto const cRho = m_view->getCRho();
auto const cAlpha = m_view->getCAlpha();
auto const cAp = m_view->getCAp();
auto const cPp = m_view->getCPp();
auto corrections =
PolarizationCorrections(correctionType, cRho, cAlpha, cAp, cPp);
if (corrections.enableInputs())
if (polarizationCorrectionRequiresInputs(correctionType)) {
m_view->enablePolarizationCorrectionInputs();
else
m_view->disablePolarizationCorrectionInputs();
return corrections;
return PolarizationCorrections(correctionType, m_view->getCRho(),
m_view->getCAlpha(), m_view->getCAp(),
m_view->getCPp());
}
m_view->disablePolarizationCorrectionInputs();
return PolarizationCorrections(correctionType);
}
boost::optional<RangeInLambda>
......
......@@ -23,11 +23,6 @@ boost::optional<double> PolarizationCorrections::cAp() const { return m_cAp; }
boost::optional<double> PolarizationCorrections::cPp() const { return m_cPp; }
bool PolarizationCorrections::enableInputs() const {
return m_correctionType == PolarizationCorrectionType::PA ||
m_correctionType == PolarizationCorrectionType::PNR;
}
bool operator!=(PolarizationCorrections const &lhs,
PolarizationCorrections const &rhs) {
return !(lhs == rhs);
......
......@@ -22,20 +22,25 @@ polarizationCorrectionTypeFromString(std::string const &correctionType) {
throw std::runtime_error("Unexpected polarization correction type.");
}
inline bool polarizationCorrectionRequiresInputs(
PolarizationCorrectionType correctionType) {
return (correctionType == PolarizationCorrectionType::PA ||
correctionType == PolarizationCorrectionType::PNR);
}
class MANTIDQT_ISISREFLECTOMETRY_DLL PolarizationCorrections {
public:
PolarizationCorrections(PolarizationCorrectionType correctionType,
boost::optional<double> CRho,
boost::optional<double> CAlpha,
boost::optional<double> CAp,
boost::optional<double> CPp);
boost::optional<double> CRho = boost::none,
boost::optional<double> CAlpha = boost::none,
boost::optional<double> CAp = boost::none,
boost::optional<double> CPp = boost::none);
PolarizationCorrectionType correctionType();
boost::optional<double> cRho() const;
boost::optional<double> cAlpha() const;
boost::optional<double> cAp() const;
boost::optional<double> cPp() const;
bool enableInputs() const;
private:
PolarizationCorrectionType m_correctionType;
......
......@@ -97,7 +97,7 @@ public:
verifyAndClear();
}
void testSetPolarizationCorrections() {
void testSetPolarizationCorrectionsUpdatesModel() {
auto presenter = makePresenter();
PolarizationCorrections polCorr(PolarizationCorrectionType::PA, 1.2, 1.3,
2.4, 2.5);
......@@ -115,6 +115,74 @@ public:
verifyAndClear();
}
void testSettingPolarizationCorrectionsToNoneDisablesInputs() {
auto presenter = makePresenter();
PolarizationCorrections polCorr(PolarizationCorrectionType::None);
expectViewReturnsDefaultAnalysisMode();
expectViewReturnsSumInLambdaDefaults();
EXPECT_CALL(m_view, getPolarizationCorrectionType())
.WillOnce(Return("None"));
EXPECT_CALL(m_view, disablePolarizationCorrectionInputs()).Times(1);
EXPECT_CALL(m_view, getCRho()).Times(0);
EXPECT_CALL(m_view, getCAlpha()).Times(0);
EXPECT_CALL(m_view, getCAp()).Times(0);
EXPECT_CALL(m_view, getCPp()).Times(0);
presenter.notifySettingsChanged();
verifyAndClear();
}
void testSetPolarizationCorrectionsToParameterFileDisablesInputs() {
auto presenter = makePresenter();
expectViewReturnsDefaultAnalysisMode();
expectViewReturnsSumInLambdaDefaults();
EXPECT_CALL(m_view, getPolarizationCorrectionType())
.WillOnce(Return("ParameterFile"));
EXPECT_CALL(m_view, disablePolarizationCorrectionInputs()).Times(1);
EXPECT_CALL(m_view, getCRho()).Times(0);
EXPECT_CALL(m_view, getCAlpha()).Times(0);
EXPECT_CALL(m_view, getCAp()).Times(0);
EXPECT_CALL(m_view, getCPp()).Times(0);
presenter.notifySettingsChanged();
verifyAndClear();
}
void testSettingPolarizationCorrectionsToPAEnablesInputs() {
auto presenter = makePresenter();
expectViewReturnsDefaultAnalysisMode();
expectViewReturnsSumInLambdaDefaults();
EXPECT_CALL(m_view, getPolarizationCorrectionType()).WillOnce(Return("PA"));
EXPECT_CALL(m_view, enablePolarizationCorrectionInputs()).Times(1);
EXPECT_CALL(m_view, getCRho()).Times(1);
EXPECT_CALL(m_view, getCAlpha()).Times(1);
EXPECT_CALL(m_view, getCAp()).Times(1);
EXPECT_CALL(m_view, getCPp()).Times(1);
presenter.notifySettingsChanged();
verifyAndClear();
}
void testSettingPolarizationCorrectionsToPNREnablesInputs() {
auto presenter = makePresenter();
expectViewReturnsDefaultAnalysisMode();
expectViewReturnsSumInLambdaDefaults();
EXPECT_CALL(m_view, getPolarizationCorrectionType())
.WillOnce(Return("PNR"));
EXPECT_CALL(m_view, enablePolarizationCorrectionInputs()).Times(1);
EXPECT_CALL(m_view, getCRho()).Times(1);
EXPECT_CALL(m_view, getCAlpha()).Times(1);
EXPECT_CALL(m_view, getCAp()).Times(1);
EXPECT_CALL(m_view, getCPp()).Times(1);
presenter.notifySettingsChanged();
verifyAndClear();
}
void testSetTransmissionRunRange() {
auto presenter = makePresenter();
RangeInLambda range(7.2, 10);
......
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