Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/smodel/utp_smodel_setXunits.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_SMODEL_SETXUNITS a set of UTPs for the smodel/setXunits method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_smodel_setXunits.m,v 1.2 2011/04/06 19:15:34 ingo Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The setXunits method of the smodel class sets the xunits property. | |
11 % | |
12 % </MethodDescription> | |
13 | |
14 function results = utp_smodel_setXunits(varargin) | |
15 | |
16 % Check the inputs | |
17 if nargin == 0 | |
18 | |
19 % Some keywords | |
20 cl = 'smodel'; | |
21 mthd = 'setXunits'; | |
22 prop = 'xunits'; | |
23 | |
24 disp('******************************************************'); | |
25 disp(['**** Running UTPs for ' cl '/' mthd]); | |
26 disp('******************************************************'); | |
27 | |
28 % Test objects | |
29 s1 = smodel('a1*x1 + a2*x2 + a3*x3'); | |
30 s1.setName(); | |
31 | |
32 s2 = smodel('a1*x1 + a2*x2'); | |
33 s2.setName(); | |
34 | |
35 s3 = smodel('a1*x1'); | |
36 s3.setName(); | |
37 | |
38 sv = [s1, s2, s1]; | |
39 sm = [s1, s2, s1; s1, s2, s1]; | |
40 | |
41 % Exception list for the UTPs: | |
42 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples(); | |
43 | |
44 % The setter method have different possibilities to set a property | |
45 val1 = 'Hz'; % obj.setXunits(val1) | |
46 val2 = unit('s'); % obj.setXunits(val2) | |
47 val3 = plist(prop, 'm'); % obj.setXunits(plist('xunits', 'm') | |
48 val4 = {val1, val2, val3}; % obj.setXunits(val1, val2, val3) | |
49 val5 = {{val1, val2, val3}}; % obj.setXunits({val1, val2, val3}) | |
50 val6 = {{val1, val2, val3}, val1, val2}; % obj.setXunits({val1, val2, val3}, val1, val2) | |
51 | |
52 % Run the general tests | |
53 results(1) = utp_genericSet_minfo(mthd, s1, prop, @algoTests_minfo); | |
54 results(2) = utp_genericAnyShape(mthd, sv, val1, @algoTests); | |
55 results(3) = utp_genericAnyShape(mthd, sv, val2, @algoTests); | |
56 results(4) = utp_genericAnyShape(mthd, sv, val3, @algoTests); | |
57 results(5) = utp_genericAnyShape(mthd, sv, val4, @algoTests); | |
58 results(6) = utp_genericAnyShape(mthd, sv, val5, @algoTests); | |
59 results(7) = utp_genericAnyShape(mthd, sv, val6, @algoTests); | |
60 results(8) = utp_genericAnyShape(mthd, sm, val6, @algoTests); | |
61 results(9) = utp_genericList(mthd, s1, s2, s3, val1, @algoTests); | |
62 results(10) = utp_genericList(mthd, s1, sv, s3, val3, @algoTests); | |
63 results(11) = utp_genericHistory(mthd, s1, val1, ple2); | |
64 results(12) = utp_genericModify(mthd, s1, val5, @algoTests, ple1); % test the modifier call | |
65 results(13) = utp_genericOutput(mthd, s1, s2, val6, @algoTests, ple2); % test the outputs | |
66 | |
67 disp('Done.'); | |
68 disp('******************************************************'); | |
69 | |
70 elseif nargin == 1 % Check for UTP functions | |
71 if strcmp(varargin{1}, 'isutp') | |
72 results = 1; | |
73 else | |
74 results = 0; | |
75 end | |
76 else | |
77 error('### Incorrect inputs') | |
78 end | |
79 | |
80 % Check that the default value un the PLIST | |
81 function atest = algoTests_minfo(defVal) | |
82 atest = true; | |
83 % Check default value for the key 'xunits' | |
84 if ~eq(defVal, []), atest = false; end | |
85 end | |
86 | |
87 % Check that the property have the correct value | |
88 function atest = algoTests(in, out, idx, value) | |
89 atest = true; | |
90 % Check that the input and output objects are the same except the | |
91 % property 'xunits' and the history | |
92 ple = plist('EXCEPTIONS', {'created', 'proctime', 'UUID', 'hist', prop}); | |
93 if ~eq(in(idx), out(idx), ple), atest = false; end | |
94 if ~eq(in(idx).hist, out(idx).hist.inhists), atest = false; end | |
95 % Check that the parameter gets the correct value. | |
96 if isa(value, 'plist') && value.nparams == 1 && value.isparam(prop) | |
97 % The value was set with a plist. | |
98 values = processValues([], value.find(prop)); | |
99 if ~isequal(out(idx).(prop), values), atest = false; end | |
100 else | |
101 values = processValues([], value); | |
102 if ~isequal(out(idx).(prop), values), atest = false; end | |
103 end | |
104 end | |
105 | |
106 function values = processValues(values, val) | |
107 switch class(val) | |
108 case 'char' | |
109 values = [values unit(val)]; | |
110 case 'unit' | |
111 values = [values reshape(val, 1, [])]; | |
112 case 'cell' | |
113 for ii=1:numel(val) | |
114 values = processValues(values, val{ii}); | |
115 end | |
116 case 'plist' | |
117 if length(val) == 1 && isa(val, 'plist') && isparam(val, prop) | |
118 vals = find(val, prop); | |
119 values = processValues(values, vals); | |
120 end | |
121 end | |
122 end | |
123 | |
124 end |