Skip to content

Commit

Permalink
Updated the tests and added a few more.
Browse files Browse the repository at this point in the history
Refs #7309
  • Loading branch information
arturbekasov committed Jul 25, 2013
1 parent 39fa9c4 commit 7267cb2
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 9 deletions.
31 changes: 22 additions & 9 deletions Code/Mantid/Framework/Algorithms/test/RenameWorkspaceTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,30 +66,43 @@ class RenameWorkspaceTest: public CxxTest::TestSuite
AnalysisDataService::Instance().remove("WSRenamed");
}

void testExecSameNames()
void testSameNames()
{
MatrixWorkspace_sptr inputWS = createWorkspace();
AnalysisDataService::Instance().add("InputWS", inputWS);

Mantid::Algorithms::RenameWorkspace alg3;
alg3.initialize();
TS_ASSERT_THROWS_NOTHING( alg3.setPropertyValue("InputWorkspace","InputWS"));
TS_ASSERT_THROWS_NOTHING( alg3.setPropertyValue("OutputWorkspace","InputWS"));

TS_ASSERT_THROWS_NOTHING( alg3.execute());
TS_ASSERT( !alg3.isExecuted());

Workspace_sptr result;
TS_ASSERT_THROWS_NOTHING(
result = AnalysisDataService::Instance().retrieveWS<Workspace>("InputWS"));
TS_ASSERT( result);
TS_ASSERT_THROWS( alg3.setPropertyValue("OutputWorkspace","InputWS"), std::invalid_argument);

AnalysisDataService::Instance().remove("InputWS");
}

void testExists()
{
MatrixWorkspace_sptr ws1 = createWorkspace();
AnalysisDataService::Instance().add("ws1", ws1);

MatrixWorkspace_sptr ws2 = createWorkspace();
AnalysisDataService::Instance().add("ws2", ws2);

Mantid::Algorithms::RenameWorkspace algInstance;
algInstance.initialize();

TS_ASSERT_THROWS_NOTHING(algInstance.setPropertyValue("InputWorkspace","ws1"));

TS_ASSERT_THROWS(algInstance.setPropertyValue("OutputWorkspace","ws2"), std::invalid_argument);

AnalysisDataService::Instance().remove("ws1");
AnalysisDataService::Instance().remove("ws2");
}

void testGroup()
{
AnalysisDataServiceImpl& ads = AnalysisDataService::Instance();

WorkspaceGroup_sptr group(new WorkspaceGroup);
ads.add("oldName",group);
MatrixWorkspace_sptr member1 = createWorkspace();
Expand Down
29 changes: 29 additions & 0 deletions Code/Mantid/Framework/Algorithms/test/RenameWorkspacesTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,35 @@ class RenameWorkspacesTest: public CxxTest::TestSuite
TS_ASSERT( algG.isExecuted());
}

/// Test that the method is not doing any renaming if one of the new workspace names
/// already exists in the ADS
void testDuplicates()
{
AnalysisDataServiceImpl& ads = AnalysisDataService::Instance();
MatrixWorkspace_sptr ws1 = createWorkspace();
ads.add("ws1", ws1);
MatrixWorkspace_sptr ws2 = createWorkspace();
ads.add("ws2", ws2);
MatrixWorkspace_sptr new_ws1 = createWorkspace();
ads.add("new_ws1", new_ws1);

Mantid::Algorithms::RenameWorkspaces algInstance;
algInstance.initialize();
algInstance.setRethrows(true);
TS_ASSERT_THROWS_NOTHING(algInstance.setPropertyValue("InputWorkspaces", "ws1, ws2"));
TS_ASSERT_THROWS_NOTHING(algInstance.setPropertyValue("Prefix", "new_"));

TS_ASSERT_THROWS(algInstance.execute(), std::invalid_argument);

// Check that old were not deleted
TS_ASSERT_THROWS_NOTHING(AnalysisDataService::Instance().retrieveWS<Workspace>("ws1"));
TS_ASSERT_THROWS_NOTHING(AnalysisDataService::Instance().retrieveWS<Workspace>("ws2"));
TS_ASSERT_THROWS_NOTHING(AnalysisDataService::Instance().retrieveWS<Workspace>("new_ws1"));

// Check that the new was not created
TS_ASSERT_THROWS(AnalysisDataService::Instance().retrieveWS<Workspace>("new_ws2"), Mantid::Kernel::Exception::NotFoundError);
}


MatrixWorkspace_sptr createWorkspace()
{
Expand Down

0 comments on commit 7267cb2

Please sign in to comment.