44
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1 % UTP_PEST_SETYUNITS a set of UTPs for the pest/setYunits method
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
3 % M Hewitson 06-08-08
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
4 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5 % $Id: utp_pest_setYunits.m,v 1.4 2011/04/06 19:14:54 ingo Exp $
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8 % <MethodDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10 % The setYunits method of the pest class sets the yunits property.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12 % </MethodDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14 function results = utp_pest_setYunits(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
16 % Check the inputs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
17 if nargin == 0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19 % Some keywords
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20 class = 'pest';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21 mthd = 'setYunits';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22 prop = 'yunits';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24 disp('******************************************************');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25 disp(['**** Running UTPs for ' class '/' mthd]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26 disp('******************************************************');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
28 % Test objects
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
29 pe1 = pest([8, 9]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
30 pe1.setName;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
31 pe2 = pest([1 2]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
32 pe2.setName;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
33 pe3 = pe1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
34
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
35 pev = [pe1, pe2, pe1];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
36 pem = [pe1, pe2, pe1; pe1, pe2, pe1];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
37
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
38 % Exception list for the UTPs:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
39 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
40
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
41 % The setter method have different possibilities to set a property
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
42 val1 = 'Hz^2 m^-2';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
43 val2 = plist(prop, unit('Hz^2 m^-2'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
44 val3 = {'kg', 'Hz'};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
45 val4 = [unit('s'), unit('Hz')];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
46
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
47 % Run the general tests
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
48 results(1) = utp_genericSet_minfo(mthd, pe1, prop, @algoTests_minfo); % test getInfo call
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
49 results(2) = utp_genericAnyShape(mthd, pev, val1, @algoTests); % test vector
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
50 results(3) = utp_genericAnyShape(mthd, pev, val2, @algoTests); % test vector call with plist
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
51 results(4) = utp_genericAnyShape(mthd, pev, val3, @algoTests); % test vector call
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
52 results(5) = utp_genericAnyShape(mthd, pev, val4, @algoTests); % test vector call
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
53 results(6) = utp_genericAnyShapeInternal(mthd, pev, val1, @algoTestsInternal); % test internal vector call
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
54 results(7) = utp_genericAnyShape(mthd, pem, val1, @algoTests); % test matrix call
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
55 results(8) = utp_genericAnyShape(mthd, pem, val2, @algoTests); % test matrix call with plist
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
56 results(9) = utp_genericAnyShapeInternal(mthd, pem, val1, @algoTestsInternal); % test internal matrix call
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
57 results(10) = utp_genericList(mthd, pe1, pe2, pe3, val1, @algoTests); % test list
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
58 results(11) = utp_genericList(mthd, pe1, pe2, pe3, val2, @algoTests); % test list with plist
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
59 results(12) = utp_genericList(mthd, pe1, pev, pem, val1, @algoTests); % test mixed shape of input objs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
60 results(13) = utp_genericHistory(mthd, pe1, val1, ple2); % test the history
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
61 results(14) = utp_genericModify(mthd, pe1, val1, @algoTests, ple1); % test the modifier call
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
62 results(15) = utp_genericOutput(mthd, pe1, pe2, val1, @algoTests, ple2); % test the outputs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
63
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
64 disp('Done.');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
65 disp('******************************************************');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
66
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
67 elseif nargin == 1 % Check for UTP functions
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
68 if strcmp(varargin{1}, 'isutp')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
69 results = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
70 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
71 results = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
72 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
73 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
74 error('### Incorrect inputs')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
75 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
76
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
77 % Check that the default value un the PLIST
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
78 function atest = algoTests_minfo(defVal)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
79 atest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
80 % Check default value for the key 'yunits'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
81 if ~eq(defVal, []), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
82 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
83
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
84 % Check that the property have the correct value
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
85 function atest = algoTests(in, out, idx, value)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
86 atest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
87 % Check that the input and output objects are the same except the
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
88 % property 'yunits' and the history
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
89 ple = plist('EXCEPTIONS', {'created', 'proctime', 'UUID', 'hist', prop});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
90 if ~eq(in(idx), out(idx), ple), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
91 if ~eq(in(idx).hist, out(idx).hist.inhists), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
92 % Check that the parameter gets the correct value.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
93 if isa(value, 'plist') && value.nparams == 1 && value.isparam(prop)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
94 % The value was set with a plist.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
95 val = value.find(prop);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
96 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
97 val = value;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
98 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
99 if ischar(val)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
100 val = unit(val);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
101 elseif iscell(val)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
102 val = unit(val{:});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
103 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
104 if ~eq(out(idx).(prop), val), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
105 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
106
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
107 % Check that the property have the correct value for an internal call
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
108 function atest = algoTestsInternal(in, out, idx, value)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
109 atest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
110 % Check that the input and output objects are the same except the
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
111 % property 'yunits' and the history
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
112 ple = plist('EXCEPTIONS', {'created', 'proctime', 'UUID', prop});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
113 if ~eq(in(idx), out(idx), ple), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
114 % Check that the parameter gets the correct value.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
115 if ischar(value)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
116 value = unit(value);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
117 elseif iscell(value)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
118 value = unit(value{:});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
119 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
120 if ~isequal(out(idx).(prop), value), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
121 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
122
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
123
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
124 end
|