Cody

# Problem 44405. Back to basics: adding comments to your code

Solution 1870455

Submitted on 10 Jul 2019
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   Fail
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×4 cell array {'% the comma should be deleted or yo…'} {'% this is the correct value with th…'} {'% this is very aggressive value and…'} {'% function end'} commentType2 = 0×0 empty cell array

Delimiting comment type missing or too short.

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

Output argument "x" (and maybe others) not assigned during call to "myFunction". Error in Test3 (line 3) assert( isequal(myFunction(A), x_correct) )

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

Output argument "x" (and maybe others) not assigned during call to "myFunction". Error in Test4 (line 3) assert( isequal(myFunction(A), x_correct) )

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

Output argument "x" (and maybe others) not assigned during call to "myFunction". Error in Test5 (line 3) assert( isequal(myFunction(A), x_correct) )

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

Output argument "x" (and maybe others) not assigned during call to "myFunction". Error in Test6 (line 3) assert( isequal(myFunction(A), x_correct) )

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

Output argument "x" (and maybe others) not assigned during call to "myFunction". Error in Test7 (line 3) assert( isequal(myFunction(A), x_correct) )

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

Output argument "x" (and maybe others) not assigned during call to "myFunction". Error in Test8 (line 3) assert( isequal(myFunction(A), x_correct) )

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

Output argument "x" (and maybe others) not assigned during call to "myFunction". Error in Test9 (line 3) assert( isequal(myFunction(A), x_correct) )

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

Output argument "x" (and maybe others) not assigned during call to "myFunction". Error in Test10 (line 3) assert( isequal(myFunction(A), x_correct) )

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

Output argument "x" (and maybe others) not assigned during call to "myFunction". Error in Test11 (line 3) assert( isequal(myFunction(A), x_correct) )

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

Output argument "x" (and maybe others) not assigned during call to "myFunction". Error in Test12 (line 3) assert( isequal(myFunction(A), x_correct) )

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

Output argument "x" (and maybe others) not assigned during call to "myFunction". Error in Test13 (line 4) assert( isequal(myFunction(A), x_correct) )

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

Output argument "x" (and maybe others) not assigned during call to "myFunction". Error in Test14 (line 4) assert( isequal(myFunction(A), x_correct) )

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

Output argument "x" (and maybe others) not assigned during call to "myFunction". Error in Test15 (line 4) assert( isequal(myFunction(A), x_correct) )

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

Output argument "x" (and maybe others) not assigned during call to "myFunction". Error in Test16 (line 4) assert( isequal(myFunction(A), x_correct) )

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

Output argument "x" (and maybe others) not assigned during call to "myFunction". Error in Test17 (line 4) assert( isequal(myFunction(A), x_correct) )

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

Output argument "x" (and maybe others) not assigned during call to "myFunction". Error in Test18 (line 4) assert( isequal(myFunction(A), x_correct) )

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

Output argument "x" (and maybe others) not assigned during call to "myFunction". Error in Test19 (line 4) assert( isequal(myFunction(A), x_correct) )

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

Output argument "x" (and maybe others) not assigned during call to "myFunction". Error in Test20 (line 4) assert( isequal(myFunction(A), x_correct) )

21   Fail
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;

Output argument "x" (and maybe others) not assigned during call to "myFunction". Error in Test21 (line 6) x_candidate = myFunction(A);