#ifndef MANTID_ALGORITHMS_CONVERTDIFFCALTEST_H_ #define MANTID_ALGORITHMS_CONVERTDIFFCALTEST_H_ #include <cxxtest/TestSuite.h> #include "MantidAPI/ITableWorkspace.h" #include "MantidAlgorithms/ConvertDiffCal.h" #include "MantidDataObjects/OffsetsWorkspace.h" #include "MantidTestHelpers/ComponentCreationHelper.h" using Mantid::Algorithms::ConvertDiffCal; using namespace Mantid::API; using Mantid::DataObjects::OffsetsWorkspace; using Mantid::DataObjects::OffsetsWorkspace_sptr; using Mantid::Kernel::V3D; class ConvertDiffCalTest : 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 ConvertDiffCalTest *createSuite() { return new ConvertDiffCalTest(); } static void destroySuite(ConvertDiffCalTest *suite) { delete suite; } void test_Init() { ConvertDiffCal alg; TS_ASSERT_THROWS_NOTHING(alg.initialize()); TS_ASSERT(alg.isInitialized()); } void test_exec() { // Create a fake offsets workspace auto instr = ComponentCreationHelper::createMinimalInstrument( V3D(0., 0., -10.), // source V3D(0., 0., 0.), // sample V3D(1., 0., 0.)); // detector OffsetsWorkspace_sptr offsets = boost::make_shared<OffsetsWorkspace>(instr); offsets->setValue(1, 0.); // wksp_index=0, detid=1 // Name of the output workspace. std::string outWSName("ConvertDiffCalTest_OutputWS"); ConvertDiffCal alg; TS_ASSERT_THROWS_NOTHING(alg.initialize()); TS_ASSERT(alg.isInitialized()); TS_ASSERT_THROWS_NOTHING(alg.setProperty("OffsetsWorkspace", offsets)); TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("OutputWorkspace", outWSName)); TS_ASSERT_THROWS_NOTHING(alg.execute();); TS_ASSERT(alg.isExecuted()); // Retrieve the workspace from data service. TODO: Change to your desired // type Workspace_sptr ws; TS_ASSERT_THROWS_NOTHING( ws = AnalysisDataService::Instance().retrieveWS<Workspace>(outWSName)); TS_ASSERT(ws); if (!ws) return; // test various values auto table = boost::dynamic_pointer_cast<ITableWorkspace>(ws); TS_ASSERT(table); std::vector<std::string> columnNames = table->getColumnNames(); TS_ASSERT_EQUALS(columnNames.size(), 4); TS_ASSERT_EQUALS(columnNames[0], "detid"); TS_ASSERT_EQUALS(columnNames[1], "difc"); auto detid = table->getColumn("detid"); TS_ASSERT(detid); TS_ASSERT_EQUALS(detid->toDouble(0), 1.); auto difc = table->getColumn("difc"); TS_ASSERT(difc); TS_ASSERT_DELTA(difc->toDouble(0), 3932.3, .1); auto difa = table->getColumn("difa"); TS_ASSERT(difa); TS_ASSERT_EQUALS(difa->toDouble(0), 0.); auto tzero = table->getColumn("tzero"); TS_ASSERT(tzero); TS_ASSERT_EQUALS(tzero->toDouble(0), 0.); // Remove workspace from the data service. AnalysisDataService::Instance().remove(outWSName); } }; #endif /* MANTID_ALGORITHMS_CONVERTDIFFCALTEST_H_ */