Cody

Solution 1349348

Submitted on 19 Nov 2017 by yurenchu
  • Size: 48
  • This is the leading solution.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
assessFunctionAbsence({'rng', ... By the way, with an ellipsis (signalling line continuation) '!', 'assert', ... all subsequent material on that line is ignored. But syntactically they 'evalin', 'assignin', ... are _not_ comments (even if they are "effectively" similar). 'system', 'dos', ... E.g. they would not be treated as comments by an autodoc (automatic documentation) tool. 'unix'}, 'FileName', 'myFunction.m') assert( isempty( regexp(fileread('myFunction.m'),'(?# By the way, comments can also be inserted in regexp "regular expression" arguments.)assert','match') ) , 'No "assert" allowed in your code!')

2   Pass
commentType1 = regexp(fileread('myFunction.m'),'(?<![\f\n\r][^'']*''[^''\f\n\r]*)(?<!\o45)\o45[^\o45][^\f\n\r]{10,}','match'); commentType1(end) = [] assert( ~isempty( commentType1 ) , 'Basic comment type missing or too short.') commentType2 = regexp(fileread('myFunction.m'),'\o45\o45[^\f\n\r]{10,}','match') assert( ~isempty( commentType2 ) , 'Delimiting comment type missing or too short.') commentType3open = regexp(fileread('myFunction.m'),'(^|[\f\n\r]*)\x{20}*\o45\o173\x{20}*[\f\n\r]') commentType3close = regexp(fileread('myFunction.m'),'(^|[\f\n\r]*)\x{20}*\o45\o175\x{20}*[\f\n\r]') if isempty(commentType3open) || isempty(commentType3open) assert(false, 'Block comment type missing.') else assert( length(commentType3close) == length(commentType3open) , 'Block comment tokens unbalanced.') assert( max(commentType3close - commentType3open) > 20 , 'Block comment type too short.') end;

commentType1 = 1×2 cell array {'% y = (A.^2 + 1.5).^(1/3);'} {'% This line results in a score that's 1 point lower than with the line above.'} commentType2 = 1×2 cell array {'%% Step 1: Calculate precise answer, y:'} {'%% Step 2: Round y until desired accuracy is reached:'} commentType3open = 27 commentType3close = 259

3   Pass
A = 1; x_correct = 1.3572; assert( isequal(myFunction(A), x_correct) )

4   Pass
A = 2; x_correct = 1.7652; assert( isequal(myFunction(A), x_correct) )

5   Pass
A = 3; x_correct = 2.1898; assert( isequal(myFunction(A), x_correct) )

6   Pass
A = 4; x_correct = 2.59625; assert( isequal(myFunction(A), x_correct) )

7   Pass
A = 5; x_correct = 2.9814; assert( isequal(myFunction(A), x_correct) )

8   Pass
A = 6; x_correct = 3.3472; assert( isequal(myFunction(A), x_correct) )

9   Pass
A = 7; x_correct = 3.6963; assert( isequal(myFunction(A), x_correct) )

10   Pass
A = 8; x_correct = 4.031; assert( isequal(myFunction(A), x_correct) )

11   Pass
A = 9; x_correct = 4.3533; assert( isequal(myFunction(A), x_correct) )

12   Pass
A = 10; x_correct = 4.6647; assert( isequal(myFunction(A), x_correct) )

13   Pass
% Test added 2019-06-24 A = 481; x_correct = 61.39; assert( isequal(myFunction(A), x_correct) )

14   Pass
% Test added 2019-06-24 A = 922; x_correct = 94.73; assert( isequal(myFunction(A), x_correct) )

15   Pass
% Test added 2019-06-24 A = 3981; x_correct = 251.185635; assert( isequal(myFunction(A), x_correct) )

16   Pass
% Test added 2019-06-24 A = 3988; x_correct = 251.48; assert( isequal(myFunction(A), x_correct) )

17   Pass
% Test added 2019-06-24 A = 3989; x_correct = 251.522035; assert( isequal(myFunction(A), x_correct) )

18   Pass
% Test added 2019-06-24 A = 7997; x_correct = 399.9; assert( isequal(myFunction(A), x_correct) )

19   Pass
% Test added 2019-06-24 A = 8000; x_correct = 400; assert( isequal(myFunction(A), x_correct) )

20   Pass
% Test added 2019-06-24 A = 8003; x_correct = 400.1; assert( isequal(myFunction(A), x_correct) )

21   Pass
threshold = 0.0001; for j = 1 : 10 A = randi(10) + rand(); x_candidate = myFunction(A); A_approx = exp( log(x_candidate * x_candidate * x_candidate - (1 + 1/2)) / 2); assert( abs(A - A_approx) <= threshold ) x_rough = round(x_candidate, 6); if abs(x_rough - x_candidate) > 10*eps(x_candidate) A_rough = exp( log(x_rough * x_rough * x_rough - (1 + 1/2)) / 2); assert( abs(A - A_rough) > threshold ) end; x_rough = round(x_candidate, 5); if abs(x_rough - x_candidate) > 10*eps(x_candidate) A_rough = exp( log(x_rough * x_rough * x_rough - (1 + 1/2)) / 2); assert( abs(A - A_rough) > threshold ) end; x_rough = round(x_candidate, 4); if abs(x_rough - x_candidate) > 10*eps(x_candidate) A_rough = exp( log(x_rough * x_rough * x_rough - (1 + 1/2)) / 2); assert( abs(A - A_rough) > threshold ) end; x_rough = round(x_candidate, 3); if abs(x_rough - x_candidate) > 10*eps(x_candidate) A_rough = exp( log(x_rough * x_rough * x_rough - (1 + 1/2)) / 2); assert( abs(A - A_rough) > threshold ) end; x_rough = round(x_candidate, 2); if abs(x_rough - x_candidate) > 10*eps(x_candidate) A_rough = exp( log(x_rough * x_rough * x_rough - (1 + 1/2)) / 2); assert( abs(A - A_rough) > threshold ) end; x_rough = round(x_candidate, 1); if abs(x_rough - x_candidate) > 10*eps(x_candidate) A_rough = exp( log(x_rough * x_rough * x_rough - (1 + 1/2)) / 2); assert( abs(A - A_rough) > threshold ) end; end;