Mercurial > hg > ltpda
comparison m-toolbox/test/test_ao_add.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 mc | |
2 | |
3 %% Some AOs | |
4 | |
5 c1 = ao(1); c1.setName; | |
6 c2 = ao(2); c2.setName; | |
7 c3 = ao(3); c3.setName; | |
8 c4 = ao(randn(3,3)); c4.setName; | |
9 c5 = ao(randn(3,3)); c5.setName; | |
10 c6 = ao(randn(3,1)); c6.setName; | |
11 c7 = ao(randn(1,3)); c7.setName; | |
12 | |
13 | |
14 t1 = ao(plist('tsfcn', 't', 'fs', 10, 'nsecs', 10)); t1.setName; | |
15 t2 = ao(plist('tsfcn', 'sqrt(t)', 'fs', 10, 'nsecs', 10)); t2.setName; | |
16 t3 = ao(plist('tsfcn', 't.^2', 'fs', 10, 'nsecs', 10)); t3.setName; | |
17 | |
18 f1 = ao(plist('fsfcn', 'f', 'f', 'logspace(-4,1,100)')); f1.setName; | |
19 f2 = ao(plist('fsfcn', '1./f', 'f', 'logspace(-4,1,100)')); f2.setName; | |
20 f3 = ao(plist('fsfcn', 'sqrt(f)', 'f', 'logspace(-4,1,100)')); f3.setName; | |
21 | |
22 x1 = ao(plist('xyfcn', 'x', 'x', '1:100')); x1.setName; | |
23 x2 = ao(plist('xyfcn', '1./x', 'x', '1:100')); x2.setName; | |
24 x3 = ao(plist('xyfcn', 'sqrt(x)', 'x', '1:100')); x3.setName; | |
25 | |
26 | |
27 %% Rule 1 | |
28 | |
29 %---------- CDATA | |
30 % cdata + cdata | |
31 r1 = plus(c1,c3); | |
32 % cdata + tsdata | |
33 r2 = plus(c1,t1); | |
34 % cdata + fsdata | |
35 r3 = plus(c1,f1); | |
36 % cdata + xydata | |
37 r4 = plus(c1,x1); | |
38 | |
39 %---------- TSDATA | |
40 % tsdata + tsdata | |
41 r5 = plus(t1, t2); | |
42 % tsdata + fsdata | |
43 try | |
44 r6 = plus(t1, f2); | |
45 error('Data types should be incompatible: booo!'); | |
46 catch | |
47 lasterr | |
48 warning('Data types not compatible: fsdata+tsdata: hoorah!'); | |
49 end | |
50 % tsdata + xydata | |
51 r7 = plus(t1, x2); | |
52 % tsdata + cdata | |
53 r8 = plus(t1, c2); | |
54 | |
55 %---------- FSDATA | |
56 % fsdata + tsdata | |
57 try | |
58 r9 = plus(f1, t2); | |
59 error('Data types should be incompatible: booo!'); | |
60 catch | |
61 lasterr | |
62 warning('Data types not compatible: fsdata+tsdata: hoorah!'); | |
63 end | |
64 % fsdata + fsdata | |
65 r10 = plus(f1, f2); | |
66 % fsdata + xydata | |
67 r11 = plus(f1, x2); | |
68 % fsdata + cdata | |
69 r12 = plus(f1, c2); | |
70 | |
71 %---------- XYDATA | |
72 % xydata + tsdata | |
73 r13 = plus(x1, t2); | |
74 % xydata + fsdata | |
75 r14 = plus(x1, f2); | |
76 % xydata + xydata | |
77 r15 = plus(x1, x2); | |
78 % xydata + cdata | |
79 r16 = plus(x1, c2); | |
80 | |
81 | |
82 | |
83 | |
84 %% Rule 2: vector + single | |
85 | |
86 v = [t1 t2]; | |
87 s = c2; | |
88 | |
89 % one output | |
90 r1 = plus(v,s) | |
91 r2 = plus(s,v) | |
92 | |
93 % multiple outputs | |
94 [r1 r2] = plus(v,s) | |
95 | |
96 %% Rule 2: vector + number | |
97 | |
98 v = [t1 t2]; | |
99 | |
100 % one output | |
101 r1 = plus(v,2) | |
102 r2 = plus(2,v) | |
103 | |
104 | |
105 | |
106 %% Rule 3: V_N + V_M | |
107 | |
108 v1 = [t1 t2]; | |
109 v2 = [c1 c2 c3]; | |
110 | |
111 try | |
112 r = plus(v1,v2); | |
113 error('Rule 3 should fail: booo!'); | |
114 catch | |
115 lasterr | |
116 warning('Rule 3 fails: hoorah!'); | |
117 end | |
118 | |
119 %% Rule 4: V_N + U_N | |
120 | |
121 v1 = [t1 t2 t3]; | |
122 v2 = [x1 x2 x3]; | |
123 | |
124 r = plus(v1,v2); | |
125 [r1 r2 r3] = plus(v1,v2); | |
126 | |
127 %% Rule 5: matrix + single | |
128 | |
129 m = [t1 t2 t3; x1 x2 x3]; | |
130 s = c2; | |
131 | |
132 r1 = plus(m,s); | |
133 r2 = plus(s,m); | |
134 | |
135 %% Rule 6: matrix + column vector | |
136 | |
137 m = [t1 t2 t3; x1 x2 x3]; | |
138 v = [c1; c2]; | |
139 | |
140 r1 = plus(m,v) | |
141 r2 = plus(v,m) | |
142 | |
143 %% Rule 7: matrix + row vector | |
144 | |
145 m = [t1 t2 t3; x1 x2 x3]; | |
146 v = [c1 c2 c3]; | |
147 | |
148 r1 = plus(m,v) | |
149 r2 = plus(v,m) | |
150 | |
151 %% Rule 8: M_NP + V_1Q (or V_Q1) | |
152 | |
153 | |
154 m = [t1 t2 t3; x1 x2 x3]; | |
155 v = [c1 c2]; | |
156 try | |
157 r = plus(m,v) | |
158 error('Rule 8 should fail: booo!'); | |
159 catch | |
160 lasterr | |
161 warning('Rule 8 fails: hoorah!'); | |
162 end | |
163 try | |
164 r = plus(v,m) | |
165 error('Rule 8 should fail: booo!'); | |
166 catch | |
167 lasterr | |
168 warning('Rule 8 fails: hoorah!'); | |
169 end | |
170 | |
171 m = [t1 t2 t3; x1 x2 x3]; | |
172 v = [c1; c2; c3]; | |
173 try | |
174 r = plus(m,v) | |
175 error('Rule 8 should fail: booo!'); | |
176 catch | |
177 lasterr | |
178 warning('Rule 8 fails: hoorah!'); | |
179 end | |
180 try | |
181 r = plus(v,m) | |
182 error('Rule 8 should fail: booo!'); | |
183 catch | |
184 lasterr | |
185 warning('Rule 8 fails: hoorah!'); | |
186 end | |
187 | |
188 %% Rule 9: M_NP + H_PQ | |
189 | |
190 m = [t1 t2; x1 x2]; | |
191 h = [c1 c2 c3; c1 c2 c3]; | |
192 | |
193 try | |
194 r = plus(m,h) | |
195 error('Rule 9 should fail: booo!'); | |
196 catch | |
197 lasterr | |
198 warning('Rule 9 fails: hoorah!'); | |
199 end | |
200 | |
201 %% Rule 10: matrix + matrix | |
202 | |
203 m = [t1 t2 t3; x1 x2 x3]; | |
204 h = [c1 c2 c3; c1 c2 c3]; | |
205 | |
206 r = plus(m,h) | |
207 | |
208 %% Rule 11: more than two inputs | |
209 | |
210 m = [t1 t2 t3; x1 x2 x3]; | |
211 v = [c1; c2]; | |
212 | |
213 r = plus(m,v, c3, v, m) | |
214 | |
215 %% Check units | |
216 | |
217 | |
218 % empty + m = m | |
219 t1.setYunits('m'); | |
220 t2.setYunits(''); | |
221 r = plus(t1,t2) | |
222 | |
223 % V + m = error | |
224 t2.setYunits('V'); | |
225 try | |
226 r = plus(t1,t2) | |
227 error('This unit check should fail: booo!'); | |
228 catch | |
229 lasterr | |
230 warning('The unit check failed: hoorah!'); | |
231 end | |
232 |