Due to the use of persistent variables and the conditional statements used, this solution would fail if the test suite were modified to include two tests in a row with the same increment value.
Test | Status | Code Input and Output |
---|---|---|
1 | Pass |
assessFunctionAbsence({'regexp','regexpi','regexprep','str2num'},'FileName','counter.m')
|
2 | Pass |
f = counter(0,1);
assert(isequal(f(),0))
assert(isequal(f(),1))
assert(isequal(2,f()))
assert(isequal(3,f()))
|
3 | Pass |
f = counter(1,0);
assert(isequal(f(),1))
assert(isequal(f(),1))
assert(isequal(1,f()))
assert(isequal(1,f()))
|
4 | Pass |
f = counter(10,2);
assert(isequal(f(),10))
assert(isequal(f(),12))
assert(isequal(14,f()))
assert(isequal(16,f()))
|
5 | Pass |
f = counter(0,5);
y_correct = [0, 5, 10, 15, 20, 55];
assert(isequal([f() f() f() f() f() f()+f()],y_correct))
|
6 | Pass |
x0 = randi(10);
b = randi(10);
f = counter(x0,b);
y_correct = x0 + (0:1000)*b;
assert(isequal(arrayfun(@(n)f(),0:1000),y_correct))
|
Replace NaNs with the number that appears to its left in the row.
2018 Solvers
1882 Solvers
495 Solvers
315 Solvers
708 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!