comparison +grid/CartesianTest.m @ 154:c7b2f645101f feature/grids

Added classes and functions for Cartesian and equidistant grids.
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 18 Feb 2016 16:46:02 +0100
parents
children ba1ae5b2c45e
comparison
equal deleted inserted replaced
153:7aee9eba3bb8 154:c7b2f645101f
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
54 function testPoints(testCase)
55 in = {
56 {[1 2]},
57 {[1 2],[3 4]},
58 {[1 2],[3 4], [5 6]},
59 };
60
61 out = {
62 [[1; 2]],
63 [[1; 1; 2; 2],[3; 4; 3; 4]],
64 [[1; 1; 1; 1; 2; 2; 2; 2],[3; 3; 4; 4; 3; 3; 4; 4],[ 5; 6; 5; 6; 5; 6; 5; 6]],
65 };
66
67 for i = 1:length(in)
68 g = grid.Cartesian(in{i}{:});
69 testCase.verifyEqual(g.points(),out{i});
70 end
71 end
72
73 function testMatrices(testCase)
74 in = {
75 {[1 2]},
76 {[1 2],[3 4]},
77 {[1 2],[3 4], [5 6]},
78 };
79
80 out{1}{1} = [1; 2];
81
82 out{2}{1} = [1, 1; 2, 2];
83 out{2}{2} = [3, 4; 3, 4];
84
85 out{3}{1}(:,:,1) = [1, 1; 2, 2];
86 out{3}{1}(:,:,2) = [1, 1; 2, 2];
87
88 out{3}{2}(:,:,1) = [3, 4; 3, 4];
89 out{3}{2}(:,:,2) = [3, 4; 3, 4];
90
91 out{3}{3}(:,:,1) = [5, 5; 5, 5];
92 out{3}{3}(:,:,2) = [6, 6; 6, 6];
93
94 for i = 1:length(in)
95 g = grid.Cartesian(in{i}{:});
96 testCase.verifyEqual(g.matrices(),out{i});
97 end
98 end