MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

end


methods (Test)
function testRemainPixels(testCase, level)
% expected number pixels equal to 1
expPixelCount = 8^level;
% actual number pixels equal to 1
actPixels = find(sierpinski(level));
testCase.verifyNumElements(actPixels,expPixelCount)
end


function testClass(testCase, type, level)
testCase.verifyClass(...
sierpinski(level,type), type)
end


function testDefaultL1Output(testCase)
exp = single([1 1 1; 1 0 1; 1 1 1]);
testCase.verifyEqual(sierpinski(1), exp)
end
end


methods (Test, ParameterCombination='sequential')
function testNumel(testCase, level, side)
import matlab.unittest.constraints.HasElementCount
testCase.verifyThat(sierpinski(level),...
HasElementCount(side^2))
end
end
end


Run All Tests


At the command prompt, create a suite from TestCarpet.m.


suite = matlab.unittest.TestSuite.fromFile('TestCarpet.m');
{suite.Name}'


ans =


'TestCarpet/testNumel(level=small,side=small)'
'TestCarpet/testNumel(level=medium,side=medium)'
'TestCarpet/testNumel(level=large,side=large)'
'TestCarpet/testRemainPixels(level=small)'
'TestCarpet/testRemainPixels(level=medium)'


Create Basic Parameterized Test
Free download pdf