Mercurial > repos > public > sbplib
comparison reshapeRowMajTest.m @ 820:501750fbbfdb
Merge with feature/grids
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Fri, 07 Sep 2018 14:40:58 +0200 |
parents | 5dad3b754c18 |
children |
comparison
equal
deleted
inserted
replaced
819:fdf0ef9150f4 | 820:501750fbbfdb |
---|---|
1 function tests = reshapeRowMajTest() | |
2 tests = functiontests(localfunctions); | |
3 end | |
4 | |
5 function test1D(testCase) | |
6 in = { | |
7 {5,[1; 2; 3; 4; 5]}, | |
8 {5,[1 2 3 4 5]}, | |
9 }; | |
10 out = { | |
11 [1; 2; 3; 4; 5], | |
12 [1; 2; 3; 4; 5], | |
13 }; | |
14 for i = 1:length(in) | |
15 testCase.verifyEqual(reshapeRowMaj(in{i}{2}, in{i}{1}),out{i}); | |
16 end | |
17 end | |
18 | |
19 | |
20 function testIdentity(testCase) | |
21 in = { | |
22 {[2,2], magic(2)}, | |
23 {[3,3], magic(3)}, | |
24 {[2,3], [1 2 3; 4 5 6]}, | |
25 }; | |
26 | |
27 for i = 1:length(in) | |
28 testCase.verifyEqual(reshapeRowMaj(in{i}{2}, in{i}{1}),in{i}{2}); | |
29 end | |
30 end | |
31 | |
32 function test2D(testCase) | |
33 in = { | |
34 {[2,2],[11; 12; 21; 22]}, | |
35 {[3,2],[1 2 3; 4 5 6]}, | |
36 {[6 1],[1 2 3; 4 5 6]}, | |
37 {[1 6],[1 2 3; 4 5 6]}, | |
38 }; | |
39 | |
40 out{1}(1,1) = 11; | |
41 out{1}(1,2) = 12; | |
42 out{1}(2,1) = 21; | |
43 out{1}(2,2) = 22; | |
44 | |
45 out{2} = [1 2; 3 4; 5 6]; | |
46 out{3} = [1; 2; 3; 4; 5; 6]; | |
47 out{4} = [1 2 3 4 5 6]; | |
48 | |
49 for i = 1:length(in) | |
50 testCase.verifyEqual(reshapeRowMaj(in{i}{2}, in{i}{1}),out{i}); | |
51 end | |
52 end | |
53 | |
54 function test3D(testCase) | |
55 in = { | |
56 {[2, 2, 2], [111; 112; 121; 122; 211; 212; 221; 222]}, | |
57 {[8 1], cat(3,[1 2; 3 4],[5 6; 7 8])}, | |
58 {[1 8], cat(3,[1 2; 3 4],[5 6; 7 8])}, | |
59 {[2 4], cat(3,[1 2; 3 4],[5 6; 7 8])}, | |
60 {[4 2], cat(3,[1 2; 3 4],[5 6; 7 8])}, | |
61 }; | |
62 | |
63 out{1}(1,1,1) = 111; | |
64 out{1}(1,1,2) = 112; | |
65 out{1}(1,2,1) = 121; | |
66 out{1}(1,2,2) = 122; | |
67 out{1}(2,1,1) = 211; | |
68 out{1}(2,1,2) = 212; | |
69 out{1}(2,2,1) = 221; | |
70 out{1}(2,2,2) = 222; | |
71 | |
72 out{2} = [1; 5; 2; 6; 3; 7; 4; 8]; | |
73 out{3} = [1 5 2 6 3 7 4 8]; | |
74 out{4} = [1 5 2 6; 3 7 4 8]; | |
75 out{5} = [1 5; 2 6; 3 7; 4 8]; | |
76 | |
77 for i = 1:length(in) | |
78 testCase.verifyEqual(reshapeRowMaj(in{i}{2}, in{i}{1}),out{i}); | |
79 end | |
80 end | |
81 | |
82 function testNonSquare(testCase) | |
83 in = { | |
84 {[2, 3, 4],[111; 112; 113; 114; 121; 122; 123; 124; 131; 132; 133; 134; 211; 212; 213; 214; 221; 222; 223; 224; 231; 232; 233; 234]}, | |
85 }; | |
86 out{1}(1,1,1) = 111; | |
87 out{1}(1,1,2) = 112; | |
88 out{1}(1,1,3) = 113; | |
89 out{1}(1,1,4) = 114; | |
90 out{1}(1,2,1) = 121; | |
91 out{1}(1,2,2) = 122; | |
92 out{1}(1,2,3) = 123; | |
93 out{1}(1,2,4) = 124; | |
94 out{1}(1,3,1) = 131; | |
95 out{1}(1,3,2) = 132; | |
96 out{1}(1,3,3) = 133; | |
97 out{1}(1,3,4) = 134; | |
98 out{1}(2,1,1) = 211; | |
99 out{1}(2,1,2) = 212; | |
100 out{1}(2,1,3) = 213; | |
101 out{1}(2,1,4) = 214; | |
102 out{1}(2,2,1) = 221; | |
103 out{1}(2,2,2) = 222; | |
104 out{1}(2,2,3) = 223; | |
105 out{1}(2,2,4) = 224; | |
106 out{1}(2,3,1) = 231; | |
107 out{1}(2,3,2) = 232; | |
108 out{1}(2,3,3) = 233; | |
109 out{1}(2,3,4) = 234; | |
110 for i = 1:length(in) | |
111 testCase.verifyEqual(reshapeRowMaj(in{i}{2}, in{i}{1}),out{i}); | |
112 end | |
113 end |