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