Cody

Problem 44521. Make your own Test Suite (part 3)

Solution 1580137

Submitted on 10 Jul 2018 by Tom Holz
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
fileID = fopen('SINE.m','w'); fprintf(fileID,'function s = SINE(angle)\n'); fprintf(fileID,' s = sind(angle);\n'); fprintf(fileID,' pause(0.012);\n'); fclose(fileID); status_correct = 'fail'; status = 'pass'; try testSuite() catch e status = 'fail' assert( isequal(e.message, 'Too slow') , 'Wrong message' ) end assert( isequal(status, status_correct) , 'Wrong status' )

status = 'fail'

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

status = 'fail' ans = 'Banned word'

3   Pass
fileID = fopen('SINE.m','w'); fprintf(fileID,'function s = SINE(angle)\n'); fprintf(fileID,' % This is a simple problem: the answer only takes one line!\n'); fprintf(fileID,' s = sind(angle);\n'); fclose(fileID); status_correct = 'pass'; status = 'pass'; try testSuite() catch e status = 'fail' end assert( isequal(status, status_correct) , 'Wrong status' )

ans = []

4   Pass
fileID = fopen('SINE.m','w'); fprintf(fileID,'function s = SINE(angle)\n'); fprintf(fileID,' s = sind(angle);\n'); fprintf(fileID,' dummy = regexp(''Test text'', ''t'');\n'); fclose(fileID); status_correct = 'fail'; status = 'pass'; try testSuite() catch e status = 'fail' e.message assert( contains(e.message, 'Banned word') , 'Wrong message' ) end assert( isequal(status, status_correct) , 'Wrong status' )

status = 'fail' ans = 'Banned word'

5   Pass
fileID = fopen('SINE.m','w'); fprintf(fileID,'function s = SINE(angle)\n'); fprintf(fileID,' s = sind(angle);\n'); fprintf(fileID,' dummy = regexpi(''Test text'', ''t'');\n'); fclose(fileID); status_correct = 'fail'; status = 'pass'; try testSuite() catch e status = 'fail' e.message assert( contains(e.message, 'Banned word') , 'Wrong message' ) end assert( isequal(status, status_correct) , 'Wrong status' )

status = 'fail' ans = 'Banned word'

6   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')

7   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 = [] ans = []

8   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 = []

9   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 = []

10   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 = []

11   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'

12   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'

13   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'

14   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'

15   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'

16   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'

17   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'

18   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'

19   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'

20   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'

21   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'

22   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'

23   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'

24   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'

25   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'

26   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!