comparison +blockmatrix/fromMatrixTest.m @ 820:501750fbbfdb

Merge with feature/grids
author Jonatan Werpers <jonatan@werpers.com>
date Fri, 07 Sep 2018 14:40:58 +0200
parents a5f1b0267dba
children
comparison
equal deleted inserted replaced
819:fdf0ef9150f4 820:501750fbbfdb
1 function tests = fromMatrixTest()
2 tests = functiontests(localfunctions);
3 end
4
5 function testErrorNonMatchingDim(testCase)
6 in = {
7 {magic(5), {[1 2 3], [4]}},
8 {magic(5), {[1 1 1 1 1 1], [5]}},
9 {magic(5), {[5], [1 1 1 1 1 1]}},
10 {ones(4,2),{[2 3],[2]}},
11 {ones(4,2),{[2 2],[3]}},
12 };
13
14 for i = 1:length(in)
15 testCase.verifyError(@()blockmatrix.fromMatrix(in{i}{:}),'blockmatrix:fromMatrix:NonMatchingDim');
16 end
17 end
18
19 function testFromMatrix(testCase)
20 cases = {
21 {
22 {[],{[],[]}},
23 {}
24 },
25 {
26 {
27 magic(3),
28 {[3],[3]}
29 },
30 {magic(3)}
31 },
32 {
33 {
34 magic(3),
35 {[1 1 1],[1 1 1]}
36 },
37 mat2cell(magic(3),[1 1 1],[1 1 1])
38 },
39 {
40 {
41 [17 24 1 8 15; 23 5 7 14 16; 4 6 13 20 22; 10 12 19 21 3; 11 18 25 2 9],
42 {[1 4],[2 3]}
43 },
44 {
45 [17 24], [1 8 15];
46 [23 5; 4 6; 10 12; 11 18], [7 14 16; 13 20 22; 19 21 3; 25 2 9];
47 };
48 },
49 {
50 {
51 magic(3),
52 {[1 0 2],[1 2 0]}
53 },
54 mat2cell(magic(3),[1 0 2],[1 2 0])
55 },
56 {
57 {
58 zeros(0,1),
59 {0,1},
60 },
61 {zeros(0,1)}
62 },
63 };
64 for i = 1:length(cases)
65 out = convertToFull(blockmatrix.fromMatrix(cases{i}{1}{:}));
66 expected = cases{i}{2};
67 testCase.verifyEqual(out,expected);
68 end
69 end
70
71 function C = convertToFull(C)
72 [N,M] = size(C);
73 for i = 1:N
74 for j = 1:M
75 C{i,j} = full(C{i,j});
76 end
77 end
78 end