x = ones(1,1e5);
end
testCase.verifyEqual(size(x),[1 1e5])
end
function testIndexingWithVariable(testCase)
import matlab.unittest.constraints.IsSameSetAs
while(testCase.keepMeasuring)
id = 1:1e5;
x(id) = 1;
end
testCase.verifyThat(x,IsSameSetAs(1))
end
function testIndexingOnLHS(testCase)
import matlab.unittest.constraints.EveryElementOf
import matlab.unittest.constraints.IsEqualTo
while(testCase.keepMeasuring)
x(1:1e5) = 1;
end
testCase.verifyThat(EveryElementOf(x),IsEqualTo(1))
end
function testForLoop(testCase)
while(testCase.keepMeasuring)
for i=1:1e5
x(i) = 1;
end
end
testCase.verifyNumElements(x,1e5)
end
end
end
Rerun the tests. All the tests complete.
results = runperf('PreallocationTest');
Running PreallocationTest
.......... .......... .......... ..
Done PreallocationTest
__________
View the results.
33 Unit Testing