MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

function test1(testCase)
testCase.applyFixture(FormatHexFixture);
actStr = getColumnForDisplay([1;2;3], 'Small Integers');
expStr = ['Small Integers '
'3ff0000000000000'
'4000000000000000'
'4008000000000000'];
testCase.verifyEqual(actStr, expStr)
end
end
end


function str = getColumnForDisplay(values, title)
elements = cell(numel(values)+1, 1);
elements{1} = title;
for idx = 1:numel(values)
elements{idx+1} = displayNumber(values(idx));
end
str = char(elements);
end


function str = displayNumber(n)
str = strtrim(evalc('disp(n);'));
end


This test applies the custom fixture and verifies that the displayed column of hexadecimal
representation is as expected.


At the command prompt, run the test.


run(SampleTest);


Running SampleTest
.
Done SampleTest




See Also


matlab.unittest.fixtures.Fixture


See Also
Free download pdf