Skip to content
Snippets Groups Projects
EnggDiffMultiRunFittingWidgetModelTest.h 3.1 KiB
Newer Older
#ifndef MANTIDQT_CUSTOMINTERFACES_ENGGDIFFMULTIRUNFITTINGWIDGETMODELTEST_H_
#define MANTIDQT_CUSTOMINTERFACES_ENGGDIFFMULTIRUNFITTINGWIDGETMODELTEST_H_

#include "../EnggDiffraction/EnggDiffMultiRunFittingWidgetModel.h"

#include "MantidTestHelpers/WorkspaceCreationHelper.h"

#include <cxxtest/TestSuite.h>

using namespace MantidQt::CustomInterfaces;

class EnggDiffMultiRunFittingWidgetModelTest : public CxxTest::TestSuite {
public:
  void test_addAndGetFittedPeak() {
    EnggDiffMultiRunFittingWidgetModel model;

    Mantid::API::MatrixWorkspace_sptr ws =
        WorkspaceCreationHelper::create2DWorkspaceBinned(4, 4, 0.5);
    const RunLabel runLabel(123, 1);
    TS_ASSERT_THROWS_NOTHING(model.addFittedPeaks(runLabel, ws));

    boost::optional<Mantid::API::MatrixWorkspace_sptr> retrievedWS(boost::none);
    TS_ASSERT_THROWS_NOTHING(retrievedWS = model.getFittedPeaks(runLabel));
    TS_ASSERT(retrievedWS);
    TS_ASSERT_EQUALS(ws, *retrievedWS);
  void test_getFittedPeaksSucceedsWhenWorkspaceNotInModel() {
    EnggDiffMultiRunFittingWidgetModel model;
    boost::optional<Mantid::API::MatrixWorkspace_sptr> retrievedWS(boost::none);
    TS_ASSERT_THROWS_NOTHING(retrievedWS =
                                 model.getFittedPeaks(RunLabel(123, 1)));
    TS_ASSERT(!retrievedWS);
  }

  void test_addAndGetFocusedRun() {
    EnggDiffMultiRunFittingWidgetModel model;

    Mantid::API::MatrixWorkspace_sptr ws =
        WorkspaceCreationHelper::create2DWorkspaceBinned(4, 4, 0.5);
    const RunLabel runLabel(123, 1);
    TS_ASSERT_THROWS_NOTHING(model.addFocusedRun(runLabel, ws));

    boost::optional<Mantid::API::MatrixWorkspace_sptr> retrievedWS(boost::none);
    TS_ASSERT_THROWS_NOTHING(retrievedWS = model.getFocusedRun(runLabel));
    TS_ASSERT(retrievedWS);
    TS_ASSERT_EQUALS(ws, *retrievedWS);
  void test_getFocusedRunSucceedsWhenWorkspaceNotInModel() {
    EnggDiffMultiRunFittingWidgetModel model;
    boost::optional<Mantid::API::MatrixWorkspace_sptr> retrievedWS(boost::none);
    TS_ASSERT_THROWS_NOTHING(retrievedWS =
                                 model.getFocusedRun(RunLabel(123, 1)));
    TS_ASSERT(!retrievedWS);
  }

  void test_getAllWorkspaceLabels() {
    EnggDiffMultiRunFittingWidgetModel model;

    Mantid::API::MatrixWorkspace_sptr ws =
        WorkspaceCreationHelper::create2DWorkspaceBinned(4, 4, 0.5);

    const RunLabel label1(123, 1);
    model.addFocusedRun(label1, ws);
    const RunLabel label2(456, 2);
    model.addFocusedRun(label2, ws);
    const std::vector<RunLabel> expectedLabels1({label1, label2});

    std::vector<RunLabel> retrievedLabels;
    TS_ASSERT_THROWS_NOTHING(retrievedLabels = model.getAllWorkspaceLabels());
    TS_ASSERT_EQUALS(expectedLabels1, retrievedLabels);
    const RunLabel label3(456, 1);
    model.addFocusedRun(label3, ws);
    model.addFittedPeaks(RunLabel(123, 2), ws);
    const std::vector<RunLabel> expectedLabels2 = {label1, label3, label2};
    TS_ASSERT_THROWS_NOTHING(retrievedLabels = model.getAllWorkspaceLabels());
    TS_ASSERT_EQUALS(expectedLabels2, retrievedLabels);
  }
};

#endif // MANTIDQT_CUSTOMINTERFACES_ENGGDIFFMULTIRUNFITTINGWIDGETMODELTEST_H_