comparison testing/utp_1.1/utps/smodel/utp_smodel_setYunits.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_SETYUNITS a set of UTPs for the smodel/setYunits method
2 %
3 % M Hewitson 06-08-08
4 %
5 % $Id: utp_smodel_setYunits.m,v 1.1 2011/04/06 19:15:48 ingo Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % The setYunits method of the smodel class sets the yunits property.
11 %
12 % </MethodDescription>
13
14 function results = utp_smodel_setYunits(varargin)
15
16 % Check the inputs
17 if nargin == 0
18
19 % Some keywords
20 cl = 'smodel';
21 mthd = 'setYunits';
22 prop = 'yunits';
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.setYunits(val1)
46 val2 = unit('s'); % obj.setYunits(val2)
47 val3 = plist(prop, 'm'); % obj.setYunits(plist('yunits', 'm')
48 val4 = {val1, val2, val1}; % obj.setYunits(val1, val2, val3)
49
50 % Run the general tests
51 results(1) = utp_genericSet_minfo(mthd, s1, prop, @algoTests_minfo);
52 results(2) = utp_genericAnyShape(mthd, sv, val1, @algoTests);
53 results(3) = utp_genericAnyShape(mthd, sv, val2, @algoTests);
54 results(4) = utp_genericAnyShape(mthd, sv, val3, @algoTests);
55 results(5) = utp_genericAnyShape(mthd, sv, val4, @algoTests);
56 results(6) = utp_genericAnyShape(mthd, sm, val2, @algoTests);
57 results(7) = utp_genericList(mthd, s1, s2, s3, val1, @algoTests);
58 results(8) = utp_genericList(mthd, s1, sv, s3, val3, @algoTests);
59 results(9) = utp_genericHistory(mthd, s1, val1, ple2);
60 results(10) = utp_genericModify(mthd, s1, val2, @algoTests, ple1);
61 results(11) = utp_genericOutput(mthd, s1, s2, val1, @algoTests, ple2);
62
63 disp('Done.');
64 disp('******************************************************');
65
66 elseif nargin == 1 % Check for UTP functions
67 if strcmp(varargin{1}, 'isutp')
68 results = 1;
69 else
70 results = 0;
71 end
72 else
73 error('### Incorrect inputs')
74 end
75
76 % Check that the default value un the PLIST
77 function atest = algoTests_minfo(defVal)
78 atest = true;
79 % Check default value for the key 'yunits'
80 if ~eq(defVal, []), atest = false; end
81 end
82
83 % Check that the property have the correct value
84 function atest = algoTests(in, out, idx, varargin)
85 atest = true;
86 value = varargin;
87 % Check that the input and output objects are the same except the
88 % property 'yunits' and the history
89 ple = plist('EXCEPTIONS', {'created', 'proctime', 'UUID', 'hist', prop});
90 if ~eq(in(idx), out(idx), ple), atest = false; end
91 if ~eq(in(idx).hist, out(idx).hist.inhists), atest = false; end
92 % Check that the parameter gets the correct value.
93 if isa(value{1}, 'plist') && value{1}.nparams == 1 && value{1}.isparam(prop)
94 % The value was set with a plist.
95 values = processValues([], value{1}.find(prop));
96 if ~isequal(out(idx).(prop), values), atest = false; end
97 else
98 if iscell(value{1}), value = value{1}; end
99 if numel(value) == numel(out)
100 if ~isequal(out(idx).(prop), unit(value{idx})), atest = false; end
101 else
102 if ~isequal(out(idx).(prop), unit(value{1})), atest = false; end
103 end
104 end
105 end
106
107 function values = processValues(values, val)
108 switch class(val)
109 case 'char'
110 values = [values unit(val)];
111 case 'unit'
112 values = [values reshape(val, 1, [])];
113 case 'cell'
114 for ii=1:numel(val)
115 values = processValues(values, val{ii});
116 end
117 case 'plist'
118 if length(val) == 1 && isa(val, 'plist') && isparam(val, prop)
119 vals = find(val, prop);
120 values = processValues(values, vals);
121 end
122 end
123 end
124
125 end