diff --git a/Code/Mantid/API/inc/MantidAPI/WorkspaceProperty.h b/Code/Mantid/API/inc/MantidAPI/WorkspaceProperty.h index f08a2c53cede92f98517264de25db1931ef3248e..c109f5ec279fa071f4267a1b867596e9ea538956 100644 --- a/Code/Mantid/API/inc/MantidAPI/WorkspaceProperty.h +++ b/Code/Mantid/API/inc/MantidAPI/WorkspaceProperty.h @@ -111,6 +111,7 @@ public: if ( ! value.empty() ) { m_workspaceName = value; + Kernel::PropertyWithValue<boost::shared_ptr<TYPE> >::m_isDefault = false; return true; } // Setting an empty workspace name is not allowed diff --git a/Code/Mantid/API/test/AlgorithmHistoryTest.h b/Code/Mantid/API/test/AlgorithmHistoryTest.h index ebaacb395b30c8395b3dea0dfb9a958e480c55a9..1e60875f8fa6e2d7b18d7b9f6168e985f89ac31e 100644 --- a/Code/Mantid/API/test/AlgorithmHistoryTest.h +++ b/Code/Mantid/API/test/AlgorithmHistoryTest.h @@ -41,7 +41,7 @@ public: correctOutput = correctOutput + "\n"; correctOutput = correctOutput + " Name: arg1_param\n"; correctOutput = correctOutput + " Value: 20\n"; - correctOutput = correctOutput + " isDefault: Yes\n"; + correctOutput = correctOutput + " isDefault: No\n"; correctOutput = correctOutput + " Direction: Input\n"; correctOutput = correctOutput + "\n"; correctOutput = correctOutput + " Name: arg2_param\n"; diff --git a/Code/Mantid/API/test/WorkspacePropertyTest.h b/Code/Mantid/API/test/WorkspacePropertyTest.h index a3adc75a4ef5b8afaa20d02feda7e2191ee84283..3be39aa04fa45517ab90c2d5d6ded02186263768 100644 --- a/Code/Mantid/API/test/WorkspacePropertyTest.h +++ b/Code/Mantid/API/test/WorkspacePropertyTest.h @@ -12,8 +12,8 @@ using namespace Mantid::Kernel; using namespace Mantid::API; class WorkspacePropertyTest : public CxxTest::TestSuite -{ - +{ + //private test class - using this removes the dependency on the DataObjects library class WorkspaceTest: public Workspace { @@ -28,7 +28,7 @@ class WorkspacePropertyTest : public CxxTest::TestSuite virtual std::vector<double>& dataY(int const index) {return data;} ///Returns the error data virtual std::vector<double>& dataE(int const index) {return data;} - + virtual const std::vector<double>& dataX(int const index)const {return data;} ///Returns the y data virtual const std::vector<double>& dataY(int const index)const {return data;} @@ -42,7 +42,7 @@ class WorkspacePropertyTest : public CxxTest::TestSuite ///Sets the ErrorHelper for this spectra virtual void setErrorHelper(int const index,const IErrorHelper* errorHelper) {} - + //Methods for getting data via python. Do not use for anything else! ///Returns the x data const virtual const std::vector<double>& getX(int const index) const {return data;} @@ -50,7 +50,7 @@ class WorkspacePropertyTest : public CxxTest::TestSuite virtual const std::vector<double>& getY(int const index) const {return data;} ///Returns the error const virtual const std::vector<double>& getE(int const index) const {return data;} - + private: std::vector<double> data; int dummy; @@ -70,7 +70,7 @@ class WorkspacePropertyTest : public CxxTest::TestSuite virtual std::vector<double>& dataY(int const index) {return data;} ///Returns the error data virtual std::vector<double>& dataE(int const index) {return data;} - + virtual const std::vector<double>& dataX(int const index)const {return data;} ///Returns the y data virtual const std::vector<double>& dataY(int const index)const {return data;} @@ -84,7 +84,7 @@ class WorkspacePropertyTest : public CxxTest::TestSuite ///Sets the ErrorHelper for this spectra virtual void setErrorHelper(int const index,const IErrorHelper* errorHelper) {} - + //Methods for getting data via python. Do not use for anything else! ///Returns the x data const virtual const std::vector<double>& getX(int const index) const {return data;} @@ -92,7 +92,7 @@ class WorkspacePropertyTest : public CxxTest::TestSuite virtual const std::vector<double>& getY(int const index) const {return data;} ///Returns the error const virtual const std::vector<double>& getE(int const index) const {return data;} - + private: std::vector<double> data; int dummy; @@ -117,7 +117,7 @@ public: { TS_ASSERT_THROWS( WorkspaceProperty<Workspace>("test","",3), std::out_of_range ) } - + void testValue() { TS_ASSERT( ! wsp1->value().compare("ws1") ) @@ -152,7 +152,7 @@ public: TS_ASSERT_THROWS_NOTHING(space = WorkspaceFactory::Instance().create("WorkspacePropertyTest") ); TS_ASSERT_THROWS_NOTHING( AnalysisDataService::Instance().add("ws1", space) ); TS_ASSERT( wsp1->isValid() ) - + // Put workspace of wrong type and check validation fails TS_ASSERT_THROWS_NOTHING( AnalysisDataService::Instance().add("ws3", space) ); TS_ASSERT( ! wsp3->isValid() ) @@ -169,18 +169,43 @@ public: TS_ASSERT_EQUALS( vals.size(), 2 ) TS_ASSERT_EQUALS( vals[0], "ws1" ) TS_ASSERT_EQUALS( vals[1], "ws3" ) - + TS_ASSERT( wsp2->allowedValues().empty() ) TS_ASSERT_THROWS_NOTHING( vals = wsp3->allowedValues() ) TS_ASSERT_EQUALS( vals.size(), 2 ) } - + + void testCreateHistory() + { + PropertyHistory history = wsp1->createHistory(); + TS_ASSERT_EQUALS( history.name(), "workspace1" ) + TS_ASSERT_EQUALS( history.value(), "ws1" ) + TS_ASSERT( ! history.isDefault() ) + TS_ASSERT_EQUALS( history.type(), wsp1->type() ) + TS_ASSERT_EQUALS( history.direction(), 0 ) + + PropertyHistory history2 = wsp2->createHistory(); + TS_ASSERT_EQUALS( history2.name(), "workspace2" ) + TS_ASSERT_EQUALS( history2.value(), "ws2" ) + TS_ASSERT( ! history2.isDefault() ) + TS_ASSERT_EQUALS( history2.type(), wsp2->type() ) + TS_ASSERT_EQUALS( history2.direction(), 1 ) + + PropertyHistory history3 = wsp3->createHistory(); + TS_ASSERT_EQUALS( history3.name(), "workspace3" ) + TS_ASSERT_EQUALS( history3.value(), "ws3" ) + TS_ASSERT( history3.isDefault() ) + TS_ASSERT_EQUALS( history3.type(), wsp3->type() ) + TS_ASSERT_EQUALS( history3.direction(), 2 ) + + } + void testStore() { // This is an input workspace so should return false TS_ASSERT( ! wsp1->store() ) - + // Since no workspace has been assigned to this output property, it should throw TS_ASSERT_THROWS( wsp2->store(), std::runtime_error ) // So now create and assign the workspace and test again @@ -192,7 +217,7 @@ public: Workspace_sptr storedspace; TS_ASSERT_THROWS_NOTHING( storedspace = AnalysisDataService::Instance().retrieve("ws2") ) TS_ASSERT( ! storedspace->id().compare("WorkspacePropTest") ) - + // This one should pass TS_ASSERT( wsp3->store() ) @@ -208,7 +233,7 @@ public: TS_ASSERT_EQUALS( wsp2->direction(), 1 ) TS_ASSERT_EQUALS( wsp3->direction(), 2 ) } - + private: WorkspaceProperty<Workspace> *wsp1; WorkspaceProperty<Workspace> *wsp2; diff --git a/Code/Mantid/DataObjects/test/WorkspaceHistoryTest.h b/Code/Mantid/DataObjects/test/WorkspaceHistoryTest.h index 9a0496ff6ca06b4d20994e2df2400720cfa182b1..d4437b57a6e6253a11d438e1c927e35ea03ad42e 100644 --- a/Code/Mantid/DataObjects/test/WorkspaceHistoryTest.h +++ b/Code/Mantid/DataObjects/test/WorkspaceHistoryTest.h @@ -199,15 +199,15 @@ public: // isdefault is true for all parameters because a setProperty has not been called on them TS_ASSERT_EQUALS(C_AP[0].name(),"InWS_1"); TS_ASSERT_EQUALS(C_AP[0].value(),"A"); - TS_ASSERT_EQUALS(C_AP[0].isDefault(),true); + TS_ASSERT_EQUALS(C_AP[0].isDefault(),false); TS_ASSERT_EQUALS(C_AP[0].direction(),0); TS_ASSERT_EQUALS(C_AP[1].name(),"InWS_2"); TS_ASSERT_EQUALS(C_AP[1].value(),"B"); - TS_ASSERT_EQUALS(C_AP[1].isDefault(),true); + TS_ASSERT_EQUALS(C_AP[1].isDefault(),false); TS_ASSERT_EQUALS(C_AP[1].direction(),0); TS_ASSERT_EQUALS(C_AP[2].name(),"InoutWS"); TS_ASSERT_EQUALS(C_AP[2].value(),"C"); - TS_ASSERT_EQUALS(C_AP[2].isDefault(),true); + TS_ASSERT_EQUALS(C_AP[2].isDefault(),false); TS_ASSERT_EQUALS(C_AP[2].direction(),2); // Test streamed output. diff --git a/Code/Mantid/Kernel/inc/MantidKernel/Property.h b/Code/Mantid/Kernel/inc/MantidKernel/Property.h index b2faa7391d7433323d8b0ea9e09ec542489adfa1..9144a1d58bc47618f1b8d91a5f33294ca49641d7 100644 --- a/Code/Mantid/Kernel/inc/MantidKernel/Property.h +++ b/Code/Mantid/Kernel/inc/MantidKernel/Property.h @@ -67,7 +67,6 @@ public: virtual const std::vector<std::string> allowedValues() const; - /// Create a PropertyHistory object representing the current state of the Property. virtual const PropertyHistory createHistory() const; protected: diff --git a/Code/Mantid/Kernel/src/Property.cpp b/Code/Mantid/Kernel/src/Property.cpp index 950fc455840cd2c4bf0baab1cc2e7e2c642ea806..d4aaff831ce92906f727befe60156590f3b99516 100644 --- a/Code/Mantid/Kernel/src/Property.cpp +++ b/Code/Mantid/Kernel/src/Property.cpp @@ -114,6 +114,7 @@ const std::vector<std::string> Property::allowedValues() const return std::vector<std::string>(); } +/// Create a PropertyHistory object representing the current state of the Property. const PropertyHistory Property::createHistory() const { return PropertyHistory(this->name(),this->value(),this->type(),this->isDefault()); diff --git a/Code/Mantid/Kernel/test/PropertyTest.h b/Code/Mantid/Kernel/test/PropertyTest.h index d1aecdb43de3a98c034a5a425ff2528d46b562da..ee257734d3bc260b758fa63efe8d2acd167d72eb 100644 --- a/Code/Mantid/Kernel/test/PropertyTest.h +++ b/Code/Mantid/Kernel/test/PropertyTest.h @@ -23,7 +23,7 @@ public: { p = new PropertyHelper; } - + void testName() { TS_ASSERT( ! p->name().compare("Test") ) @@ -46,7 +46,7 @@ public: TS_ASSERT( ! p->type().compare("i") ) #else TS_ASSERT( ! p->type().compare("int") ) -#endif +#endif } void testIsValid() @@ -70,10 +70,20 @@ public: { TS_ASSERT( p->allowedValues().empty() ) } - + + void testCreateHistory() + { + PropertyHistory history = p->createHistory(); + TS_ASSERT_EQUALS( history.name(), "Test" ) + TS_ASSERT_EQUALS( history.value(), "Nothing" ) + TS_ASSERT( history.isDefault() ) + TS_ASSERT_EQUALS( history.type(), p->type() ) + TS_ASSERT_EQUALS( history.direction(), 99 ) + } + private: Property *p; - + }; #endif /*PROPERTYTEST_H_*/