Test | Status | Code Input and Output |
---|---|---|
1 | Pass |
% Banning these to discourage hard-coded answers and silly 'scoring cheats'. Sorry if it disrupts some legitimate usage.
% Please don't try any other hacks or workarounds.
assessFunctionAbsence({'str2num','str2double','regexp', 'regexpi'}, 'FileName','negativeRabbits.m');
FR = fileread('negativeRabbits.m');
msg = 'Don''t hard-code your ''solution''.';
assert( ~any( cellfun( @(z) contains(FR, z) , {'54800875592', '716768017756', '9845401187926'} ) ) , msg )
|
2 | Pass |
% I don't think it's very good style to be using "ans".
RE = regexp(fileread('negativeRabbits.m'), '\w+', 'match');
tabooWords = {'ans'};
testResult = cellfun( @(z) ismember(z, tabooWords), RE );
msg = ['Please do not include the following banned strings in your code!' char([10 13]) ...
strjoin(RE(testResult)) char([10 13])];
assert(~any( cellfun( @(z) ismember(z, tabooWords), RE ) ), msg)
|
3 | Pass |
% This is important.
assert( isequal( class(negativeRabbits(0)) , 'int64' ) , 'Wrong data type.')
|
4 | Pass |
% Test Suite shall ensure it only ever checks n < 3.
assert( isequal(negativeRabbits(+2), 1) , 'Failed at n =+2.' )
assert( isequal(negativeRabbits(+1), 1) , 'Failed at n =+1.' )
assert( isequal(negativeRabbits( 0), 0) , 'Failed at n = 0.' )
assert( isequal(negativeRabbits(-1), 1) , 'Failed at n =-1.' )
|
5 | Pass |
for n = 0 : -1 : -10
assert( isequal(negativeRabbits(n)+negativeRabbits(n+1), negativeRabbits(n+2)) , ['Failed at n =' num2str(n) '.'])
end;
|
6 | Pass |
for n = -10 : -1 : -20
assert( isequal(negativeRabbits(n)+negativeRabbits(n+1), negativeRabbits(n+2)) , ['Failed at n =' num2str(n) '.'])
end;
|
7 | Pass |
for n = -20 : -1 : -40
assert( isequal(negativeRabbits(n)+negativeRabbits(n+1), negativeRabbits(n+2)) , ['Failed at n =' num2str(n) '.'])
end;
|
8 | Pass |
for n = -40 : -1 : -77
assert( isequal(negativeRabbits(n)+negativeRabbits(n+1), negativeRabbits(n+2)) , ['Failed at n =' num2str(n) '.'])
end;
|
9 | Pass |
% This is difficult, but feasible within the parameters of the problem.
for n = -77 : -1 : -92
assert( isequal(negativeRabbits(n)+negativeRabbits(n+1), negativeRabbits(n+2)) , ['Failed at n =' num2str(n) '.'])
end;
|
2240 Solvers
819 Solvers
Matrix indexing with two vectors of indices
485 Solvers
154 Solvers
583 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!