Added unit tests.

parent 0a729519
expected_str_1 = sprintf('toto is an empty dates object.\n');
expected_str_2 = sprintf('toto = <dates: 1950Q1, 1950Q2>\n');
expected_str_3 = sprintf('toto = <dates: 1950Q1, 1950Q2, ..., 1950Q4, 1951Q1>\n');
expected_str_4 = sprintf('toto = <dates: 1950Q1, 1950Q2, 1950Q3, 1950Q4, 1951Q1>\n');
function p = copy(o)
function p = copy(o) % --*-- Unitary tests --*--
% Do a copy of a dates object.
%
......@@ -26,3 +26,24 @@ function p = copy(o)
p = dates();
p.freq = o.freq;
p.time = o.time;
%@test:1
%$ % Define a dates object
%$ o = dates('1945Q3','1944Q4');
%$ q = dates('1945Q3','1944Q4');
%$
%$ % Call the tested routine.
%$ try
%$ p = copy(o);
%$ t(1) = true;
%$ catch
%$ t(1) = false;
%$ end
%$
%$ if t(1)
%$ o.sort_();
%$ t(2) = dassert(p, q);
%$ end
%$
%$ T = all(t);
%@eof:1
\ No newline at end of file
......@@ -109,6 +109,21 @@ classdef dates<handle % --*-- Unitary tests --*--
end
error('dates:ArgCheck','You should first read the manual!')
end % dates constructor.
% Other methods
p = sort(o);
o = sort_(o);
p = unique(o);
o = unique_(o);
p = append(o, d);
o = append_(o, d);
p = pop(o, d);
o = pop_(o, d);
p = remove(o, d);
o = remove_(o, d);
s = char(o);
a = double(o);
n = ndat(o);
n = length(o);
end % methods
end % classdef
......
function lastIndex = end(o, k, n)
function lastIndex = end(o, k, n) % --*-- Unitary tests --*--
% Overloads end keyword.
%
......@@ -27,3 +27,23 @@ function lastIndex = end(o, k, n)
assert(k==1 && n==1, 'dates:end:ArgCheck', 'dates only has one dimension');
lastIndex = o.ndat();
%@test:1
%$ % Define a dates object
%$ o = dates('1938Q4'):dates('2015Q4');
%$ q = dates('2015Q4');
%$
%$ % Call the tested routine.
%$ try
%$ p = o(end);
%$ t(1) = true;
%$ catch
%$ t(1) = false;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(p, q);
%$ end
%$
%$ T = all(t);
%@eof:1
\ No newline at end of file
function l = isequal(o, p, fake)
function l = isequal(o, p, fake) % --*-- Unitary tests --*--
% Overloads isequal function for dates objects. Returns true (1) iff o and p have the same elements.
%
......
function n = length(o)
function n = length(o) % --*-- Unitary tests --*--
% Returns the number of elements in a dates object.
%
......
function [o, p] = comparison_arg_checks(varargin)
function [o, p] = comparison_arg_checks(varargin) % --*-- Unitary tests --*--
% Returns two dates objects or an error if objects to be compared are not compatible.
%
......@@ -45,4 +45,121 @@ if ~isequal(varargin{1}.ndat, varargin{2}.ndat) && ~(isequal(varargin{1}.ndat,1)
end
o = varargin{1};
p = varargin{2};
\ No newline at end of file
p = varargin{2};
%@test:1
%$ OPATH = pwd();
%$ [DATES_PATH, junk1, junk2] = fileparts(which('dates'));
%$ cd([DATES_PATH '/private']);
%$
%$ try
%$ [o, p] = comparison_arg_checks(1);
%$ t(1) = false;
%$ catch
%$ t(1) = true;
%$ end
%$
%$ T = all(t);
%$ cd(OPATH);
%@eof:1
%@test:2
%$ OPATH = pwd();
%$ [DATES_PATH, junk1, junk2] = fileparts(which('dates'));
%$ cd([DATES_PATH '/private']);
%$
%$ try
%$ [o, p] = comparison_arg_checks('make', 'my', 'day');
%$ t(1) = false;
%$ catch
%$ t(1) = true;
%$ end
%$
%$ T = all(t);
%$ cd(OPATH);
%@eof:2
%@test:3
%$ OPATH = pwd();
%$ [DATES_PATH, junk1, junk2] = fileparts(which('dates'));
%$ cd([DATES_PATH '/private']);
%$
%$ try
%$ [o, p] = comparison_arg_checks('punk', dates('1950Q1'));
%$ t(1) = false;
%$ catch
%$ t(1) = true;
%$ end
%$
%$ T = all(t);
%$ cd(OPATH);
%@eof:3
%@test:4
%$ OPATH = pwd();
%$ [DATES_PATH, junk1, junk2] = fileparts(which('dates'));
%$ cd([DATES_PATH '/private']);
%$
%$ try
%$ [o, p] = comparison_arg_checks(dates('1950Q1'), 1);
%$ t(1) = false;
%$ catch
%$ t(1) = true;
%$ end
%$
%$ T = all(t);
%$ cd(OPATH);
%@eof:4
%@test:5
%$ OPATH = pwd();
%$ [DATES_PATH, junk1, junk2] = fileparts(which('dates'));
%$ cd([DATES_PATH '/private']);
%$
%$ try
%$ [o, p] = comparison_arg_checks(dates('1950Q1'), dates('1950M1'));
%$ t(1) = false;
%$ catch
%$ t(1) = true;
%$ end
%$
%$ T = all(t);
%$ cd(OPATH);
%@eof:5
%@test:6
%$ OPATH = pwd();
%$ [DATES_PATH, junk1, junk2] = fileparts(which('dates'));
%$ cd([DATES_PATH '/private']);
%$
%$ try
%$ [o, p] = comparison_arg_checks(dates('1950Q1'):dates('1950Q2'), dates('1950Q1'):dates('1950Q3'));
%$ t(1) = false;
%$ catch
%$ t(1) = true;
%$ end
%$
%$ T = all(t);
%$ cd(OPATH);
%@eof:6
%@test:7
%$ OPATH = pwd();
%$ [DATES_PATH, junk1, junk2] = fileparts(which('dates'));
%$ cd([DATES_PATH '/private']);
%$
%$ try
%$ [o, p] = comparison_arg_checks(dates('1950Q2'), dates('1950Q1'));
%$ t(1) = true;
%$ catch
%$ t(1) = false;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(o, dates('1950Q2'));
%$ t(3) = dassert(p, dates('1950Q1'));
%$ end
%$
%$ T = all(t);
%$ cd(OPATH);
%@eof:7
\ No newline at end of file
function str = dates4display(o, name, max_number_of_elements)
function str = dates4display(o, name, max_number_of_elements) % --*-- Unitary tests --*--
% Converts a list object to a string.
%
......@@ -45,4 +45,117 @@ else
str = sprintf('%s%s, ', str, '...');
str = sprintf('%s%s, ', str, date2string(o.time(o.length()-1,:),o.freq));
end
str = sprintf('%s%s>', str, date2string(o.time(o.length(),:),o.freq));
\ No newline at end of file
str = sprintf('%s%s>\n', str, date2string(o.time(o.length(),:),o.freq));
%@test:1
%$ OPATH = pwd();
%$ [DATES_PATH, junk1, junk2] = fileparts(which('dates'));
%$ cd([DATES_PATH '/private']);
%$ addpath('../../../data/')
%$
%$ try
%$ toto = dates();
%$ str = dates4display(toto, 'toto', 5);
%$ t(1) = true;
%$ catch
%$ t(1) = false;
%$ end
%$
%$ if t(1)
%$ test_dates4display;
%$ try
%$ t(2) = dassert(str, expected_str_1);
%$ catch
%$ t(2) = false;
%$ end
%$ end
%$
%$ T = all(t);
%$ rmpath('../../../data/')
%$ cd(OPATH);
%@eof:1
%@test:2
%$ OPATH = pwd();
%$ [DATES_PATH, junk1, junk2] = fileparts(which('dates'));
%$ cd([DATES_PATH '/private']);
%$ addpath('../../../data/')
%$
%$ try
%$ toto = dates('1950Q1'):dates('1950Q2');
%$ str = dates4display(toto, 'toto', 5);
%$ t(1) = true;
%$ catch
%$ t(1) = false;
%$ end
%$
%$ if t(1)
%$ test_dates4display;
%$ try
%$ t(2) = dassert(str, expected_str_2);
%$ catch
%$ t(2) = false;
%$ end
%$ end
%$
%$ T = all(t);
%$ rmpath('../../../data/')
%$ cd(OPATH);
%@eof:2
%@test:3
%$ OPATH = pwd();
%$ [DATES_PATH, junk1, junk2] = fileparts(which('dates'));
%$ cd([DATES_PATH '/private']);
%$ addpath('../../../data/')
%$
%$ try
%$ toto = dates('1950Q1'):dates('1951Q1');
%$ str = dates4display(toto, 'toto', 4);
%$ t(1) = true;
%$ catch
%$ t(1) = false;
%$ end
%$
%$ if t(1)
%$ test_dates4display;
%$ try
%$ t(2) = dassert(str, expected_str_3);
%$ catch
%$ t(2) = false;
%$ end
%$ end
%$
%$ T = all(t);
%$ rmpath('../../../data/')
%$ cd(OPATH);
%@eof:3
%@test:4
%$ OPATH = pwd();
%$ [DATES_PATH, junk1, junk2] = fileparts(which('dates'));
%$ cd([DATES_PATH '/private']);
%$ addpath('../../../data/')
%$
%$ try
%$ toto = dates('1950Q1'):dates('1951Q1');
%$ str = dates4display(toto, 'toto', 6);
%$ t(1) = true;
%$ catch
%$ t(1) = false;
%$ end
%$
%$ if t(1)
%$ test_dates4display;
%$ try
%$ t(2) = dassert(str, expected_str_4);
%$ catch
%$ t(2) = false;
%$ end
%$ end
%$
%$ T = all(t);
%$ rmpath('../../../data/')
%$ cd(OPATH);
%@eof:4
function c = greaterorequal(a,b)
function c = greaterorequal(a,b) % --*-- Unitary tests --*--
% Copyright (C) 2013-2014 Dynare Team
% Copyright (C) 2013-2015 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
......@@ -27,4 +27,123 @@ else
c = false;
end
end
end
\ No newline at end of file
end
%@test:1
%$ OPATH = pwd();
%$ [DATES_PATH, junk1, junk2] = fileparts(which('dates'));
%$ cd([DATES_PATH '/private']);
%$
%$ a = [2, 4];
%$ b = [1, 2];
%$
%$ try
%$ boolean = greaterorequal(a, b);
%$ t(1) = true;
%$ catch
%$ t(1) = false;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(boolean, true);
%$ end
%$
%$ T = all(t);
%$ cd(OPATH);
%@eof:1
%@test:2
%$ OPATH = pwd();
%$ [DATES_PATH, junk1, junk2] = fileparts(which('dates'));
%$ cd([DATES_PATH '/private']);
%$
%$ a = [1, 4];
%$ b = [2, 2];
%$
%$ try
%$ boolean = greaterorequal(a, b);
%$ t(1) = true;
%$ catch
%$ t(1) = false;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(boolean, false);
%$ end
%$
%$ T = all(t);
%$ cd(OPATH);
%@eof:2
%@test:3
%$ OPATH = pwd();
%$ [DATES_PATH, junk1, junk2] = fileparts(which('dates'));
%$ cd([DATES_PATH '/private']);
%$
%$ a = [1, 4];
%$ b = [1, 2];
%$
%$ try
%$ boolean = greaterorequal(a, b);
%$ t(1) = true;
%$ catch
%$ t(1) = false;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(boolean, true);
%$ end
%$
%$ T = all(t);
%$ cd(OPATH);
%@eof:3
%@test:4
%$ OPATH = pwd();
%$ [DATES_PATH, junk1, junk2] = fileparts(which('dates'));
%$ cd([DATES_PATH '/private']);
%$
%$ a = [1, 2];
%$ b = [1, 4];
%$
%$ try
%$ boolean = greaterorequal(a, b);
%$ t(1) = true;
%$ catch
%$ t(1) = false;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(boolean, false);
%$ end
%$
%$ T = all(t);
%$ cd(OPATH);
%@eof:4
%@test:5
%$ OPATH = pwd();
%$ [DATES_PATH, junk1, junk2] = fileparts(which('dates'));
%$ cd([DATES_PATH '/private']);
%$
%$ a = [1, 2];
%$ b = [1, 2];
%$
%$ try
%$ boolean = greaterorequal(a, b);
%$ t(1) = true;
%$ catch
%$ t(1) = false;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(boolean, true);
%$ end
%$
%$ T = all(t);
%$ cd(OPATH);
%@eof:5
function c = greaterthan(a,b)
function c = greaterthan(a,b) % --*-- Unitary tests --*--
% Copyright (C) 2013-2014 Dynare Team
%
......@@ -27,4 +27,119 @@ else
c = false;
end
end
end
\ No newline at end of file
end
%@test:1
%$ OPATH = pwd();
%$ [DATES_PATH, junk1, junk2] = fileparts(which('dates'));
%$ cd([DATES_PATH '/private']);
%$
%$ a = [2, 4];
%$ b = [1, 2];
%$
%$ try
%$ boolean = greaterthan(a, b);
%$ t(1) = true;
%$ catch
%$ t(1) = false;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(boolean, true);
%$ end
%$
%$ T = all(t);
%$ cd(OPATH);
%@eof:1
%@test:2
%$ OPATH = pwd();
%$ [DATES_PATH, junk1, junk2] = fileparts(which('dates'));
%$ cd([DATES_PATH '/private']);
%$
%$ a = [1, 4];
%$ b = [2, 2];
%$
%$ try
%$ boolean = greaterthan(a, b);
%$ t(1) = true;
%$ catch
%$ t(1) = false;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(boolean, false);
%$ end
%$
%$ T = all(t);
%$ cd(OPATH);
%@eof:2
%@test:3
%$ OPATH = pwd();
%$ [DATES_PATH, junk1, junk2] = fileparts(which('dates'));
%$ cd([DATES_PATH '/private']);
%$
%$ a = [1, 4];
%$ b = [1, 2];
%$
%$ try
%$ boolean = greaterthan(a, b);
%$ t(1) = true;
%$ catch
%$ t(1) = false;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(boolean, true);
%$ end
%$
%$ T = all(t);
%$ cd(OPATH);
%@eof:3
%@test:4
%$ OPATH = pwd();
%$ [DATES_PATH, junk1, junk2] = fileparts(which('dates'));
%$ cd([DATES_PATH '/private']);
%$
%$ a = [1, 2];
%$ b = [1, 4];
%$
%$ try
%$ boolean = greaterthan(a, b);
%$ t(1) = true;
%$ catch
%$ t(1) = false;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(boolean, false);
%$ end
%$
%$ T = all(t);
%$ cd(OPATH);
%@eof:4
%@test:5
%$ OPATH = pwd();
%$ [DATES_PATH, junk1, junk2] = fileparts(which('dates'));
%$ cd([DATES_PATH '/private']);
%$
%$ a = [1, 2];
%$ b = [1, 2];
%$
%$ try
%$ boolean = greaterthan(a, b);
%$ t(1) = true;
%$ catch
%$ t(1) = false;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(boolean, false);
%$ end
%$
%$ T = all(t);
%$ cd(OPATH);
%@eof:5
function c = lessorequal(a, b)
function c = lessorequal(a, b) % --*-- Unitary tests --*--
% Copyright (C) 2013-2014 Dynare Team
%
......@@ -27,4 +27,119 @@ else
c = false;
end
end
end
\ No newline at end of file
end
%@test:1
%$ OPATH = pwd();
%$ [DATES_PATH, junk1, junk2] = fileparts(which('dates'));
%$ cd([DATES_PATH '/private']);
%$
%$ a = [2, 4];
%$ b = [1, 2];
%$
%$ try
%$ boolean = lessorequal(a, b);
%$ t(1) = true;
%$ catch
%$ t(1) = false;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(boolean, false);
%$ end
%$
%$ T = all(t);
%$ cd(OPATH);
%@eof:1
%@test:2
%$ OPATH = pwd();
%$ [DATES_PATH, junk1, junk2] = fileparts(which('dates'));
%$ cd([DATES_PATH '/private']);
%$
%$ a = [1, 4];
%$ b = [2, 2];
%$
%$ try
%$ boolean = lessorequal(a, b);
%$ t(1) = true;
%$ catch
%$ t(1) = false;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(boolean, true);
%$ end
%$
%$ T = all(t);
%$ cd(OPATH);
%@eof:2
%@test:3
%$ OPATH = pwd();
%$ [DATES_PATH, junk1, junk2] = fileparts(which('dates'));
%$ cd([DATES_PATH '/private']);
%$
%$ a = [1, 4];
%$ b = [1, 2];
%$
%$ try
%$ boolean = lessorequal(a, b);
%$ t(1) = true;
%$ catch
%$ t(1) = false;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(boolean, false);
%$ end
%$
%$ T = all(t);
%$ cd(OPATH);
%@eof:3
%@test:4
%$ OPATH = pwd();
%$ [DATES_PATH, junk1, junk2] = fileparts(which('dates'));
%$ cd([DATES_PATH '/private']);
%$
%$ a = [1, 2];
%$ b = [1, 4];
%$