diff --git a/src/@dseries/rename.m b/src/@dseries/rename.m index 2a038595d71e941bb5d7ae8c2fbc1eb5d11f4ecf..517dc3cd083c0b8dbdd0549e898b37bf6c49d481 100644 --- a/src/@dseries/rename.m +++ b/src/@dseries/rename.m @@ -17,14 +17,28 @@ function ts = rename(ts,old,new) % --*-- Unitary tests --*-- % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. -if ~ischar(old) || ~ischar(new) - error(['dseries::rename: Input arguments ''' inputname(2) ''' and ''' inputname(3) ''' have to be strings!']) +if isempty(ts) + error('dseries::rename: Cannot rename variable(s) because the object is empty!') end - -idname = find(strcmp(old,ts.name)); -if isempty(idname) - error(['dseries::rename: Variable ' old ' is unknown in dseries object ' inputname(1) '!']) +if nargin<3 + if isequal(vobs(ts), 1) + new = old; + else + error('dseries::rename: Missing argument!') + end + if ~ischar(new) + error(['dseries::rename: Input argument ''' inputname(2) ''' has to be a string!']) + end + idname = 1; +else + if ~ischar(old) || ~ischar(new) + error(['dseries::rename: Input arguments ''' inputname(2) ''' and ''' inputname(3) ''' have to be strings!']) + end + idname = find(strcmp(old,ts.name)); + if isempty(idname) + error(['dseries::rename: Variable ' old ' is unknown in dseries object ' inputname(1) '!']) + end end ts.name(idname) = {new}; @@ -74,3 +88,20 @@ ts.name(idname) = {new}; %$ %$ T = all(t); %@eof:2 + +%@test:3 +%$ t = zeros(2,1); +%$ ts = dseries(randn(10,1)); +%$ try +%$ ts = ts.rename('Dora'); +%$ t(1) = 1; +%$ catch +%$ t = 0; +%$ end +%$ +%$ if length(t)>1 +%$ t(2) = dassert(ts.name,{'Dora'}); +%$ end +%$ +%$ T = all(t); +%@eof:3 diff --git a/tests/runalldseriestests.m b/tests/runalldseriestests.m index eba08296a7de1004776f3b7ac736dc4fad9a459e..a06d60aea75a5cb8b38f4541346bd80b7cac79c5 100644 --- a/tests/runalldseriestests.m +++ b/tests/runalldseriestests.m @@ -1,6 +1,9 @@ opath = path(); % Check that the m-unit-tests module is available. + +install_unit_test_toolbox = false; + try initialize_unit_tests_toolbox; catch @@ -12,6 +15,7 @@ catch delete('master.zip') addpath([pwd() '/../externals/m-unit-tests-master/src']) initialize_unit_tests_toolbox; + install_unit_test_toolbox = true; end % Initialize the dseries module @@ -28,5 +32,8 @@ tmp = tmp(1:end-1); % Remove trailing slash. run_unitary_tests_in_directory(tmp); delete('*.log'); -rmdir('../externals/m-unit-tests-master','s'); + +if install_unit_test_toolbox + rmdir('../externals/m-unit-tests-master','s'); +end path(opath); \ No newline at end of file