In the following we will show how to create an exercise and set it up in CodeJudge. We will use Python as language, but it can easily be substituted by another language (see How to create test data for my language?). In this guide, we will go through the following steps:
Please note that this is a quick start guide, and CodeJudge supports many more features for testing than described here. But this guide will take you through the most common features.
First we should figure out what the exercise should be about. In this guide we will use the following problem:
Create a Python program that have the functions sum(a, b) that should return the sum of the numbers a and b. Furthermore it should have the function factorial(a) that must return 1 * 2 * ... * a = a! (should work for a >= 0).
Next, we'll create a solution to the problem, let us call it solution.py. The solution will serve multiple purposes:
def sum(a, b):
return a + b
def factorial(a):
if a <= 1:
return 1
return factorial(a - 1) * a
Let us prepare some test cases, we want to to test submissions on. Each line represent an individual test.
print(sum(3, 6))
print(sum(-5, -9))
print(sum(33, 64))
print(factorial(5))
print(factorial(10))
print(factorial(2))
print(factorial(1))
print(factorial(0))
You might now be thinking that we also need to prepare what the answer/expected output of our test cases are. However, in this example we will let CodeJudge produce the expected output by uploading just the "input" of the test cases and the solution. (It is possible to manually specify the expected output instead - see the documentation for this)
Test cases can be much more complex than this example; they may involve input from the console, command line arguments, files, multiple correct outputs, etc. For more about this, see the documentation.
It is now time to setup the exercise on CodeJudge, so we will navigate to our course on CodeJudge. Before setting up the exercise, we have to create an exercise group. Normally one will create an exercise group per week/exercise class/similar. Follow these steps:
We are now ready to setup the actual exercise.
Finally create the tests. This will automatically generate the expected output as well. An exercise can consist of multiple test groups, but simple exercises only need one. See the documentation for more information:
After a short while of generating answer files, the exercise is ready!
As a final step, it is a good idea to see if the exercise actually works as expected (especially when it is the first time you create one). Navigate to the "View"-tab of the exercise and try to upload your solution. If you have not tried CodeJudge before, it is also a good idea to experiment with the different kind of mistakes students might make (compiler errors, programs producing exceptions, wrong output, etc).
If you are going to manage many exercises, it might be tedius to use the web interface for this. Instead we support file-based exercise management. See the guide How to set up a file-based exercise to learn how to do this.