Cody

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

Created by David Verrelli in Community

In this task you need to imagine that you — yes, YOU — have developed a problem on Cody for me to solve, and now you need to implement a robust Test Suite to check whether my submitted solutions meet your requirements or not, and to be fairly assured that I am not trying to 'game' the system.

So the tables are turned! You are now in the role of Tester! I am in the role of Player!

The problem you've set me is to:

  • output the sine of an angle, when the angle is specified in degrees as a (scalar) double, with no restriction in the domain,
  • without using regexp or regexpi or ans,
  • within less than 0.01 seconds (10 milliseconds).

You provide me with the following example for the function defined as s = SINE(a):

 % INPUT
 a = 45 % degrees
 % OUTPUT
 s = 1/sqrt(2)

Now I have responded by submitting a large number of purported 'solutions', some of which are reasonably accurate, and others which are either too imprecise or else logically flawed.

Your Test Suite (contained within your function testSuite) must address each of the elements of your problem specification:

  1. Check that my submitted code reliably returns sufficiently accurate values for sine of many different angles. Use the assert function.
  2. Ensure that the returned data type is suitable.
  3. You cannot use (or mention) the functions sind, sin, cscd or cosd in your Test Suite; any other functions are allowed. [ MOTIVATION: You shouldn't be exposing an efficient way of solving the problem within your Test Suite, otherwise I can just copy and paste your solution and submit it as my own! ]
  4. You must check that I haven't used "regexp" or "regexpi" or "ans". You could try using the assessFunctionAbsence function in the form assessFunctionAbsence(..., 'FileName','SINE.m'), or else you could try 'manually' opening the file SINE.m that corresponds to my submitted solution and then parsing it for occurrence of the prohibited function/variable.
  5. You must check that my code returns a result within less than 0.01 seconds (for a single input of an arbitrary angle). You could use tic & toc or timeit, or a variety of other MATLAB functions (but not cputime in this case). If your Test Suite claims that my submission runs slowly, then you must be confident that it is truly caused only by inefficiency in my submitted code, not just general/erratic overheads in 'queuing' or suchlike on the Cody servers.
  6. Your assert (or other) function must throw errors/exceptions with the following error message text contents.
  • 'Incorrect value' if the output is too inaccurate.
  • 'Incorrect data type' if the output is not appropriate.
  • 'Too slow' if my submitted code is too slow.
  • 'Banned word' if my submitted code contains the regexp or regexpi functions or the ans variable. For this infringement, additional text can also (optionally!) be present in the message — for example, 'You cannot do that! Banned word (regexp/regexpi)' would also be acceptable.

When creating a Test Suite for a Cody problem it is a good habit to try to anticipate the tactics that diverse Players might employ!

See also:

Solution Stats

40.0% Correct | 60.0% Incorrect
Last solution submitted on Feb 05, 2019

Problem Comments