Mercurial > repos > public > sbplib
comparison +grid/CartesianTest.m @ 820:501750fbbfdb
Merge with feature/grids
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Fri, 07 Sep 2018 14:40:58 +0200 |
parents | 7c1d3fc33f90 |
children |
comparison
equal
deleted
inserted
replaced
819:fdf0ef9150f4 | 820:501750fbbfdb |
---|---|
1 function tests = CartesianTest() | |
2 tests = functiontests(localfunctions); | |
3 end | |
4 | |
5 | |
6 function testWarningEmptyGrid(testCase) | |
7 in = { | |
8 {[]}, | |
9 {[],[1]}, | |
10 {[1],[2], []}, | |
11 }; | |
12 | |
13 for i = 1:length(in) | |
14 testCase.verifyError(@()grid.Cartesian(in{i}{:}),'grid:Cartesian:EmptyGrid'); | |
15 end | |
16 end | |
17 | |
18 function testN(testCase) | |
19 in = { | |
20 {[1 2 3]}, | |
21 {[1 2 3],[1 2]}, | |
22 {[1 2 3],[1 2 3]}, | |
23 {[1 2 3],[1 2 3], [1]}, | |
24 {[1 2 3],[1 2 3], [1 3 4]}, | |
25 }; | |
26 | |
27 out = [3,6,9,9,27]; | |
28 | |
29 for i = 1:length(in) | |
30 g = grid.Cartesian(in{i}{:}); | |
31 testCase.verifyEqual(g.N(),out(i)); | |
32 end | |
33 end | |
34 | |
35 | |
36 function testD(testCase) | |
37 in = { | |
38 {[1 2 3]}, | |
39 {[1 2 3],[1 2]}, | |
40 {[1 2 3],[1 2 3]}, | |
41 {[1 2 3],[1 2 3], [1]}, | |
42 {[1 2 3],[1 2 3], [1 3 4]}, | |
43 }; | |
44 | |
45 out = [1,2,2,3,3]; | |
46 | |
47 for i = 1:length(in) | |
48 g = grid.Cartesian(in{i}{:}); | |
49 testCase.verifyEqual(g.D(),out(i)); | |
50 end | |
51 end | |
52 | |
53 function testSize(testCase) | |
54 in = { | |
55 {[1 2 3]}, | |
56 {[1 2 3],[1 2]}, | |
57 {[1 2 3],[1 2 3]}, | |
58 {[1 2 3],[1 2 3], [1]}, | |
59 {[1 2 3],[1 2 3], [1 3 4]}, | |
60 }; | |
61 | |
62 out = { | |
63 [3], | |
64 [3 2], | |
65 [3 3], | |
66 [3 3 1], | |
67 [3 3 3], | |
68 }; | |
69 | |
70 for i = 1:length(in) | |
71 g = grid.Cartesian(in{i}{:}); | |
72 testCase.verifyEqual(g.size(),out{i}); | |
73 end | |
74 end | |
75 | |
76 function testPoints(testCase) | |
77 in = { | |
78 {[1 2]}, | |
79 {[1 2],[3 4]}, | |
80 {[1 2],[3 4], [5 6]}, | |
81 }; | |
82 | |
83 out = { | |
84 [[1; 2]], | |
85 [[1; 1; 2; 2],[3; 4; 3; 4]], | |
86 [[1; 1; 1; 1; 2; 2; 2; 2],[3; 3; 4; 4; 3; 3; 4; 4],[ 5; 6; 5; 6; 5; 6; 5; 6]], | |
87 }; | |
88 | |
89 for i = 1:length(in) | |
90 g = grid.Cartesian(in{i}{:}); | |
91 testCase.verifyEqual(g.points(),out{i}); | |
92 end | |
93 end | |
94 | |
95 function testMatrices(testCase) | |
96 in = { | |
97 {[1 2]}, | |
98 {[1 2],[3 4]}, | |
99 {[1 2],[3 4], [5 6]}, | |
100 }; | |
101 | |
102 out{1}{1} = [1; 2]; | |
103 | |
104 out{2}{1} = [1, 1; 2, 2]; | |
105 out{2}{2} = [3, 4; 3, 4]; | |
106 | |
107 out{3}{1}(:,:,1) = [1, 1; 2, 2]; | |
108 out{3}{1}(:,:,2) = [1, 1; 2, 2]; | |
109 | |
110 out{3}{2}(:,:,1) = [3, 4; 3, 4]; | |
111 out{3}{2}(:,:,2) = [3, 4; 3, 4]; | |
112 | |
113 out{3}{3}(:,:,1) = [5, 5; 5, 5]; | |
114 out{3}{3}(:,:,2) = [6, 6; 6, 6]; | |
115 | |
116 for i = 1:length(in) | |
117 g = grid.Cartesian(in{i}{:}); | |
118 testCase.verifyEqual(g.matrices(),out{i}); | |
119 end | |
120 end | |
121 | |
122 | |
123 function testRestrictFuncInvalidInput(testCase) | |
124 inG1 = { | |
125 {[1 2 3 4 5]}, | |
126 {[1 2 3],[4 5 6 7 8]}, | |
127 {[1 2 3],[4 5 6 7 8]}, | |
128 {[1 2 3],[4 5 6 7 8]}, | |
129 }; | |
130 | |
131 inG2 = { | |
132 {[1 3 4 5]}, | |
133 {[1 3],[4 5 6 8]}, | |
134 {[1 3],[4 6 8]}, | |
135 {[1 3],[4 6 8]}, | |
136 }; | |
137 | |
138 inGf = { | |
139 [1; 2; 3; 4; 5], | |
140 [14; 15; 16; 17; 18; 24; 25; 26; 27; 28; 34; 35; 36; 37; 38]; | |
141 [14; 15; 16; 17; 18; 24; 25; 26; 27; 28; 34; 35; 36]; | |
142 [14; 15; 16; 17; 18; 24; 25; 26; 27; 28; 34; 35; 36; 37; 38; 39; 40]; | |
143 }; | |
144 | |
145 out = { | |
146 'grid:Cartesian:restrictFunc:NonMatchingGrids', | |
147 'grid:Cartesian:restrictFunc:NonMatchingGrids', | |
148 'grid:Cartesian:restrictFunc:NonMatchingFunctionSize', | |
149 'grid:Cartesian:restrictFunc:NonMatchingFunctionSize', | |
150 }; | |
151 | |
152 for i = 1:length(inG1) | |
153 g1 = grid.Cartesian(inG1{i}{:}); | |
154 g2 = grid.Cartesian(inG2{i}{:}); | |
155 testCase.verifyError(@()g1.restrictFunc(inGf{i},g2),out{i}); | |
156 end | |
157 end | |
158 | |
159 function testRestrictFunc(testCase) | |
160 inG1 = { | |
161 {[1 2 3 4 5]}, | |
162 {[1 2 3],[4 5 6 7 8]}, | |
163 }; | |
164 | |
165 inG2 = { | |
166 {[1 3 5]}, | |
167 {[1 3],[4 6 8]}, | |
168 }; | |
169 | |
170 inGf = { | |
171 [1; 2; 3; 4; 5], | |
172 [14; 15; 16; 17; 18; 24; 25; 26; 27; 28; 34; 35; 36; 37; 38]; | |
173 }; | |
174 | |
175 outGf = { | |
176 [1; 3; 5], | |
177 [14; 16; 18; 34; 36; 38]; | |
178 }; | |
179 | |
180 for i = 1:length(inG1) | |
181 g1 = grid.Cartesian(inG1{i}{:}); | |
182 g2 = grid.Cartesian(inG2{i}{:}); | |
183 testCase.verifyEqual(g1.restrictFunc(inGf{i}, g2), outGf{i}); | |
184 end | |
185 end | |
186 | |
187 function testScaling(testCase) | |
188 in = {[1 2 3], [1 2]}; | |
189 g = grid.Cartesian(in{:}); | |
190 | |
191 testCase.verifyError(@()g.scaling(),'grid:Cartesian:NoScalingSet'); | |
192 | |
193 g.h = [2 1]; | |
194 testCase.verifyEqual(g.scaling(),[2 1]); | |
195 | |
196 end | |
197 | |
198 | |
199 function testGetBoundaryNames(testCase) | |
200 in = { | |
201 {[1 2 3]}, | |
202 {[1 2 3], [4 5]}, | |
203 {[1 2 3], [4 5], [6 7 8]}, | |
204 }; | |
205 | |
206 out = { | |
207 {'l', 'r'}, | |
208 {'w', 'e', 's', 'n'}, | |
209 {'w', 'e', 's', 'n', 'd', 'u'}, | |
210 }; | |
211 | |
212 for i = 1:length(in) | |
213 g = grid.Cartesian(in{i}{:}); | |
214 testCase.verifyEqual(g.getBoundaryNames(), out{i}); | |
215 end | |
216 end | |
217 | |
218 function testGetBoundary(testCase) | |
219 grids = { | |
220 {[1 2 3]}, | |
221 {[1 2 3], [4 5]}, | |
222 {[1 2 3], [4 5], [6 7 8]}, | |
223 }; | |
224 | |
225 boundaries = { | |
226 {'l', 'r'}, | |
227 {'w', 'e', 's', 'n'}, | |
228 {'w', 'e', 's', 'n', 'd', 'u'}, | |
229 }; | |
230 | |
231 | |
232 % 1d | |
233 out{1,1} = 1; | |
234 out{1,2} = 3; | |
235 | |
236 % 2d | |
237 out{2,1} = [ | |
238 1,4; | |
239 1,5; | |
240 ]; | |
241 out{2,2} = [ | |
242 3,4; | |
243 3,5; | |
244 ]; | |
245 out{2,3} = [ | |
246 1,4; | |
247 2,4; | |
248 3,4; | |
249 ]; | |
250 out{2,4} = [ | |
251 1,5; | |
252 2,5; | |
253 3,5; | |
254 ]; | |
255 | |
256 % 3d | |
257 out{3,1} = [ | |
258 1,4,6; | |
259 1,4,7; | |
260 1,4,8; | |
261 1,5,6; | |
262 1,5,7; | |
263 1,5,8; | |
264 ]; | |
265 out{3,2} = [ | |
266 3,4,6; | |
267 3,4,7; | |
268 3,4,8; | |
269 3,5,6; | |
270 3,5,7; | |
271 3,5,8; | |
272 ]; | |
273 out{3,3} = [ | |
274 1,4,6; | |
275 1,4,7; | |
276 1,4,8; | |
277 2,4,6; | |
278 2,4,7; | |
279 2,4,8; | |
280 3,4,6; | |
281 3,4,7; | |
282 3,4,8; | |
283 ]; | |
284 out{3,4} = [ | |
285 1,5,6; | |
286 1,5,7; | |
287 1,5,8; | |
288 2,5,6; | |
289 2,5,7; | |
290 2,5,8; | |
291 3,5,6; | |
292 3,5,7; | |
293 3,5,8; | |
294 ]; | |
295 out{3,5} = [ | |
296 1,4,6; | |
297 1,5,6; | |
298 2,4,6; | |
299 2,5,6; | |
300 3,4,6; | |
301 3,5,6; | |
302 ]; | |
303 out{3,6} = [ | |
304 1,4,8; | |
305 1,5,8; | |
306 2,4,8; | |
307 2,5,8; | |
308 3,4,8; | |
309 3,5,8; | |
310 ]; | |
311 | |
312 for ig = 1:length(grids) | |
313 g = grid.Cartesian(grids{ig}{:}); | |
314 for ib = 1:length(boundaries{ig}) | |
315 testCase.verifyEqual(g.getBoundary(boundaries{ig}{ib}), out{ig,ib}); | |
316 end | |
317 end | |
318 end |