Cody

Problem 44616. Make your own Test Suite (part 2)

Solution 3231543

Submitted on 16 Oct 2020 by Rafael S.T. Vieira
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
% NOTE: You may notice that the user function has been named "SINE", % in uppercase. That is an extra precaution to avoid accidentally % triggering an error due to a banned 'word' (sequence of characters). % Careful choice of code to check for banned _functions_ is better! assessFunctionAbsence('sind', 'FileName','testSuite.m') assessFunctionAbsence('sin', 'FileName','testSuite.m') assessFunctionAbsence('cscd', 'FileName','testSuite.m') assessFunctionAbsence('cosd', 'FileName','testSuite.m')

2   Pass
fileID = fopen('SINE.m','w'); fprintf(fileID,'function s = SINE(angle)\n'); fprintf(fileID,' s = sind(angle);\n'); fclose(fileID); status_correct = 'pass'; status = 'pass'; testSuite() try testSuite() catch e status = 'fail' end assert( isequal(status, status_correct) , 'Wrong status' )

ans = logical 1 ans = logical 1

3   Pass
fileID = fopen('SINE.m','w'); fprintf(fileID,'function s = SINE(angle)\n'); fprintf(fileID,' s = sind(angle + eps(angle));\n'); fclose(fileID); status_correct = 'pass'; status = 'pass'; try testSuite() catch e status = 'fail' end assert( isequal(status, status_correct) , 'Wrong status' )

ans = logical 1

4   Pass
fileID = fopen('SINE.m','w'); fprintf(fileID,'function s = SINE(angle)\n'); fprintf(fileID,' s = sin(angle * pi / 180);\n'); fclose(fileID); status_correct = 'pass'; status = 'pass'; try testSuite() catch e status = 'fail' end assert( isequal(status, status_correct) , 'Wrong status' )

ans = logical 1

5   Pass
fileID = fopen('SINE.m','w'); fprintf(fileID,'function s = SINE(angle)\n'); fprintf(fileID,' s = 1 ./ cscd(angle);\n'); fclose(fileID); status_correct = 'pass'; status = 'pass'; try testSuite() catch e status = 'fail' end assert( isequal(status, status_correct) , 'Wrong status' )

ans = logical 1

6   Pass
fileID = fopen('SINE.m','w'); fprintf(fileID,'function s = SINE(angle)\n'); fprintf(fileID,' s = sin(angle * 3.14 / 180);\n'); fclose(fileID); status_correct = 'fail'; status = 'pass'; try testSuite() catch e status = 'fail' assert( isequal(e.message, 'Incorrect value') , 'Wrong message' ) end assert( isequal(status, status_correct) , 'Wrong status' )

status = 'fail'

7   Pass
fileID = fopen('SINE.m','w'); fprintf(fileID,'function s = SINE(angle)\n'); fprintf(fileID,' s = sin(angle * (22/7) / 180);\n'); fclose(fileID); status_correct = 'fail'; status = 'pass'; try testSuite() catch e status = 'fail' assert( isequal(e.message, 'Incorrect value') , 'Wrong message' ) end assert( isequal(status, status_correct) , 'Wrong status' )

status = 'fail'

8   Pass
fileID = fopen('SINE.m','w'); fprintf(fileID,'function s = SINE(angle)\n'); fprintf(fileID,' s = sind(angle + 10000*eps(angle));\n'); fclose(fileID); status_correct = 'fail'; status = 'pass'; try testSuite() catch e status = 'fail' assert( isequal(e.message, 'Incorrect value') , 'Wrong message' ) end assert( isequal(status, status_correct) , 'Wrong status' )

status = 'fail'

9   Pass
fileID = fopen('SINE.m','w'); fprintf(fileID,'function s = SINE(angle)\n'); fprintf(fileID,' s = cosd(angle);\n'); fclose(fileID); status_correct = 'fail'; status = 'pass'; try testSuite() catch e status = 'fail' assert( isequal(e.message, 'Incorrect value') , 'Wrong message' ) end assert( isequal(status, status_correct) , 'Wrong status' )

status = 'fail'

10   Pass
fileID = fopen('SINE.m','w'); fprintf(fileID,'function s = SINE(angle)\n'); fprintf(fileID,' s = sind(angle*sign(angle));\n'); fclose(fileID); status_correct = 'fail'; status = 'pass'; try testSuite() catch e status = 'fail' assert( isequal(e.message, 'Incorrect value') , 'Wrong message' ) end assert( isequal(status, status_correct) , 'Wrong status' )

status = 'fail'

11   Pass
fileID = fopen('SINE.m','w'); fprintf(fileID,'function s = SINE(angle)\n'); fprintf(fileID,' s = -sind(angle*sign(angle));\n'); fclose(fileID); status_correct = 'fail'; status = 'pass'; try testSuite() catch e status = 'fail' assert( isequal(e.message, 'Incorrect value') , 'Wrong message' ) end assert( isequal(status, status_correct) , 'Wrong status' )

status = 'fail'

12   Pass
fileID = fopen('SINE.m','w'); fprintf(fileID,'function s = SINE(angle)\n'); fprintf(fileID,' s = sind(angle)*sign(sind(angle));\n'); fclose(fileID); status_correct = 'fail'; status = 'pass'; try testSuite() catch e status = 'fail' assert( isequal(e.message, 'Incorrect value') , 'Wrong message' ) end assert( isequal(status, status_correct) , 'Wrong status' )

status = 'fail'

13   Pass
fileID = fopen('SINE.m','w'); fprintf(fileID,'function s = SINE(angle)\n'); fprintf(fileID,' s = sind(fix(angle));\n'); fclose(fileID); status_correct = 'fail'; status = 'pass'; try testSuite() catch e status = 'fail' assert( isequal(e.message, 'Incorrect value') , 'Wrong message' ) end assert( isequal(status, status_correct) , 'Wrong status' )

status = 'fail'

14   Pass
fileID = fopen('SINE.m','w'); fprintf(fileID,'function s = SINE(angle)\n'); fprintf(fileID,' inc=0;\n'); fprintf(fileID,' if mod(angle,1)==0, inc=1; end;\n'); fprintf(fileID,' s = sind(angle + inc);\n'); fclose(fileID); status_correct = 'fail'; status = 'pass'; try testSuite() catch e status = 'fail' assert( isequal(e.message, 'Incorrect value') , 'Wrong message' ) end assert( isequal(status, status_correct) , 'Wrong status' )

status = 'fail'

15   Pass
fileID = fopen('SINE.m','w'); fprintf(fileID,'function s = SINE(angle)\n'); if rand() < 0.5, fprintf(fileID,' s = int8(sind(angle));\n'); else fprintf(fileID,' s = int16(sind(angle));\n'); end; fclose(fileID); status_correct = 'fail'; status = 'pass'; try testSuite() catch e status = 'fail' assert( isequal(e.message, 'Incorrect value') | ... isequal(e.message, 'Incorrect data type') , 'Wrong message' ) end assert( isequal(status, status_correct) , 'Wrong status' )

status = 'fail'

16   Pass
fileID = fopen('SINE.m','w'); fprintf(fileID,'function s = SINE(angle)\n'); if rand() < 0.5, fprintf(fileID,' s = int32(sind(angle));\n'); else fprintf(fileID,' s = int64(sind(angle));\n'); end; fclose(fileID); status_correct = 'fail'; status = 'pass'; try testSuite() catch e status = 'fail' assert( isequal(e.message, 'Incorrect value') | ... isequal(e.message, 'Incorrect data type') , 'Wrong message' ) end assert( isequal(status, status_correct) , 'Wrong status' )

status = 'fail'

17   Pass
fileID = fopen('SINE.m','w'); fprintf(fileID,'function s = SINE(angle)\n'); fprintf(fileID,' s = sind(double(int32(angle)));\n'); fclose(fileID); status_correct = 'fail'; status = 'pass'; try testSuite() catch e status = 'fail' assert( isequal(e.message, 'Incorrect value') , 'Wrong message' ) end assert( isequal(status, status_correct) , 'Wrong status' )

status = 'fail'

18   Pass
fileID = fopen('SINE.m','w'); fprintf(fileID,'function s = SINE(angle)\n'); fprintf(fileID,' s = "ratio";\n'); fclose(fileID); status_correct = 'fail'; status = 'pass'; try testSuite() catch e status = 'fail' assert( isequal(e.message, 'Incorrect data type') , 'Wrong message' ) end assert( isequal(status, status_correct) , 'Wrong status' )

status = 'fail'

19   Pass
fileID = fopen('SINE.m','w'); fprintf(fileID,'function s = SINE(angle)\n'); fprintf(fileID,' s = "?";\n'); fclose(fileID); status_correct = 'fail'; status = 'pass'; try testSuite() catch e status = 'fail' assert( isequal(e.message, 'Incorrect data type') , 'Wrong message' ) end assert( isequal(status, status_correct) , 'Wrong status' )

status = 'fail'

20   Pass
fileID = fopen('SINE.m','w'); fprintf(fileID,'function s = SINE(angle)\n'); fprintf(fileID,' s = {1:1E4};\n'); fclose(fileID); status_correct = 'fail'; status = 'pass'; try testSuite() catch e status = 'fail' assert( isequal(e.message, 'Incorrect data type') , 'Wrong message' ) end assert( isequal(status, status_correct) , 'Wrong status' )

status = 'fail'

21   Pass
fileID = fopen('SINE.m','w'); fprintf(fileID,'function s = SINE(angle)\n'); fprintf(fileID,' s = {sind(angle)};\n'); fclose(fileID); status_correct = 'fail'; status = 'pass'; try testSuite() catch e status = 'fail' assert( isequal(e.message, 'Incorrect data type') , 'Wrong message' ) end assert( isequal(status, status_correct) , 'Wrong status' )

status = 'fail'

Suggested Problems

More from this Author31

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!