comparison testing/utp_1.1/utps/pzmodel/utp_pzmodel_loadobj.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_PZMODEL_LOADOBJ a set of UTPs for the pzmodel/loadobj method
2 %
3 % M Hewitson 06-08-08
4 %
5 % $Id: utp_pzmodel_loadobj.m,v 1.1 2009/01/12 19:08:19 ingo Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % The loadobj method of the pzmodel class will be automatically called by
11 % MATLAB if an older object is not compatible with the current object structure.
12 % This happens only for objects which are stored as a MATLAB formatted
13 % (MAT-file). The load mechanism for XML formated files calls always the
14 % 'update_struct' method to keep the stored objects up to date. The
15 % 'update_struct' method convert the read object structure to the object
16 % structure which is used in the currend LTPDA version.
17 % This UTP will load old objects which are stored with an older LTPDA version.
18 %
19 % REMARK: Since LTPDA version 1.9.2 will be an object which should be saved as a
20 % MAT file stored as a struct and not as the object.
21 %
22 % </MethodDescription>
23
24 function results = utp_pzmodel_loadobj(varargin)
25
26 % Check the inputs
27 if nargin == 0
28
29 % Some keywords
30 class = 'pzmodel';
31 mthd = 'loadobj';
32
33 results = [];
34 disp('******************************************************');
35 disp(['**** Running UTPs for ' class '/' mthd]);
36 disp('******************************************************');
37
38 % Run the tests
39 results = [results utp_01]; % getInfo call
40
41 disp('Done.');
42 disp('******************************************************');
43
44 elseif nargin == 1 % Check for UTP functions
45 if strcmp(varargin{1}, 'isutp')
46 results = 1;
47 else
48 results = 0;
49 end
50 else
51 error('### Incorrect inputs')
52 end
53
54 %% UTP_01
55
56 % <TestDescription>
57 %
58 % Tests that the getInfo call works for this method.
59 %
60 % </TestDescription>
61 function result = utp_01
62
63
64 % <SyntaxDescription>
65 %
66 % Test that the getInfo call works for no sets, all sets, and each set
67 % individually.
68 %
69 % </SyntaxDescription>
70
71 try
72 % <SyntaxCode>
73 % Get all .MAT and .XML files
74 path = fullfile(fileparts(which(mfilename)), '..', '..', 'utp_test_files');
75
76 matfiles = utils.prog.filescan(path, '.mat');
77 xmlfiles = utils.prog.filescan(path, '.xml');
78
79 % Load .MAT files
80 obj_no = 1;
81 for ii=1:numel(matfiles)
82 fn = matfiles{ii};
83 [path, name] = fileparts(fn);
84 cl = strtok(name, '_');
85
86 if strcmp(cl, class)
87 objs(obj_no).fname = name;
88 objs(obj_no).obj = pzmodel(fn);
89 obj_no = obj_no+1;
90 end
91 end
92
93 % Load .XML files
94 for ii=1:numel(xmlfiles)
95 fn = xmlfiles{ii};
96 [path, name] = fileparts(fn);
97 cl = strtok(name, '_');
98
99 if strcmp(cl, class)
100 objs(obj_no).fname = name;
101 objs(obj_no).obj = pzmodel(fn);
102 obj_no = obj_no+1;
103 end
104 end
105 % </SyntaxCode>
106 stest = true;
107 catch err
108 disp(err.message)
109 stest = false;
110 end
111
112 % <AlgoDescription>
113 %
114 % 1) Check the shape of the loaded objects.
115 %
116 % </AlgoDescription>
117
118 atest = true;
119 if stest
120 % <AlgoCode>
121 for ii = 1:numel(objs)
122 obj = objs(ii).obj;
123 fname = objs(ii).fname;
124
125 if ~isempty(strfind(fname, '_vec'))
126 % Loaded object must be a vector
127 if ~isvector(obj), atest = false; end
128 elseif ~isempty(strfind(fname, '_mat'))
129 % Loaded object must be a matrix
130 % REMARK: Known error in LTPDA version 1.9.2
131 % A saved matrix doesn't keep the shape of the matrix.
132 if isempty(strfind(fname, '_192'))
133 if ~(size(obj,1) > 1 && size(obj,2) > 1), atest = false; end
134 end
135 else
136 % Loaded object must be a single object
137 if ~(size(obj,1) == 1 && size(obj,2) == 1),
138 atest = false; end
139 end
140
141 end
142 % </AlgoCode>
143 else
144 atest = false;
145 end
146
147 % Return a result structure
148 result = utp_prepare_result(atest, stest, dbstack, mfilename);
149 end % END UTP_01
150
151 end