comparison testing/utp_1.1/generic_utps/utp_903.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 % <TestDescription>
2 %
3 % Tests that the model <MODEL> responds to 'DIM' configuration key.
4 %
5 % </TestDescription>
6 %
7 % $Id: utp_903.m,v 1.4 2010/07/27 07:37:28 hewitson Exp $
8 %
9
10 function result = utp_903(cl, model_name, pl)
11
12 % <SyntaxDescription>
13 %
14 % Test that the model <MODEL> responds to 'DIM' configuration key.
15 %
16 % </SyntaxDescription>
17
18 try
19
20 % <SyntaxCode>
21 pl = combine(pl, plist('built-in', model_name, 'DIM', 1));
22 mdl1 = feval(cl, pl);
23 pl.pset('DIM', 2)
24 mdl2 = feval(cl, pl);
25 pl.pset('DIM', 3)
26 mdl3 = feval(cl, pl);
27 % </SyntaxCode>
28 stest = true;
29 catch err
30 disp(err.message)
31 msg = [err.message ' - ' err.stack(1).name ' - line ' num2str(err.stack(1).line)];
32 stest = false;
33 end
34
35 % <AlgoDescription>
36 %
37 % 1) Check that the model builds with DIM==1
38 % 2) Check that the model builds with DIM==2
39 % 3) Check that the model builds with DIM==3
40 % 4) Check that the 3 models are different
41 %
42 % </AlgoDescription>
43
44 atest = true;
45 if stest
46 msg = '';
47 % <AlgoCode>
48 % check we have a model of the correct class
49 if ~isa(mdl1, cl)
50 atest = false;
51 msg = sprintf('The model produced by %s is not a %s model', model_name, cl);
52 end
53 if ~isa(mdl2, cl)
54 atest = false;
55 msg = sprintf('The model produced by %s is not a %s model', model_name, cl);
56 end
57 if ~isa(mdl3, cl)
58 atest = false;
59 msg = sprintf('The model produced by %s is not a %s model', model_name, cl);
60 end
61
62 % check models are different by looking at the states
63 if ~isempty(mdl1.states) && ~isempty(mdl2.states)
64 if isequal(size(mdl1.states.ports), size(mdl2.states.ports))
65 atest = false;
66 msg = sprintf('The model %s with DIM=1 and DIM=2 has the same number of states.', model_name);
67 end
68 end
69 if ~isempty(mdl1.states) && ~isempty(mdl3.states)
70 if isequal(size(mdl1.states.ports), size(mdl3.states.ports))
71 atest = false;
72 msg = sprintf('The model %s with DIM=1 and DIM=3 has the same number of states.', model_name);
73 end
74 end
75 if ~isempty(mdl2.states) && ~isempty(mdl3.states)
76 if isequal(size(mdl2.states.ports), size(mdl3.states.ports))
77 atest = false;
78 msg = sprintf('The model %s with DIM=2 and DIM=3 has the same number of states.', model_name);
79 end
80 end
81
82 % check models are different by looking at the input sizes
83 if ~isempty(mdl1.inputsizes) && ~isempty(mdl2.inputsizes)
84 if isequal(mdl1.inputsizes, mdl2.inputsizes)
85 atest = false;
86 msg = sprintf('The model %s with DIM=1 and DIM=2 has the same input sizes.', model_name);
87 end
88 end
89 if ~isempty(mdl1.inputsizes) && ~isempty(mdl3.inputsizes)
90 if isequal(mdl1.inputsizes, mdl3.inputsizes)
91 atest = false;
92 msg = sprintf('The model %s with DIM=1 and DIM=3 has the same input sizes.', model_name);
93 end
94 end
95 if ~isempty(mdl2.inputsizes) && ~isempty(mdl3.inputsizes)
96 if isequal(mdl2.inputsizes, mdl3.inputsizes)
97 atest = false;
98 msg = sprintf('The model %s with DIM=2 and DIM=3 has the same input sizes.', model_name);
99 end
100 end
101 % check the history plist contains the correct value for 'DIM'
102 if mdl1.hist.plistUsed.find('DIM') ~= 1
103 atest = false;
104 msg = sprintf('The model %s with DIM=1 has the wrong DIM value in the history.', model_name);
105 end
106 if mdl2.hist.plistUsed.find('DIM') ~= 2
107 atest = false;
108 msg = sprintf('The model %s with DIM=2 has the wrong DIM value in the history.', model_name);
109 end
110 if mdl3.hist.plistUsed.find('DIM') ~= 3
111 atest = false;
112 msg = sprintf('The model %s with DIM=3 has the wrong DIM value in the history.', model_name);
113 end
114 % </AlgoCode>
115 else
116 atest = false;
117 end
118
119 % Return a result structure
120 dd = dbstack;
121 mfilename = dd(2).file(1:end-2);
122 result = utp_prepare_result(atest, stest, dbstack, mfilename, msg);
123 end % END UTP_901