The testDefaultXLim function test verifies that the x-axis limits are large enough to
display the cylinder. The lower limit needs to be less than -10, and the upper limit needs
to be greater than 10. These values come from the figure generated in the helper function
— a cylinder with a 10 unit radius centered on the origin. This test function opens the
figure created and saved in the setupOnce function, queries the axes limit, and verifies
the limits are correct. The qualification functions, verifyLessThanOrEqual and
verifyGreaterThanOrEqual, takes the test case, the actual value, the expected value,
and optional diagnostic information to display in the case of failure as inputs.
Create the testDefaultXLim function as local function to axesPropertiesTest.
% Copyright 2015 The MathWorks, Inc.
function testDefaultXLim(testCase)
xlim = testCase.TestData.Axes.XLim;
verifyLessThanOrEqual(testCase, xlim(1), -10,...
'Minimum x-limit was not small enough')
verifyGreaterThanOrEqual(testCase, xlim(2), 10,...
'Maximum x-limit was not big enough')
end
The surfaceColorTest function accesses the figure that you created and saved in the
setupOnce function. surfaceColorTest queries the face color of the cylinder and
verifies that it is red. The color red has an RGB value of [1 0 0]. The qualification
function, verifyEqual, takes as inputs the test case, the actual value, the expected
value, and optional diagnostic information to display in the case of failure. Typically when
using verifyEqual on floating point-values, you specify a tolerance for the comparison.
For more information, see matlab.unittest.constraints.
Create the surfaceColorTest function as local function to axesPropertiesTest.
% Copyright 2015 The MathWorks, Inc.
function surfaceColorTest(testCase)
h = findobj(testCase.TestData.Axes,'Type','surface');
co = h.FaceColor;
verifyEqual(testCase, co, [1 0 0],'FaceColor is incorrect')
end
33 Unit Testing