diff --git a/src/@dates/append.m b/src/@dates/append.m index 231da9731b428446311601cce85927df0c3df09d..1bef79eccb3f8fe4f8b101c913635262930fa2c3 100644 --- a/src/@dates/append.m +++ b/src/@dates/append.m @@ -4,12 +4,12 @@ function o = append(o, d) % --*-- Unitary tests --*-- % % INPUTS % - o [dates] -% - a [dates or string] dates object with one element or string that can be interpreted as a date. +% - d [dates,char] date to be appended (if not a dates object, it must be a row char array that can be interpreted as a date). % % OUTPUTS -% - o [dates] dates object containing dates defined in o and d. +% - o [dates] containing dates defined in o and d. -% Copyright (C) 2012-2017 Dynare Team +% Copyright © 2012-2020 Dynare Team % % This code is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by @@ -42,95 +42,97 @@ end o = copy(o); o.append_(d); +return + %@test:1 -%$ % Define some dates -%$ B1 = '1953Q4'; -%$ B2 = '1950Q2'; -%$ B3 = '1950Q1'; -%$ B4 = '1945Q3'; -%$ B5 = '2009Q2'; -%$ -%$ % Define expected results. -%$ e.time = [1945 3; 1950 1; 1950 2; 1953 4]; -%$ e.freq = 4; -%$ -%$ % Call the tested routine. -%$ d = dates(B4,B3,B2,B1); -%$ try -%$ d.append(dates(B5)); -%$ t(1) = true; -%$ catch -%$ t(1) = false; -%$ end -%$ -%$ % Check the results. -%$ if t(1) -%$ t(2) = dassert(d.time,e.time); -%$ t(3) = dassert(d.freq,e.freq); -%$ end -%$ T = all(t); +% Define some dates +B1 = '1953Q4'; +B2 = '1950Q2'; +B3 = '1950Q1'; +B4 = '1945Q3'; +B5 = '2009Q2'; + +% Define expected results. +e.time = [1945 3; 1950 1; 1950 2; 1953 4]; +e.freq = 4; + +% Call the tested routine. +d = dates(B4,B3,B2,B1); +try + d.append(dates(B5)); + t(1) = true; +catch + t(1) = false; +end + +% Check the results. +if t(1) + t(2) = isequal(d.time,e.time); + t(3) = isequal(d.freq,e.freq); +end +T = all(t); %@eof:1 %@test:2 -%$ % Define some dates -%$ B1 = '1953Q4'; -%$ B2 = '1950Q2'; -%$ B3 = '1950Q1'; -%$ B4 = '1945Q3'; -%$ B5 = '2009q2'; -%$ -%$ % Define expected results. -%$ e.time = [1945 3; 1950 1; 1950 2; 1953 4; 2009 2]; -%$ f.time = [1945 3; 1950 1; 1950 2; 1953 4]; -%$ e.freq = 4; -%$ -%$ % Call the tested routine. -%$ d = dates(B4,B3,B2,B1); -%$ try -%$ c = d.append(B5); -%$ t(1) = true; -%$ catch -%$ t(1) = false; -%$ end -%$ -%$ % Check the results. -%$ if t(1) -%$ t(2) = dassert(d.time,f.time); -%$ t(3) = dassert(c.time,e.time); -%$ t(4) = dassert(c.freq,e.freq); -%$ t(5) = dassert(d.freq,e.freq); -%$ end -%$ T = all(t); +% Define some dates +B1 = '1953Q4'; +B2 = '1950Q2'; +B3 = '1950Q1'; +B4 = '1945Q3'; +B5 = '2009q2'; + +% Define expected results. +e.time = [1945 3; 1950 1; 1950 2; 1953 4; 2009 2]; +f.time = [1945 3; 1950 1; 1950 2; 1953 4]; +e.freq = 4; + +% Call the tested routine. +d = dates(B4,B3,B2,B1); +try + c = d.append(B5); + t(1) = true; +catch + t(1) = false; +end + +% Check the results. +if t(1) + t(2) = isequal(d.time,f.time); + t(3) = isequal(c.time,e.time); + t(4) = isequal(c.freq,e.freq); + t(5) = isequal(d.freq,e.freq); +end +T = all(t); %@eof:2 %@test:3 -%$ % Define some dates -%$ B1 = '1953Q4'; -%$ B2 = '1950Q2'; -%$ B3 = '1950Q1'; -%$ B4 = '1945Q3'; -%$ B5 = '2009q2'; -%$ -%$ % Define expected results. -%$ e.time = [1945 3; 1950 1; 1950 2; 1953 4; 2009 2]; -%$ f.time = [1945 3; 1950 1; 1950 2; 1953 4]; -%$ e.freq = 4; -%$ -%$ % Call the tested routine. -%$ d = dates(B4,B3,B2,B1); -%$ try -%$ c = append(d, B5); -%$ t(1) = true; -%$ catch -%$ t(1) = false; -%$ end -%$ -%$ % Check the results. -%$ if t(1) -%$ t(2) = dassert(d.time,f.time); -%$ t(3) = dassert(c.time,e.time); -%$ t(4) = dassert(c.freq,e.freq); -%$ t(5) = dassert(d.freq,e.freq); -%$ end -%$ T = all(t); +% Define some dates +B1 = '1953Q4'; +B2 = '1950Q2'; +B3 = '1950Q1'; +B4 = '1945Q3'; +B5 = '2009q2'; + +% Define expected results. +e.time = [1945 3; 1950 1; 1950 2; 1953 4; 2009 2]; +f.time = [1945 3; 1950 1; 1950 2; 1953 4]; +e.freq = 4; + +% Call the tested routine. +d = dates(B4,B3,B2,B1); +try + c = append(d, B5); + t(1) = true; +catch + t(1) = false; +end + +% Check the results. +if t(1) + t(2) = isequal(d.time,f.time); + t(3) = isequal(c.time,e.time); + t(4) = isequal(c.freq,e.freq); + t(5) = isequal(d.freq,e.freq); +end +T = all(t); %@eof:3 diff --git a/src/@dates/append_.m b/src/@dates/append_.m index 2c4a3a8de26826ebafb175c6518c71f998382481..5b676d13656a9e7ac6893102bddaf94485699182 100644 --- a/src/@dates/append_.m +++ b/src/@dates/append_.m @@ -4,12 +4,12 @@ function o = append_(o, d) % --*-- Unitary tests --*-- % % INPUTS % - o [dates] -% - a [dates or string] dates object with one element or string that can be interpreted as a date. +% - d [dates,char] date to be appended (if not a dates object, it must be a row char array that can be interpreted as a date). % % OUTPUTS % - o [dates] dates object containing dates defined in o and d. -% Copyright (C) 2012-2017 Dynare Team +% Copyright © 2012-2020 Dynare Team % % This code is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by @@ -41,149 +41,191 @@ end o.time = [o.time; d.time]; +return + %@test:1 -%$ % Define some dates -%$ B1 = '1953Q4'; -%$ B2 = '1950Q2'; -%$ B3 = '1950Q1'; -%$ B4 = '1945Q3'; -%$ B5 = '2009Q2'; -%$ -%$ % Define expected results. -%$ e.time = [1945 3; 1950 1; 1950 2; 1953 4; 2009 2]; -%$ e.freq = 4; -%$ -%$ % Call the tested routine. -%$ d = dates(B4,B3,B2,B1); -%$ try -%$ d.append_(dates(B5)); -%$ t(1) = true; -%$ catch -%$ t(1) = false; -%$ end -%$ -%$ % Check the results. -%$ if t(1) -%$ t(2) = dassert(d.time,e.time); -%$ t(3) = dassert(d.freq,e.freq); -%$ end -%$ T = all(t); +% Define some dates +B1 = '1953Q4'; +B2 = '1950Q2'; +B3 = '1950Q1'; +B4 = '1945Q3'; +B5 = '2009Q2'; + +% Define expected results. +e.time = [1945 3; 1950 1; 1950 2; 1953 4; 2009 2]; +e.freq = 4; + +% Call the tested routine. +d = dates(B4,B3,B2,B1); +try + d.append_(dates(B5)); + t(1) = true; +catch + t(1) = false; +end + +% Check the results. +if t(1) + t(2) = isequal(d.time,e.time); + t(3) = isequal(d.freq,e.freq); +end +T = all(t); %@eof:1 %@test:2 -%$ % Define some dates -%$ B1 = '1953Q4'; -%$ B2 = '1950Q2'; -%$ B3 = '1950Q1'; -%$ B4 = '1945Q3'; -%$ B5 = '2009Q2'; -%$ -%$ % Define expected results. -%$ e.time = [1945 3; 1950 1; 1950 2; 1953 4; 2009 2]; -%$ e.freq = 4; -%$ -%$ % Call the tested routine. -%$ d = dates(B4,B3,B2,B1); -%$ try -%$ d.append_(B5); -%$ t(1) = true; -%$ catch -%$ t(1) = false; -%$ end -%$ -%$ % Check the results. -%$ if t(1) -%$ t(2) = dassert(d.time,e.time); -%$ t(3) = dassert(d.freq,e.freq); -%$ end -%$ T = all(t); +% Define some dates +B1 = '1953Q4'; +B2 = '1950Q2'; +B3 = '1950Q1'; +B4 = '1945Q3'; +B5 = '2009Q2'; + +% Define expected results. +e.time = [1945 3; 1950 1; 1950 2; 1953 4; 2009 2]; +e.freq = 4; + +% Call the tested routine. +d = dates(B4,B3,B2,B1); +try + d.append_(B5); + t(1) = true; +catch + t(1) = false; +end + +% Check the results. +if t(1) + t(2) = isequal(d.time,e.time); + t(3) = isequal(d.freq,e.freq); +end +T = all(t); %@eof:2 %@test:3 -%$ % Define some dates -%$ B1 = '1953Q4'; -%$ B2 = '1950Q2'; -%$ B3 = '1950Q1'; -%$ B4 = '1945Q3'; -%$ B5 = '2009Q2'; -%$ -%$ % Define expected results. -%$ e.time = [1945 3; 1950 1; 1950 2; 1953 4; 2009 2]; -%$ e.freq = 4; -%$ -%$ % Call the tested routine. -%$ d = dates(B4,B3,B2,B1); -%$ try -%$ c = d.append_(B5); -%$ t(1) = true; -%$ catch -%$ t(1) = false; -%$ end -%$ -%$ % Check the results. -%$ if t(1) -%$ t(2) = dassert(d.time,e.time); -%$ t(3) = dassert(c.time,e.time); -%$ t(4) = dassert(d.freq,e.freq); -%$ t(5) = dassert(c.freq,e.freq); -%$ end -%$ T = all(t); +% Define some dates +B1 = '1953Q4'; +B2 = '1950Q2'; +B3 = '1950Q1'; +B4 = '1945Q3'; +B5 = '2009Q2'; + +% Define expected results. +e.time = [1945 3; 1950 1; 1950 2; 1953 4; 2009 2]; +e.freq = 4; + +% Call the tested routine. +d = dates(B4,B3,B2,B1); +try + c = d.append_(B5); + t(1) = true; +catch + t(1) = false; +end + +% Check the results. +if t(1) + t(2) = isequal(d.time,e.time); + t(3) = isequal(c.time,e.time); + t(4) = isequal(d.freq,e.freq); + t(5) = isequal(c.freq,e.freq); +end +T = all(t); %@eof:3 %@test:4 -%$ % Define some dates -%$ B1 = '1953Q4'; -%$ B2 = '1950Q2'; -%$ B3 = '1950Q1'; -%$ B4 = '1945Q3'; -%$ B5 = '2009Q2'; -%$ -%$ % Call the tested routine. -%$ d = dates(B4,B3); -%$ e = dates(B1,B2,B5); -%$ try -%$ d.append_(e); -%$ t(1) = false; -%$ catch -%$ t(1) = true; -%$ end -%$ -%$ T = all(t); +% Define some dates +B1 = '1953Q4'; +B2 = '1950Q2'; +B3 = '1950Q1'; +B4 = '1945Q3'; +B5 = '2009Q2'; + +% Call the tested routine. +d = dates(B4,B3); +e = dates(B1,B2,B5); +try + d.append_(e); + t(1) = false; +catch + t(1) = true; +end + +T = all(t); %@eof:4 %@test:5 -%$ % Define some dates -%$ B = '1950Q2'; -%$ -%$ % Call the tested routine. -%$ d = dates(B); -%$ try -%$ d.append_('1950Q3'); -%$ t(1) = true; -%$ catch -%$ t(1) = false; -%$ end -%$ -%$ if t(1) -%$ t(2) = dassert(d.time, [1950 2; 1950 3]); -%$ end -%$ -%$ T = all(t); +% Define some dates +B = '1950Q2'; + +% Call the tested routine. +d = dates(B); +try + d.append_('1950Q3'); + t(1) = true; +catch + t(1) = false; +end + +if t(1) + t(2) = isequal(d.time, [1950 2; 1950 3]); +end + +T = all(t); %@eof:5 %@test:6 -%$ % Define some dates -%$ B = '1950Q2'; -%$ -%$ % Call the tested routine. -%$ d = dates(B); -%$ try -%$ d.append_('1950Z3'); -%$ t(1) = false; -%$ catch -%$ t(1) = true; -%$ end -%$ -%$ T = all(t); +% Define some dates +B = '1950Q2'; + +% Call the tested routine. +d = dates(B); +try + d.append_('1950Z3'); + t(1) = false; +catch + t(1) = true; +end + +T = all(t); %@eof:6 + +%@test:7 +% Define some dates +B1 = '2020-01-01'; +B2 = '2020-01-02'; +B3 = '2020-01-03'; +B4 = '2020-01-04'; +B5 = '2020-01-05'; + +% Call the tested routine. +d = dates(B4,B3); +e = dates(B1,B2,B5); +try + d.append_(e); + t(1) = false; +catch + t(1) = true; +end + +T = all(t); +%@eof:7 + +%@test:8 +% Define some dates +B1 = '2020-01-01'; +B2 = '2020-01-02'; +B3 = '2020Q1'; + +% Call the tested routine. +d = dates(B1,B2); +e = dates(B3); +try + d.append_(e); + t(1) = false; +catch + t(1) = true; +end + +T = all(t); +%@eof:8 diff --git a/src/@dates/char.m b/src/@dates/char.m index fe41d6cb836a8ffe5f41151fb0404e26d8a2aac2..2d59e776b2fc4d8021dd969b06c384eb294566bc 100644 --- a/src/@dates/char.m +++ b/src/@dates/char.m @@ -8,7 +8,7 @@ function s = char(o) % --*-- Unitary tests --*-- % OUTPUTS % - s [string] -% Copyright (C) 2014-2017 Dynare Team +% Copyright © 2014-2020 Dynare Team % % This code is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by @@ -29,92 +29,94 @@ end s = date2string(o.time, o.freq); +return + %@test:1 -%$ % Define a dates object -%$ o = dates('1950Q1'); -%$ -%$ % Call the tested routine. -%$ try -%$ str = char(o); -%$ t(1) = true; -%$ catch -%$ t(1) = false; -%$ end -%$ -%$ if t(1) -%$ t(2) = dassert(str,'1950Q1'); -%$ end -%$ T = all(t); +% Define a dates object +o = dates('1950Q1'); + +% Call the tested routine. +try + str = char(o); + t(1) = true; +catch + t(1) = false; +end + +if t(1) + t(2) = isequal(str,'1950Q1'); +end +T = all(t); %@eof:1 %@test:2 -%$ % Define a dates object -%$ o = dates('1950M1'); -%$ -%$ % Call the tested routine. -%$ try -%$ str = char(o); -%$ t(1) = true; -%$ catch -%$ t(1) = false; -%$ end -%$ -%$ if t(1) -%$ t(2) = dassert(str,'1950M1'); -%$ end -%$ T = all(t); +% Define a dates object +o = dates('1950M1'); + +% Call the tested routine. +try + str = char(o); + t(1) = true; +catch + t(1) = false; +end + +if t(1) + t(2) = isequal(str,'1950M1'); +end +T = all(t); %@eof:2 %@test:3 -%$ % Define a dates object -%$ o = dates('1950W50'); -%$ -%$ % Call the tested routine. -%$ try -%$ str = char(o); -%$ t(1) = true; -%$ catch -%$ t(1) = false; -%$ end -%$ -%$ if t(1) -%$ t(2) = dassert(str,'1950W50'); -%$ end -%$ T = all(t); +% Define a dates object +o = dates('2020-10-01'); + +% Call the tested routine. +try + str = char(o); + t(1) = true; +catch + t(1) = false; +end + +if t(1) + t(2) = isequal(str,'2020-10-01'); +end +T = all(t); %@eof:3 %@test:4 -%$ % Define a dates object -%$ o = dates('1950Y'); -%$ -%$ % Call the tested routine. -%$ try -%$ str = char(o); -%$ t(1) = true; -%$ catch -%$ t(1) = false; -%$ end -%$ -%$ if t(1) -%$ t(2) = dassert(str,'1950Y'); -%$ end -%$ T = all(t); +% Define a dates object +o = dates('1950Y'); + +% Call the tested routine. +try + str = char(o); + t(1) = true; +catch + t(1) = false; +end + +if t(1) + t(2) = isequal(str,'1950Y'); +end +T = all(t); %@eof:4 %@test:5 -%$ % Define a dates object -%$ o = dates('1950A'); -%$ -%$ % Call the tested routine. -%$ try -%$ str = char(o); -%$ t(1) = true; -%$ catch -%$ t(1) = false; -%$ end -%$ -%$ if t(1) -%$ t(2) = dassert(str,'1950Y'); -%$ end -%$ T = all(t); -%@eof:5 +% Define a dates object +o = dates('1950A'); + +% Call the tested routine. +try + str = char(o); + t(1) = true; +catch + t(1) = false; +end + +if t(1) + t(2) = isequal(str,'1950Y'); +end +T = all(t); +%@eof:5 \ No newline at end of file