Import assignments via XML
David avatar
Written by David
Updated over a week ago

Vocareum provides automatic creation of an assignment/exercise through import of an XML file which defines the assignment including its description, parts, starter code & tests. Upon import, Vocareum will generate all necessary components of an assignment, a grading script, as specified.

The main elements in such an XML are as follows :- 

  1. Name of the assignment (required field)

  2. Description (optional)

  3. Parts (required). For each part :-

  • You must specify the programming language to be used - must be python or c/c++ (required)

  • You may specify a README which will be saved in ../resource/asnlib/public/docs (optional)

  • You must specify one or more files to be saved in ../resource/startercode (required)

  • You may specify reference implementation code which Vocareum will use to generate golden output for comparison (optional)

  • Each test can specify an input (file or command line arguments), output (if reference code not given) for comparison, rubic name and max score.

  • You may also specify a test harness (e.g. python code) to exercise student code, instead of golden output comparison.

Following is an example for a sample XML :-

<assessment name="Factorial XML">
    <parts>
        <part name="Part-1">
            <language>python2</language>
            <readme format="text">
                <![CDATA[Implement the factorial function]]>
            </readme>
            <startercode>
                <file name="factorial.py">
                    <![CDATA[              
import sys
sys.path.append(".")

def refFactorial(n):
## PUT your code here

counter = 0
for x in sys.argv[1:]:
    n = int(x)

    # expected
    exp = refFactorial(n)
    print str(exp)

exit(0)
                    ]]>
                </file>
            </startercode>
            <referencecode>
                <file name="factorial.py">
                    <![CDATA[
import sys
sys.path.append(".")

def refFactorial(n):
    if (n <= 1):
        return 1;
    return n * refFactorial(n - 1)

counter = 0
for x in sys.argv[1:]:
    n = int(x)

    # expected
    exp = refFactorial(n)
    print str(exp)

exit(0)
                    ]]>
                </file>
            </referencecode>
            <tests input="command-args">
                <test type="run" name="test1: factorial 4">
                    <input>4</input>
                    <output>24</output>
                </test>
                <test type="run submit" name="test2: factorial 10" points="5">
                    <input>10</input>
                </test>
                <test type="submit" name="test3: factorial 15">
                    <input>15</input>
                </test>
                <test type="submit">
                    <input>18</input>
                </test>
            </tests>
        </part>
    </parts>
</assessment>

  

The above XML has the following elements :-

  1. <assessment> is the starting element for the assignment and you can specify the name of the assignment

  2. <parts> is where you can specify different parts and <part> is where you specify the individual part

  3. <readme> is where you can specify the description as html or simple text

  4. <startercode><file> is where you specify the file which will be part of the students startercode

  5. Same goes for <referencecode> which is not accessible to the students but only to generate the golden output

  6. <tests> will specify the different tests to be run on the student code and you can specify whether input is command-line arguments or as a standard input (command-args or stdin)

If there are no points specified for any of the tests, Vocareum will create a default rubric element called "score" with maximum 1 point and the score will be set to 1 if all tests pass.

Did this answer your question?