-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathConstructorTest.m
139 lines (119 loc) · 5.54 KB
/
ConstructorTest.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
classdef ConstructorTest < matlab.unittest.TestCase
% ConstructorTest tests the Cube constructor api and resulting object
% properties.
properties
% expected default values for missing parameters for the cube
defaultQuantity = 'Unknown';
defaultWavelengthUnit = 'Band index';
defaultUnknownUnit = 'Unknown';
% constant test data cube and corresponding metadata
data = gallery('uniformdata', [2,3,4], 1);
wl = gallery('uniformdata', [1,4], 1);
end
properties (TestParameter)
type = {'double', ...
'single', ...
'int8', 'uint8',...
'int16', 'uint16',...
'int32', 'uint32',...
'int64', 'uint64'...
};
% Size parameters
width = struct('column', 1, ...
'small', 2, ...
'large', 10 ...
);
height = struct('row', 1, ...
'small', 2, ...
'large', 10 ...
);
bands = struct('image', 1, ...
'rgb', 3, ...
'hsi', 100 ...
);
bands2 = struct('image', 1, ...
'rgb', 3, ...
'hsi', 50 ...
);
% Test metadata
qty = {'A', 'Quantity'};
wlu = {'nm', 'Wavelength unit'};
end
methods (Test)
function testNullConstructor(testCase)
% (only) the null constructor should result in empty properties
nullCube = Cube();
testCase.verifyEmpty(nullCube.Data);
testCase.verifyEmpty(nullCube.Bands);
testCase.verifyEmpty(nullCube.Wavelength);
testCase.verifyEmpty(nullCube.FWHM);
end
function testDataIdentity(testCase, width, height, bands, type)
% Cube should retain the data as is
cube = ones(height, width, bands, type);
c = Cube(cube);
testCase.verifyClass(c.Data, type);
testCase.verifyEqual(c.Type, type);
end
function testMetaSize(testCase, width, height, bands)
% Wavelength, FWHM sizes should match the data and nBands prop.
cube = ones(height, width, bands);
c = Cube(cube);
testCase.verifyLength(c.Wavelength, bands);
testCase.verifyLength(c.FWHM, bands);
testCase.verifyEqual(c.nBands, bands);
end
function testWavelengthMismatch(testCase, width, height, bands, bands2)
% Mismatched wavelength vector size should result in error
testCase.assumeNotEqual(bands, bands2);
cube = ones(height, width, bands);
wls = 1:bands2;
testCase.verifyError(@() Cube(cube, 'wl', wls), 'Cube:IncorrectWavelength');
end
function testFWHMMismatch(testCase, width, height, bands, bands2)
% Mismatched fwhm vector size should result in error
testCase.assumeNotEqual(bands, bands2);
cube = ones(height, width, bands);
fwhms = 1:bands2;
testCase.verifyError(@() Cube(cube, 'fwhm', fwhms), 'Cube:IncorrectFWHM');
end
function testDefaultQuantity(testCase)
c = testCase.verifyWarning(@()Cube(testCase.data), 'Cube:DefaultQuantity');
testCase.verifyEqual(c.Quantity, testCase.defaultQuantity);
end
function testDefaultWavelengthUnit(testCase)
c = testCase.verifyWarning(@()Cube(testCase.data), 'Cube:DefaultWavelengthUnit');
testCase.verifyEqual(c.WavelengthUnit, testCase.defaultWavelengthUnit);
end
function testDefaultWavelength(testCase, width, height, bands)
% Default wavelength vector should be [1, 2, ... , bands]
cube = ones(height, width, bands);
c = testCase.verifyWarning(@()Cube(cube), 'Cube:DefaultWavelength');
testCase.verifyEqual(c.Wavelength, 1:bands);
end
function testUnknownWavelengthUnit(testCase)
% If wavelengths are supplied without the unit, it is set to
% testCase.defaultUnknownUnit with a warning
c = testCase.verifyWarning(@()Cube(testCase.data, 'wl', testCase.wl), 'Cube:UnknownWavelengthUnit');
testCase.verifyEqual(c.WavelengthUnit, testCase.defaultUnknownUnit);
end
function testDefaultFWHM(testCase, width, height, bands)
% Default FWHM vector should be zeros(1, bands)
cube = ones(height, width, bands);
c = testCase.verifyWarning(@()Cube(cube), 'Cube:DefaultFWHM');
testCase.verifyEqual(c.FWHM, zeros(1,bands));
end
function testUpdateConstructor_Quantity(testCase)
c1 = Cube(testCase.data, 'quantity', 'OldQuantity');
c2 = Cube(c1, 'quantity', 'NewQuantity');
testCase.verifyEqual(c1.Quantity, 'OldQuantity');
testCase.verifyEqual(c2.Quantity, 'NewQuantity');
end
function testUpdateConstructor_WavelengthUnit(testCase)
c1 = Cube(testCase.data, 'wlunit', 'OldWavelengthUnit');
c2 = Cube(c1, 'wlunit', 'NewWavelengthUnit');
testCase.verifyEqual(c1.WavelengthUnit, 'OldWavelengthUnit');
testCase.verifyEqual(c2.WavelengthUnit, 'NewWavelengthUnit');
end
end
end