comparison +grid/CartesianTest.m @ 168:ba1ae5b2c45e feature/grids

grid.Cartesian: Added methods and test to fulfilll abstract class.
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 24 Feb 2016 15:01:54 +0100
parents c7b2f645101f
children f7bb2a94d291
comparison
equal deleted inserted replaced
167:15baeb35f74e 168:ba1ae5b2c45e
48 g = grid.Cartesian(in{i}{:}); 48 g = grid.Cartesian(in{i}{:});
49 testCase.verifyEqual(g.D(),out(i)); 49 testCase.verifyEqual(g.D(),out(i));
50 end 50 end
51 end 51 end
52 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
53 75
54 function testPoints(testCase) 76 function testPoints(testCase)
55 in = { 77 in = {
56 {[1 2]}, 78 {[1 2]},
57 {[1 2],[3 4]}, 79 {[1 2],[3 4]},
94 for i = 1:length(in) 116 for i = 1:length(in)
95 g = grid.Cartesian(in{i}{:}); 117 g = grid.Cartesian(in{i}{:});
96 testCase.verifyEqual(g.matrices(),out{i}); 118 testCase.verifyEqual(g.matrices(),out{i});
97 end 119 end
98 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