1function [o, p] = align(o, p) % --*-- Unitary tests --*--
2
3% If necessay completes dseries object o and p so that they are defined on the same time range
4% (in place modification).
5%
6% INPUTS
7% - o [dseries]
8% - p [dseries]
9%
10% OUTPUTS
11% - o [dseries]
12% - p [dseries]
13
14% Copyright (C) 2013-2017 Dynare Team
15%
16% This file is part of Dynare.
17%
18% Dynare is free software: you can redistribute it and/or modify
19% it under the terms of the GNU General Public License as published by
20% the Free Software Foundation, either version 3 of the License, or
21% (at your option) any later version.
22%
23% Dynare is distributed in the hope that it will be useful,
24% but WITHOUT ANY WARRANTY; without even the implied warranty of
25% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26% GNU General Public License for more details.
27%
28% You should have received a copy of the GNU General Public License
29% along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
30
31o = copy(o);
32p = copy(p);
33align_(o, p);
34
35%@test:1
36%$ % Define a datasets.
37%$ A = rand(8,3); B = rand(7,2);
38%$
39%$ % Define names
40%$ A_name = {'A1';'A2';'A3'};
41%$ B_name = {'B1';'B2'};
42%$
43%$ % Define initial dates
44%$ A_init = '1990Q1';
45%$ B_init = '1989Q2';
46%$
47%$ % Instantiate two dseries objects
48%$ ts1 = dseries(A,A_init,A_name);
49%$ ts2 = dseries(B,B_init,B_name);
50%$
51%$ try
52%$   [ts1, ts2] = align(ts1, ts2);
53%$   t(1) = 1;
54%$ catch
55%$   t(1) = 0;
56%$ end
57%$
58%$ if t(1)
59%$   t(2) = dassert(ts1.nobs,ts2.nobs);
60%$   t(3) = dassert(ts1.init,ts2.init);
61%$   t(4) = dassert(ts1.data,[NaN(3,3); A], 1e-15);
62%$   t(5) = dassert(ts2.data,[B; NaN(4,2)], 1e-15);
63%$ end
64%$ T = all(t);
65%@eof:1
66
67%@test:2
68%$ % Define a datasets.
69%$ A = rand(8,3); B = rand(7,2);
70%$
71%$ % Define names
72%$ A_name = {'A1';'A2';'A3'};
73%$ B_name = {'B1';'B2'};
74%$
75%$ % Define initial dates
76%$ A_init = '1990Q1';
77%$ B_init = '1990Q1';
78%$
79%$ % Instantiate two dseries objects
80%$ ts1 = dseries(A,A_init,A_name);
81%$ ts2 = dseries(B,B_init,B_name);
82%$
83%$ try
84%$   [ts1, ts2] = align(ts1, ts2);
85%$   t(1) = 1;
86%$ catch
87%$   t(1) = 0;
88%$ end
89%$
90%$ if t(1)
91%$   t(2) = dassert(ts1.nobs,ts2.nobs);
92%$   t(3) = dassert(ts1.init,ts2.init);
93%$   t(4) = dassert(ts1.data,A, 1e-15);
94%$   t(5) = dassert(ts2.data,[B; NaN(1,2)], 1e-15);
95%$ end
96%$ T = all(t);
97%@eof:2
98
99%@test:3
100%$ % Define a datasets.
101%$ A = rand(8,3); B = rand(7,2);
102%$
103%$ % Define names
104%$ A_name = {'A1';'A2';'A3'};
105%$ B_name = {'B1';'B2'};
106%$
107%$ % Define initial dates
108%$ A_init = '1990Q1';
109%$ B_init = '1990Q1';
110%$
111%$ % Instantiate two dseries objects
112%$ ts1 = dseries(A,A_init,A_name);
113%$ ts2 = dseries(B,B_init,B_name);
114%$
115%$ try
116%$   [ts2, ts1] = align(ts2, ts1);
117%$   t(1) = 1;
118%$ catch
119%$   t(1) = 0;
120%$ end
121%$
122%$ if t(1)
123%$   t(2) = dassert(ts1.nobs,ts2.nobs);
124%$   t(3) = dassert(ts1.init,ts2.init);
125%$   t(4) = dassert(ts1.data,A, 1e-15);
126%$   t(5) = dassert(ts2.data,[B; NaN(1,2)], 1e-15);
127%$ end
128%$ T = all(t);
129%@eof:3