CreateExercise - cloudcoderdotorg/CloudCoder GitHub Wiki

To create an exercise, select a course and press the Problems button (in the top left of the screen.) On the problems page, click the New button to create a new exercise.

You can edit an existing exercise by going to the problems page, selecting an exercise in the list, and clicking the Edit button.

Important: Periodically, you should use the Save problem! button to save your work.

Suggestion: import an exercise from the exercise repository to see how it is written. These exercises should serve as a useful reference for writing new exercises.

Exercise fields

Problem Type - this selects the programming langauge and how the test cases will be judged:

  • JAVA_METHOD - Write or complete a Java method. Test cases are judged by passing values to the method and comparing the method's return value against an expected value using the equals method.
  • PYTHON_FUNCTION - Write or complete a Python function. Test cases are judged by passing values to the function and comparing the function's return value against an expected value.
  • C_FUNCTION - Write or complete a C/C++ function. Test cases are judged by passing values to the function and comparing the method's return value against an expected value using the == operator.
  • C_PROGRAM - Write or complete a program (which must include a main function.) Test cases are judged by sending input text to the program as its standard input, and matching each line of program output against a regular expression. If the regular expression matches any of the lines, the test passes.
  • JAVA_PROGRAM - Write or complete Java program, meaning a top-level class with a main method. Test cases are judged by by sending input text to the program as its standard input, and matching each line of program output against a regular expression. If the regular expression matches any of the lines, the test passes.
  • RUBY_METHOD - Write or complete a Ruby method. Test cases are judged by passing values to the function and comparing the function's return value against an expected value using the == operator.

Problem name - the (brief) name of the exercise. Important: for the problem types in which the student writes a method or function (such as JAVA_METHOD, PYTHON_FUNCTION, C_FUNCTION, and RUBY_FUNCTION) the problem name must be the name of the method/function. For the other problem types, it is free form.

Full description - HTML describing the problem.

Skeleton code - The code that is provided to the student as a starting point. For example, in a JAVA_METHOD exercise you could define the method with an empty body for the student to complete.

Author name, Author email, Author website - Information identifying the author of the exercise. These should be filled in automatically based on your user account information.

Creation date - When the exercise was created. Will be initialized automatically to the current date.

License - The terms under which the exercise may be redistributed. If you choose NOT_REDISTRIBUTABLE, the exercise may not be redistributed. If you choose any other value, it allows the exercise to be uploaded to the CloudCoder exercise repository so that it can be used by other CloudCoder users.

When assigned, When due - the dates/times when an exercise is assigned (when students are expected to start working on it) and when it is due.

Problem visible to students - if checked, the exercise will be immediately visible to students. You will want to leave this unchecked at first, since some testing and re-editing is typically required before an exercise is ready to give to students.

Test cases

Every exercise should have at least one test case. To add a test case, click the Add test case button. (You may need to scroll down to see this button.)

Writing good test cases is generally the most challenging part of creating an exercise. The test cases should test typical inputs and unusual inputs. If at all possible, it is nice to include test cases that award partial credit to a partially working submission (although this is hard to do).

There are several fields to edit for each test case.

Test case name - a name for the test case. You may wish to use this as description of what the test case is testing.

Test input - the input for the test case. For C_PROGRAM and JAVA_PROGRAM exercises, this is text that will be sent to the program's standard input. For the other exercise types, this should be a list of literal arguments. For example, to test a C_FUNCTION submission that takes two integer arguments, you might specify the test input as

2, 3

to pass the integer values 2 and 3.

Test output - the expected output of the test case. For C_PROGRAM and JAVA_PROGRAM exercises, this should be a regular expression that is matched against lines of output from the submission. For example, if the expected line of program output is

Answer is: 42

then your regular expression might be

^.*Answer\s+is\s*:\s*42\s*$i

There are a few things to be aware of when writing regular expressions:

  • The output of an input prompt may appear on the line containing the program output you want to check, hence the ^.* at the beginning of the regular expression.
  • You may want to allow variations in whitespace, so use \s* for optional whitespace and \s+ for mandatory whitespace. Using \s* for trailing whitespace is also a good idea.
  • If the regular expression ends in $i, then matching will be case-insensitive. (Note that the $ is an end-of-line anchor.)
  • If the regular expression ends in $j, multi-line output will be joined into a single line; each line will be separated by a single space. For example, if the output of the program is
HELLO
GOODBYE

The output will be joined into HELLO GOODBYE (notice that there is a space after GOODBYE). To match this output, you can use the regular expression ^HELLO GOODBYE $j (make sure to leave a space between GOODBYE and $j).

The regular expression syntax supported is the one supported by the java.util.regex.Pattern class.

For the other types of exercises (such as JAVA_METHOD, PYTHON_FUNCTION, etc.) the test output is a literal value against which the return value of the submitted method/function will be checked for equality. Note that for JAVA_METHOD submissions, both the expected test output and the method return value are typecast to Object, then the equals method is used for the comparison.

Secret - If this is checked, the test case is a "secret" test, in which the test input, expected test output, and the program's output are not revealed to students. Note that the existence of the test case and the name of the test case are revealed. Using secret tests may be useful for exercises given as quizzes, since they avoid revealing information that students could use to "game" the quiz (by making the submission a series of if/else tests checking specific inputs and producing specific outputs without any actual computation.)