Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/matrix/utp_matrix_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_MATRIX_LOADOBJ a set of UTPs for the matrix/loadobj method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_matrix_loadobj.m,v 1.1 2010/05/12 15:58:16 ingo Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The loadobj method of the matrix 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_matrix_loadobj(varargin) | |
25 | |
26 % Check the inputs | |
27 if nargin == 0 | |
28 | |
29 % Some keywords | |
30 class = 'matrix'; | |
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 = matrix(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 = matrix(fn); | |
102 obj_no = obj_no+1; | |
103 end | |
104 end | |
105 % </SyntaxCode> | |
106 stest = true; | |
107 catch err | |
108 disp(objs(obj_no).fname) | |
109 disp(fn) | |
110 disp(err.message) | |
111 stest = false; | |
112 end | |
113 | |
114 % <AlgoDescription> | |
115 % | |
116 % 1) Check the shape of the loaded objects. | |
117 % | |
118 % </AlgoDescription> | |
119 | |
120 atest = true; | |
121 if stest | |
122 % <AlgoCode> | |
123 for ii = 1:numel(objs) | |
124 obj = objs(ii).obj; | |
125 fname = objs(ii).fname; | |
126 | |
127 if ~isempty(strfind(fname, '_vec')) | |
128 % Loaded object must be a vector | |
129 if ~isvector(obj), atest = false; end | |
130 elseif ~isempty(strfind(fname, '_mat')) | |
131 % Loaded object must be a matrix | |
132 % REMARK: Known error in LTPDA version 1.9.2 | |
133 % A saved matrix doesn't keep the shape of the matrix. | |
134 if isempty(strfind(fname, '_192')) | |
135 if ~(size(obj,1) > 1 && size(obj,2) > 1), atest = false; end | |
136 end | |
137 else | |
138 % Loaded object must be a single object | |
139 if ~(size(obj,1) == 1 && size(obj,2) == 1), | |
140 atest = false; end | |
141 end | |
142 | |
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 |