comparison testing/utp_1.1/utps/ao/utp_ao_dft.m @ 44:409a22968d5e default

Add unit tests
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Tue, 06 Dec 2011 18:42:11 +0100
parents
children
comparison
equal deleted inserted replaced
43:bc767aaa99a8 44:409a22968d5e
1 % UTP_AO_DFT a set of UTPs for the ao/dft method
2 %
3 % M Hewitson 06-08-08
4 %
5 % $Id: utp_ao_dft.m,v 1.13 2009/09/20 16:51:33 hewitson Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % The dft method of the ao class computes the discrete fourier transform of
11 % time-series AOs.
12 %
13 % </MethodDescription>
14
15 function results = utp_ao_dft(varargin)
16
17 % Check the inputs
18 if nargin == 0
19
20 % Some keywords
21 class = 'ao';
22 mthd = 'dft';
23
24 results = [];
25 disp('******************************************************');
26 disp(['**** Running UTPs for ' class '/' mthd]);
27 disp('******************************************************');
28
29 % Test AOs
30 [at1,at2,at3,at4,at5,at6,atvec,atmat] = eval(['get_test_objects_' class]);
31
32 % Exception list for the UTPs:
33 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples();
34
35 % Run the tests
36 atvec = [at1 at5 at6];
37 atmat = [at1 at5 at6; at5 at6 at1];
38 pli = plist('f', 3, 'neval', true);
39
40 results = [results utp_01]; % getInfo call
41 results = [results utp_02(mthd, atvec, @algo_test_y, pli, ple3)]; % Vector input
42 results = [results utp_03(mthd, atmat, @algo_test_y, pli, ple3)]; % Matrix input
43 results = [results utp_04(mthd, at1, at5, at6, @algo_test_y, pli, ple3)]; % List input
44 results = [results utp_05(mthd, at1, atvec, atmat, @algo_test_y, pli, ple3)]; % Test with mixed input
45 results = [results utp_06(mthd, at1, pli, ple2)]; % Test history is working
46 results = [results utp_07(mthd, at1, pli, ple2)]; % Test the modify call works
47 results = [results utp_09(mthd, at5, at6)]; % Test input data shape == output data shape
48 results = [results utp_10(mthd, at1, at5, ple2)]; % Test output of the data
49 results = [results utp_11(mthd, at1, ple1)]; % Test plotinfo doesn't disappear
50 results = [results utp_12(mthd, at1, ple1)]; % Test errors are cleared
51
52 disp('Done.');
53 disp('******************************************************');
54
55 elseif nargin == 1 % Check for UTP functions
56 if strcmp(varargin{1}, 'isutp')
57 results = 1;
58 else
59 results = 0;
60 end
61 else
62 error('### Incorrect inputs')
63 end
64
65 %% Algorithm test for UTP 02,03,04,05
66
67 function atest = algo_test_y(in, out, pli)
68 atest = true;
69 % Compute DFT
70 f = pli.find('f');
71 fs = in.data.fs;
72 N = length(in.y);
73 J = -2*pi*1i.*[0:N-1]/fs;
74 dfts = zeros(size(f));
75 for ss = 1:length(f)
76 dfts(ss) = exp(f(ss)*J)*in.y;
77 end
78 if ~isequal(in.fs, out.fs), atest = false; end
79 if ~isequal(f, out.x), atest = false; end
80 if ~isequal(dfts, out.y), atest = false; end
81 end
82
83 %% UTP_01
84
85 % <TestDescription>
86 %
87 % Tests that the getInfo call works for this method.
88 %
89 % </TestDescription>
90 function result = utp_01
91
92
93 % <SyntaxDescription>
94 %
95 % Test that the getInfo call works for no sets, all sets, and each set
96 % individually.
97 %
98 % </SyntaxDescription>
99
100 try
101 % <SyntaxCode>
102 % Call for no sets
103 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']);
104 % Call for all sets
105 io(2) = eval([class '.getInfo(''' mthd ''')']);
106 % Call for each set
107 for kk=1:numel(io(2).sets)
108 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']);
109 end
110 % </SyntaxCode>
111 stest = true;
112 catch err
113 disp(err.message)
114 stest = false;
115 end
116
117 % <AlgoDescription>
118 %
119 % 1) Check that getInfo call returned an minfo object in all cases.
120 % 2) Check that all plists have the correct parameters.
121 %
122 % </AlgoDescription>
123
124 atest = true;
125 if stest
126 % <AlgoCode>
127 % check we have minfo objects
128 if isa(io, 'minfo')
129 %%% SET 'None'
130 if ~isempty(io(1).sets), atest = false; end
131 if ~isempty(io(1).plists), atest = false; end
132 %%% Check all Sets
133 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end
134 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end
135 %%%%%%%%%% SET 'Default'
136 if io(3).plists.nparams ~= 1, atest = false; end
137 % Check key
138 if ~io(3).plists.isparam('f'), atest = false; end
139 % Check default value
140 if ~isequal(io(3).plists.find('f'), -1), atest = false; end
141 % Check options
142 if ~isequal(io(3).plists.getOptionsForParam('f'), {-1}), atest = false; end
143 end
144 % </AlgoCode>
145 else
146 atest = false;
147 end
148
149 % Return a result structure
150 result = utp_prepare_result(atest, stest, dbstack, mfilename);
151 end % END UTP_01
152
153 end