Mercurial > repos > public > sbplib
comparison CellTest.m @ 524:6aad1c4c8e01 feature/grids
Merge default
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 02 Aug 2017 15:46:10 +0200 |
parents | da7df0c9af05 |
children | 2ce903f28193 |
comparison
equal
deleted
inserted
replaced
523:3c062cc72986 | 524:6aad1c4c8e01 |
---|---|
1 function tests = CellTest() | |
2 tests = functiontests(localfunctions); | |
3 end | |
4 | |
5 function testSize(testCase) | |
6 cases = { | |
7 {{}, [0, 0]}, | |
8 {{1}, [1, 1]}, | |
9 {{1, 2}, [1, 2]}, | |
10 {{1; 2}, [2, 1]}, | |
11 {{1, 2; 3, 4}, [2,2]}, | |
12 }; | |
13 | |
14 for i = 1:length(cases) | |
15 A = Cell(cases{i}{1}); | |
16 expected = cases{i}{2}; | |
17 | |
18 testCase.verifyEqual(size(A),expected); | |
19 end | |
20 end | |
21 | |
22 function testLength(testCase) | |
23 cases = { | |
24 {{}, 0}, | |
25 {{1}, 1}, | |
26 {{1, 2}, 2}, | |
27 {{1; 2}, 2}, | |
28 {{1, 2; 3, 4}, 2}, | |
29 }; | |
30 | |
31 for i = 1:length(cases) | |
32 A = Cell(cases{i}{1}); | |
33 expected = cases{i}{2}; | |
34 | |
35 testCase.verifyEqual(length(A),expected); | |
36 end | |
37 end | |
38 | |
39 function testTranspose(testCase) | |
40 testCase.verifyEqual(Cell({1i, 2}).', Cell({1i; 2})); | |
41 testCase.verifyEqual(Cell({1i; 2}).', Cell({1i, 2})); | |
42 end | |
43 | |
44 function testCtranspose(testCase) | |
45 testCase.verifyEqual(Cell({1i, 2})', Cell({1i; 2})); | |
46 testCase.verifyEqual(Cell({1i; 2})', Cell({1i, 2})); | |
47 end | |
48 | |
49 function testRoundIndexWithProperty(testCase) | |
50 A = Cell({3,2,1}); | |
51 | |
52 result = A([1,3]).data; | |
53 testCase.verifyEqual(result, {3, 1}); | |
54 end | |
55 | |
56 function testSubAssignmentRound(testCase) | |
57 cases = { | |
58 % { | |
59 % lArray, | |
60 % index, | |
61 % rhs, | |
62 % expectedResult | |
63 % }, | |
64 { | |
65 {}, | |
66 1, | |
67 {'a'}, | |
68 {'a'}, | |
69 }, | |
70 { | |
71 {1}, | |
72 1, | |
73 {'a'}, | |
74 {'a'}, | |
75 }, | |
76 { | |
77 {1,2,3}, | |
78 2, | |
79 {'a'}, | |
80 {1,'a',3}, | |
81 }, | |
82 { | |
83 {1,2,3}, | |
84 2, | |
85 [], | |
86 {1,3}, | |
87 }, | |
88 }; | |
89 | |
90 for i = 1:length(cases) | |
91 lArray = Cell(cases{i}{1}); | |
92 index = cases{i}{2}; | |
93 rhs = cases{i}{3}; | |
94 expectedResult = cases{i}{4}; | |
95 | |
96 lArray(index) = rhs; | |
97 | |
98 testCase.verifyEqual(lArray.data, expectedResult) | |
99 end | |
100 end | |
101 | |
102 function testSubAssignmentCurly(testCase) | |
103 cases = { | |
104 % { | |
105 % lArray, | |
106 % index, | |
107 % rhs, | |
108 % expectedResult | |
109 % }, | |
110 { | |
111 {}, | |
112 1, | |
113 'a', | |
114 {'a'}, | |
115 }, | |
116 { | |
117 {1}, | |
118 1, | |
119 'a', | |
120 {'a'}, | |
121 }, | |
122 { | |
123 {1,2,3}, | |
124 2, | |
125 'a', | |
126 {1,'a',3}, | |
127 }, | |
128 }; | |
129 | |
130 for i = 1:length(cases) | |
131 lArray = Cell(cases{i}{1}); | |
132 index = cases{i}{2}; | |
133 rhs = cases{i}{3}; | |
134 expectedResult = cases{i}{4}; | |
135 | |
136 lArray{index} = rhs; | |
137 | |
138 testCase.verifyEqual(lArray.data, expectedResult) | |
139 end | |
140 end | |
141 | |
142 function testIndexreferenceRound(testCase) | |
143 cases = { | |
144 % { | |
145 % array, | |
146 % index, | |
147 % roundResult | |
148 % }, | |
149 { | |
150 {1,2,3}, | |
151 1, | |
152 {1}, | |
153 }, | |
154 { | |
155 {1,3,2}, | |
156 2, | |
157 {3}, | |
158 }, | |
159 { | |
160 {1,3,2}, | |
161 [1 3], | |
162 {1, 2}, | |
163 }, | |
164 }; | |
165 | |
166 | |
167 for i = 1:length(cases) | |
168 array = Cell(cases{i}{1}); | |
169 index = cases{i}{2}; | |
170 expected = cases{i}{3}; | |
171 | |
172 result = array(index); | |
173 | |
174 testCase.verifyTrue(isa(result, 'Cell')); | |
175 testCase.verifyEqual(result.data, expected); | |
176 end | |
177 end | |
178 | |
179 function testEndIndexing(testCase) | |
180 C = Cell({1,2,3}); | |
181 | |
182 testCase.verifyEqual(C(end), Cell({3})); | |
183 testCase.verifyEqual(C{end}, 3); | |
184 end | |
185 | |
186 function testColonIndexing(testCase) | |
187 C = Cell({1, 2, 3}); | |
188 D = Cell({1; 2; 3}); | |
189 | |
190 testCase.verifyEqual(C(:), D); | |
191 testCase.verifyEqual(D(:), D); | |
192 end | |
193 | |
194 function testIndexreferenceCurly(testCase) | |
195 cases = { | |
196 % { | |
197 % array, | |
198 % index, | |
199 % curlyResult | |
200 % }, | |
201 { | |
202 {1,2,3}, | |
203 1, | |
204 1 | |
205 }, | |
206 { | |
207 {1,3,2}, | |
208 2, | |
209 3 | |
210 }, | |
211 }; | |
212 | |
213 | |
214 for i = 1:length(cases) | |
215 array = Cell(cases{i}{1}); | |
216 index = cases{i}{2}; | |
217 expected = cases{i}{3}; | |
218 | |
219 result = array{index}; | |
220 | |
221 testCase.verifyEqual(result, expected); | |
222 end | |
223 end | |
224 | |
225 function testConcat(testCase) | |
226 cases = { | |
227 {{},{}}, | |
228 {{1},{}}, | |
229 {{},{1}}, | |
230 {{1},{2}}, | |
231 {{1, 2},{3, 4}}, | |
232 {{1; 2},{3; 4}}, | |
233 }; | |
234 | |
235 horzCat = { | |
236 {}, | |
237 {1}, | |
238 {1}, | |
239 {1,2}, | |
240 {1, 2, 3, 4}, | |
241 {1, 3; 2, 4}, | |
242 }; | |
243 | |
244 vertCat = { | |
245 {}, | |
246 {1}, | |
247 {1}, | |
248 {1; 2}, | |
249 {1, 2; 3, 4}, | |
250 {1; 2; 3; 4}, | |
251 }; | |
252 | |
253 for i = 1:length(cases) | |
254 A = Cell(cases{i}{1}); | |
255 B = Cell(cases{i}{2}); | |
256 | |
257 C_horz = [A, B]; | |
258 C_vert = [A; B]; | |
259 | |
260 testCase.verifyEqual(C_horz.data, horzCat{i}); | |
261 testCase.verifyEqual(C_vert.data, vertCat{i}); | |
262 | |
263 end | |
264 end |