Commit f4bfaa88 authored by Stéphane Adjemian's avatar Stéphane Adjemian
Browse files

Merge branch 'pr#34'

parents 97788174 ffd3b542
function clean(o)
function clean(o) % --*-- Unitary tests --*--
% Erase generated files if any.
......@@ -20,4 +20,19 @@ function clean(o)
if ~isempty(o.results)
basename = o.results.name;
delete(sprintf('%s.*', basename))
end
\ No newline at end of file
end
%@test:1
%$ try
%$ series = dseries(rand(100,1),'1999M1');
%$ o = x13(series);
%$ o.x11('save','(d11)');
%$ o.run();
%$ o.clean();
%$ t(1) = true;
%$ catch
%$ t(1) = false;
%$ end
%$
%$ T = all(t);
%@eof:1
\ No newline at end of file
function basename = print(o, basename)
function basename = print(o, basename) % --*-- Unitary tests --*--
% Prints spc file.
......@@ -352,7 +352,7 @@ if ismember('x11regression', o.commands)
for i=1:length(conditionningvariables)
if ~ismember(conditionningvariables{i}, o.x.name)
fclose(fid);
error('x13:x11regression: Variable %s is unkonwn', conditionningvariables{i})
error('x13:x11regression: Variable %s is unknown', conditionningvariables{i})
end
end
% Select the data.
......@@ -390,4 +390,35 @@ if ismember('x11regression', o.commands)
fprintf(fid, '}\n\n');
end
fclose(fid);
\ No newline at end of file
fclose(fid);
%@test:1
%$ try
%$ series = dseries(rand(100,1),'1999M1');
%$ o = x13(series);
%$ o.x11('save','(d11)');
%$ o.automdl('savelog','amd','mixed','no');
%$ o.outlier('types','all','save','(fts)');
%$ o.check('maxlag',24,'save','(acf pcf)');
%$ o.estimate('save','(mdl est)');
%$ o.forecast('maxlead',18,'probability',0.95,'save','(fct fvr)');
%$ o.run(); % necessary to invoke alphanumeric "basename"
%$ o.print();
%$
%$ text = fileread(sprintf('%s.spc',o.results.name));
%$ comm = o.commands;
%$
%$ for i = 1:numel(comm)
%$ ex(i,1) = ~isempty(strfind(text,[comm{i} ' {']));
%$ end
%$
%$ if all(ex)
%$ t(1) = true;
%$ o.clean();
%$ end
%$ catch
%$ t(1) = false;
%$ end
%$
%$ T = all(t);
%@eof:1
\ No newline at end of file
function val = subsasgn(val, idx, rhs)
function val = subsasgn(val, idx, rhs) % --*-- Unitary tests --*--
% Copyright (C) 2017 Dynare Team
%
......@@ -16,3 +16,33 @@ function val = subsasgn(val, idx, rhs)
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
error('Members of x13 class are private')
%@test:1
%$ t = zeros(3,1);
%$
%$ y = dseries(rand(100,1),'1999M1');
%$ o = x13(y);
%$
%$ try
%$ o.commands = {'yes','no','maybe'};
%$ t(1) = false;
%$ catch
%$ t(1) = true;
%$ end
%$
%$ try
%$ o.results = 'Perverse string';
%$ t(2) = false;
%$ catch
%$ t(2) = true;
%$ end
%$
%$ try
%$ o.y = dseries(rand(100,1));
%$ t(3) = false;
%$ catch
%$ t(3) = true;
%$ end
%$
%$ T = all(t);
%@eof:1
\ No newline at end of file
function o = subsref(o, S)
function o = subsref(o, S) % --*-- Unitary tests --*--
% Overloads the subsref method.
......@@ -93,4 +93,47 @@ switch S(1).type
end
otherwise
error('x13:: I do not understand what you are asking for!')
end
\ No newline at end of file
end
%@test:1
%$ t = zeros(1,5);
%$ o = x13();
%$
%$ try
%$ o(arima);
%$ t(1) = false;
%$ catch
%$ t(1) = true;
%$ end
%$
%$ try
%$ o.unicorn;
%$ t(2) = false;
%$ catch
%$ t(2) = true;
%$ end
%$
%$ try
%$ o.x11('onearg','onevalue','twoargs');
%$ t(3) = false;
%$ catch
%$ t(3) = true;
%$ end
%$
%$ try
%$ o.x11('unicorn','yes please');
%$ o.x11.unicorn;
%$ t(4) = false;
%$ catch
%$ t(4) = true;
%$ end
%$
%$ try
%$ o.print.unicorn;
%$ t(5) = false;
%$ catch
%$ t(5) = true;
%$ end
%$
%$ T = all(t);
%@eof:1
\ No newline at end of file
classdef x13<handle
classdef x13<handle % --*-- Unitary tests --*--
% Class for X13 toolbox.
......@@ -118,4 +118,42 @@ methods
end
end
end
\ No newline at end of file
end
%@test:1
%$
%$ try
%$ series = dseries(rand(100,2),'1999M1');
%$ o = x13(series);
%$ t(1) = false;
%$ catch
%$ t(1) = true;
%$ end
%$
%$ T = all(t);
%@eof:1
%@test:2
%$ try
%$ series = rand(100,2);
%$ o = x13(series);
%$ t(1) = false;
%$ catch
%$ t(1) = true;
%$ end
%$
%$ T = all(t);
%@eof:2
%@test:3
%$ try
%$ y = dseries(rand(100,1),'1999M1');
%$ x = rand(100,2);
%$ o = x13(y,x);
%$ t(1) = false;
%$ catch
%$ t(1) = true;
%$ end
%$
%$ T = all(t);
%@eof:3
\ No newline at end of file
function checkcommandcompatibility(o, comm)
function checkcommandcompatibility(o, comm) % --*-- Unitary tests --*--
% Checks for compatibility of X13 commands.
......@@ -20,7 +20,7 @@ function checkcommandcompatibility(o, comm)
switch comm
case 'arima'
if ismember('automdl', o.commands)
error('x13:arima: ARIMA command is not compatible with AUTOMDL command!')
error('x13:arima: ARIMA command is not compatible with AUTOMDL command!')
elseif ismember('pickmdl', o.commands)
error('x13:arima: ARIMA command is not compatible with PICKMDL command!')
end
......@@ -34,7 +34,31 @@ switch comm
if ismember('arima', o.commands)
error('x13:pickmdl: PICKMDL command is not compatible with ARIMA command!')
elseif ismember('automdl', o.commands)
error('x13:pickmdl: PICKMDL command is not compatible with AUTOMDL command!')
end
error('x13:pickmdl: PICKMDL command is not compatible with AUTOMDL command!')
end
otherwise
end
\ No newline at end of file
end
%@test:1
%$ t = zeros(2,1);
%$
%$ series = dseries(rand(100,1),'1999M1');
%$ o = x13(series);
%$ o.arima('save','(d11)');
%$
%$ try
%$ o.automdl('savelog','amd');
%$ t(1) = false;
%$ catch
%$ t(1) = true;
%$ end
%$
%$ try
%$ o.pickmdl('savelog','amd');
%$ t(2) = false;
%$ catch
%$ t(2) = true;
%$ end
%$
%$ T = all(t);
%@eof:1
\ No newline at end of file
function checkoptioncompatibility(o)
function checkoptioncompatibility(o) % --*-- Unitary tests --*--
% Checks for compatibility of options in different X13 commands.
......@@ -34,5 +34,36 @@ if ~isempty(o.estimate.file)
error('Command AUTOMDL not compatible with ESTIMATE.file option!');
elseif ismember('pickmdl',o.commands)
error('Command PICKMDL not compatible with ESTIMATE.file option!');
end
end
\ No newline at end of file
end
end
%@test:1
%$ t = zeros(3,1);
%$
%$ series = dseries(rand(100,1),'1999M1');
%$ o = x13(series);
%$ o.estimate('file','test');
%$
%$ try
%$ o.arima('model','(1 0 1)');
%$ t(1) = false;
%$ catch
%$ t(1) = true;
%$ end
%$
%$ try
%$ o.pickmdl('savelog','amd');
%$ t(2) = false;
%$ catch
%$ t(2) = true;
%$ end
%$
%$ try
%$ o.regression('b',0.9);
%$ t(3) = false;
%$ catch
%$ t(3) = true;
%$ end
%$
%$ T = all(t);
%@eof:1
\ No newline at end of file
function b = isoption(command, option)
function b = isoption(command, option) % --*-- Unitary tests --*--
% Copyright (C) 2017 Dynare Team
%
......@@ -78,3 +78,21 @@ switch command
otherwise
error('x13:isoption: Unknown block!')
end
%@test:1
%$ try
%$ b = isoption('unicorn','horse sounds');
%$ t(1) = false;
%$ catch
%$ t(1) = true;
%$ end
%$
%$ T = all(t);
%@eof:1
%@test:2
%$ b = isoption('arima','ar');
%$ c = ~isoption('arima','unicorn');
%$ t = [b;c];
%$ T = all(t);
%@eof:2
\ No newline at end of file
function printoption(fid, optname, optvalue)
function printoption(fid, optname, optvalue) % --*-- Unitary tests --*--
% Copyright (C) 2017 Dynare Team
%
......@@ -41,4 +41,21 @@ elseif isreal(optvalue)
error('This option value type is not implemented!');
end
end
end
\ No newline at end of file
end
%@test:1
%$ fid = fopen('test.spc', 'w');
%$
%$ try
%$ series = dseries(rand(100,1),'1999M1');
%$ o = x13(series);
%$ o.x11('save','(d11)');
%$ optnames = fieldnames(o.x11);
%$ printoption(fid,'mode',o.x11.mode);
%$ t(1) = false;
%$ catch
%$ t(1) = true;
%$ end
%$
%$ T = all(t);
%@eof:1
\ No newline at end of file
function printspan(fid, period1, period2)
function printspan(fid, period1, period2) % --*-- Unitary tests --*--
% Copyright (C) 2017 Dynare Team
%
......@@ -37,4 +37,46 @@ switch period1.freq
fprintf(fid, ' span = (%i,%i)\n', period1.year, period2.year);
otherwise
error('x13:regression: This is a bug! Please contact the authors.')
end
\ No newline at end of file
end
%@test:1
%$ try
%$ per1 = dates(52,1996,1);
%$ per2 = dates(52,1996,2);
%$ fid = fopen('test.spc', 'w');
%$ printstart(fid,per1,per2);
%$ t(1) = false;
%$ catch
%$ t(1) = true;
%$ end
%$
%$ T = all(t);
%@eof:1
%@test:2
%$ try
%$ per1 = dates(52,1996,1);
%$ per2 = dates(52,1994,2);
%$ fid = fopen('test.spc', 'w');
%$ printstart(fid,per1,per2);
%$ t(1) = false;
%$ catch
%$ t(1) = true;
%$ end
%$
%$ T = all(t);
%@eof:2
%@test:3
%$ try
%$ per1 = dates(4,1996,1);
%$ per2 = dates(52,1996,2);
%$ fid = fopen('test.spc', 'w');
%$ printstart(fid,per1,per2);
%$ t(1) = false;
%$ catch
%$ t(1) = true;
%$ end
%$
%$ T = all(t);
%@eof:3
\ No newline at end of file
function printstart(fid, period)
function printstart(fid, period) % --*-- Unitary tests --*--
% Copyright (C) 2017 Dynare Team
%
......@@ -29,4 +29,17 @@ switch period.freq
fprintf(fid, ' start = %i\n', period.year);
otherwise
error('x13:regression: This is a bug! Please contact the authors.')
end
\ No newline at end of file
end
%@test:1
%$ try
%$ per = dates(52,1996,1);
%$ fid = fopen('test.spc', 'w');
%$ printstart(fid,per);
%$ t(1) = false;
%$ catch
%$ t(1) = true;
%$ end
%$
%$ T = all(t);
%@eof:1
\ No newline at end of file
function s = setdefaultmember(name)
function s = setdefaultmember(name) % --*-- Unitary tests --*--
% Sets members of X13 object to default values (empty).
......@@ -82,3 +82,14 @@ switch name
otherwise
error('x13:setdefaultmember: Unknown member!')
end
%@test:1
%$ try
%$ setdefaultmember('PyotrIlychTchaikowsky');
%$ t(1) = false;
%$ catch
%$ t(1) = true;
%$ end
%$
%$ T = all(t);
%@eof:1
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment