-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathRepmatTest.m
147 lines (126 loc) · 5.59 KB
/
RepmatTest.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
classdef RepmatTest < matlab.unittest.TestCase
properties
testCube
end
properties (TestParameter)
n = {1,2,3,10}
end
properties (ClassSetupParameter)
height = struct('row', 1, ...
'small', 3, ...
'large', 10 ...
)
width = struct('column', 1, ...
'small', 3, ...
'large', 10 ...
)
nbands = struct('single', 1, ...
'rgb', 3, ...
'multi', 5, ...
'hyper', 100 ...
);
end
methods (TestClassSetup)
function createCube(testCase, width, height, nbands)
data = gallery('uniformdata', [height, width, nbands], 1);
% Suppress default value warnings for clearer test output
warning('off', 'Cube:DefaultQuantity');
warning('off', 'Cube:DefaultWavelengthUnit');
warning('off', 'Cube:DefaultWavelength');
warning('off', 'Cube:DefaultFWHM');
testCase.testCube = Cube(data);
% Turn warnings back on
warning('on', 'all');
end
end
methods (Test)
function repmatInvalidNsError(testCase)
% Invalid replication arguments should throw an error
c = testCase.testCube;
% Only [1,3]-sized vectors should be allowed
testCase.verifyError(@()c.repmat(2), 'Cube:InvalidNs');
testCase.verifyError(@()c.repmat([2,2]), 'Cube:InvalidNs');
testCase.verifyError(@()c.repmat([2;2]), 'Cube:InvalidNs');
testCase.verifyError(@()c.repmat([2;2;2]), 'Cube:InvalidNs');
testCase.verifyError(@()c.repmat([2,2;2,2]), 'Cube:InvalidNs');
end
function repmatResultWidth(testCase, n)
% Second dimension should multiply the width
orig = testCase.testCube.Width;
c = testCase.testCube.repmat([1,n,1]);
testCase.verifyEqual(c.Width, orig * n);
end
function repmatResultHeightNBands(testCase, n)
% Multiplying second dimension should not change height or nbands
origb = testCase.testCube.nBands;
origh = testCase.testCube.Height;
c = testCase.testCube.repmat([1,n,1]);
testCase.verifyEqual(c.nBands, origb);
testCase.verifyEqual(c.Height, origh);
end
function repmatResultHeight(testCase, n)
% First dimension should multiply the height
orig = testCase.testCube.Height;
c = testCase.testCube.repmat([n,1,1]);
testCase.verifyEqual(c.Height, orig * n);
end
function repmatResultWidthNBands(testCase, n)
% Multiplying first dimension should not change width or nbands
origb = testCase.testCube.nBands;
origw = testCase.testCube.Width;
c = testCase.testCube.repmat([n,1,1]);
testCase.verifyEqual(c.nBands, origb);
testCase.verifyEqual(c.Width, origw);
end
function repmatResultNBands(testCase, n)
% Third dimension should multiply the bands
orig = testCase.testCube.nBands;
c = testCase.testCube.repmat([1,1,n]);
testCase.verifyEqual(c.nBands, orig * n);
end
function repmatResultWidthHeight(testCase, n)
% Multiplying third dimension should not change width or height
origw = testCase.testCube.Width;
origh = testCase.testCube.Height;
c = testCase.testCube.repmat([1,1,n]);
testCase.verifyEqual(c.Width, origw);
testCase.verifyEqual(c.Height, origh);
end
function repmatResultWavelength(testCase, n)
% repeating band dimension should repeat the metadata
orig = testCase.testCube.Wavelength;
c = testCase.testCube.repmat([1,1,n]);
testCase.verifyEqual(c.Wavelength, repmat(orig, [1,n]));
end
function repmatWidthWavelength(testCase, n)
% repeating second dimension should preserve the metadata
orig = testCase.testCube.Wavelength;
c = testCase.testCube.repmat([1,n,1]);
testCase.verifyEqual(c.Wavelength, orig);
end
function repmatHeightWavelength(testCase, n)
% repeating first dimension should preserve the metadata
orig = testCase.testCube.Wavelength;
c = testCase.testCube.repmat([n,1,1]);
testCase.verifyEqual(c.Wavelength, orig);
end
function repmatResultFWHM(testCase, n)
% repeating band dimension should repeat the metadata
orig = testCase.testCube.FWHM;
c = testCase.testCube.repmat([1,1,n]);
testCase.verifyEqual(c.FWHM, repmat(orig, [1,n]));
end
function repmatWidthFWHM(testCase, n)
% repeating second dimension should preserve the metadata
orig = testCase.testCube.FWHM;
c = testCase.testCube.repmat([1,n,1]);
testCase.verifyEqual(c.FWHM, orig);
end
function repmatHeightFWHM(testCase, n)
% repeating first dimension should preserve the metadata
orig = testCase.testCube.FWHM;
c = testCase.testCube.repmat([n,1,1]);
testCase.verifyEqual(c.FWHM, orig);
end
end
end