CodeGrade Help
Go to websiteAPI docsContact us
  • 🏠CodeGrade Help Center
  • ❓FAQ
    • Using CodeGrade in Safari
    • Using sections
    • Configuring roles of members
    • Archiving your course
    • Adding new members
    • Releasing grades and feedback
    • Exporting Submissions
    • Choosing a grading scale
    • Creating course-wide snippets
    • Course Gradebook
    • Allowing students to hand in after the deadline
  • Use built-in content
    • 👥Community Library
    • 🐍Introduction to Python Curriculum
  • Create your own assignments
    • 1️⃣Build your assignment
      • ➕Create assignment
        • ➕Standalone
        • ➕In Blackboard
        • ➕In Brightspace
        • ➕In Canvas
        • ➕In Moodle
        • ➕In Sakai
        • ➕In Open edX
        • 💾Importing a previous assignment
      • ⚙️General settings
      • 📋Add Rubric
      • 🤖Add Automatic Grading
      • 🧑‍🎓Student View
    • 2️⃣Grade your assignment
      • ✏️Give Feedback
      • 💯Give a Grade
    • 3️⃣Analyze your assignment
      • 🕵️‍♂️Detect Plagiarism
      • 📊Analytics
      • 🎓View and export grades
    • *️⃣Other features
      • AI Assistant
      • 👥Peer Feedback
      • 🫂Group Assignments
      • 🙋Collaborative Grading
      • 🕶️Anonymous Grading
      • 🛡️Manage Course Permissions
      • 📬Hand In Requirements
  • Automatic Grading Guides
    • 🏗️AutoTest V2 Blocks
    • ✏️Quizzes
      • ❓Multiple Choice Question
      • ❓Select All Question
      • 💻Coding Question
    • 🐍Python
      • 🐍Create your first Python assignment
      • 🐍Advanced Python autograding
    • ☕Java
      • ☕Create your first Java assignment
      • ☕Advanced Java autograding
    • 📘Jupyter Notebook
    • 🐬MySQL
    • 🌐Web Development
      • 🌐Web Development with Selenium
      • 🎨Automatically grading CSS
    • 🟨JavaScript
      • 🟨Create your first JavaScript assignment
      • 🟨Advanced JavaScript autograding
    • 📊R
    • ©️C
      • ©️Create your first C assignment
      • ©️Advanced C Autograding
    • 🖥️C#
      • 🖥️Create your first C# assignment
      • 🖥️Advanced C# autograding
    • ➕C++
      • ➕Create your first C++ assignment
      • ➕Advanced C++ autograding
    • 🐘PHP
      • 🐘Create your first PHP assignment
      • 🐘Advanced PHP autograding
    • 🏗️Code Structure Tests with Semgrep
  • For students
    • 🚀Getting started
      • 🚀Getting started in CodeGrade
      • 🚀Getting started in Blackboard
      • 🚀Getting started in Brightspace
      • 🚀Getting started in Canvas
      • 🚀Getting started in Moodle
      • 🤷‍♂️I forgot my CodeGrade username / password
    • 🧬Advanced Features
      • 👥Handing in with a group
      • 📥Handing in using Git
      • 📝Giving Peer Feedback
      • 🏆Doing a Final Exam
      • ❓Asking Questions
      • 💳Enrolling in a paid course
      • 🎟️Using a coupon to enroll in a course
      • ⏪Refunding a paid course
  • 📘APIv2: Typescript
  • 🐍APIv1: Python
  • 🤖APIv1: Docs
  • 🌐Our Website
  • ✉️Contact us
Powered by GitBook
On this page
  • Step 1: Create an assignment
  • Step 2: Configure submission settings
  • Step 3: Create a rubric
  • Step 4: Create automatic tests
  • Step 4.1: Setup
  • Step 4.2: Compilation test
  • Step 4.3: Input/Output tests
  • Step 4.4: Code structure tests
  • Step 5: Test and publish your AutoTests
  • Conclusion
  1. Automatic Grading Guides
  2. C

Create your first C assignment

PreviousCNextAdvanced C Autograding

Last updated 9 months ago

In this tutorial we will guide you through all the steps to create your very first C assignment in CodeGrade. For this tutorial we will be considering the example below. The zip folder contains a completed solution and a template file. Please make sure to save this file somewhere accessible on your computer:

A quick note about this example In this assignment, students have been asked to create a C program that prints the first 'n' numbers of the Fibonacci sequence starting from 1, where 'n' is determined by user input.

Step 1: Create an assignment

Firstly, we need an assignment to work with. Whether CodeGrade is integrated in your LMS or you are using CodeGrade Standalone, you can follow the steps in the guide below to get started:

Step 2: Configure submission settings

The first step in setting up an assignment is to ensure that students can submit their code correctly. Because this example is straightforward and only requires a single solution file, we will offer the students the option to code in the CodeGrade Editor alongside the default File Uploader option.

  1. Navigate to the Assignment Management page by using the icon at the right-hand side of the page header on the submissions page.

  1. Find the Submission settings in the corresponding container under the General tab.

  1. Enable the File uploader and Editor submission methods by clicking the respective check boxes.

  2. Enabling the Editor will reveal the Template files option. Unzip the Fibonacci.zip folder and upload Fibonacci/Template/Fibonacci.c as the template.

  3. Finalize your settings by clicking the "Submit" button.

It is good practice to provide a template file when enabling the Editor so that your students don't have to create their own file. This also avoids the risk of students submitting a file with the wrong name.

Step 3: Create a rubric

While you can always grade assignments directly by manually setting the Final grade, It's only possible to award points for your automatic tests with Rubrics. Rubrics also allow you to standardize the grading scheme for graders and they allow you to clarify the grading requirements to your students.

CodeGrade offers two types of rubric category:

  • Discrete category - Specify points in discrete steps (eg. 0, 5 or 10 points)

  • Continuous category - Specify points as a continuous scale (eg. 0 - 10)

  1. Navigate to the Rubric tab on the Assignment Management page.

  2. Select Create new rubric.

  3. Create 3 new Continuous Categories. Set the parameters as follows:

Category name
Description
Min - Max points

Compilation test

Check that your program compiles without errors.

0 - 20

IO tests

Check that your program produces the expected output given a specific input.

0 - 40

Code structure tests

Check that your program uses the required code structures.

0 - 40

Step 4: Create automatic tests

Automatic tests are really what gives your students the opportunity to learn in a unique way. The immediate feedback they get from the automatic tests allow them to learn through trial and error by applying the instant feedback and resubmitting their work.

For this tutorial we will be setting up three automatic tests: a compilation test, IO Tests, and Semgrep code structure tests.

Step 4.1: Setup

Before actually creating the tests, we need to make sure that we have the correct version of our compiler, GCC, installed.

  1. Navigate to the Setup tab under the AutoTest settings.

  2. Add the Install GCC block to your configuration.

  3. Select the latest version of GCC using the drop-down menu.

Step 4.2: Compilation test

Since C is a compiled language, we first have to compile our students' .c files to get an executable that we can run. We will also make the compilation step a graded component of the assignment. You can create compile steps like this using the Script block in AutoTest v2. This block is essentially a shell script that passes or fails depending on the exit code of the commands.

  1. Navigate to the Tests tab under the AutoTest settings.

  2. Add a Connect Rubric block to your configuration and select the "Compilation test" category from the drop-down menu.

  3. Add a Script block to your configuration. In the editor provided type the following command to compile your students' programs.

    gcc -o Fibonacci.o Fibonacci.c

Step 4.3: Input/Output tests

Input/Output tests, or "IO tests" for short, are a great way of checking a program's functionality by providing various input cases that should result in different outputs. You can create IO test cases in AutoTest v2 using the IO Test wrapper block and its corresponding Full match, Substring match, and Regex match blocks.

  1. Add a Connect Rubric block to your AutoTest configuration and select the "IO Tests" Rubric category from the drop-down menu.

  2. Add an IO test block to your AutoTest configuration and nest it within the Connect Rubric block. Run the program with the command ./Fibonacci.o in the provided editor.

  3. Add five Substring match blocks to your AutoTest configuration and nest them inside of the IO test block. Make sure each match block ignores whitespaces.

  4. For each Substring match block, copy one row from the table into the Input and Expected output fields in their respective match blocks:

Input
Expected output

1

1

3

1 1 2

5

1 1 2 3 5

0

invalid

-1

invalid

It's a good idea to give your tests descriptive names so that it's clear to both you and your students what is actually being checked (e.g. "Does your program produce the correct output? - Input: 5").

Step 4.4: Code structure tests

For this example, we want to check that the students have used a for loop and an if-statement in their program. Here are the Semgrep rules we will be using:

rules:
  - id: untitled_rule
    pattern: for($INT = $NUM; $COND; $UPDATE_INT){...}
    message: Semgrep found a match
    languages: [c]
    severity: WARNING
rules:
  - id: untitled_rule
    pattern: if($COND){...}
    message: Semgrep found a match
    languages: [c]
    severity: WARNING
  1. Add a Connect rubric block to your test configuration and select the "Code structure tests" category from the drop-down menu.

  2. Add a Code structure test block to your test configuration and nest it within the Connect rubric block.

  3. In the Student file input field, write "Fibonacci.c".

  4. Add two Positive match blocks to your test configuration and nest them within the Code structure test block

  5. Copy and paste the semgrep rules in the code blocks above into the provided editor in each Positive match block. Make sure to delete the template provided.

The version of Semgrep available in the AutoTest v2 editor may not be the most recent. For this reason, rules that work in the Semgrep playground may not always work in the Code Structure test block.

Step 5: Test and publish your AutoTests

It's important to test your AutoTest configuration before running it on students' submissions to make sure that your tests are running as expected and to check for edge cases. This is easy to do with Snapshots. When you're ready to check your tests, simply press the Build snapshot button at the bottom of the test block sidebar. This will make a test run of your AutoTest configuration on your Test submission.

The first time you build a snapshot, CodeGrade will prompt you to upload a Test submission. Use the "Click here to upload files" option or drag-and-drop the Fibonacci/Solution/fibonacci.c file that you downloaded at the beginning of this tutorial and click "Submit".

If in the future you need to re-upload your test submission, you can do so by going to Upload Submission option in the General Settings tab. Just upload your file and check the "Test Submission" option before clicking "Submit"

Once you're happy with your tests, you need to publish them to your students for them to run on their submissions. Publish your tests by building a snapshot and at the bottom of the pop-up modal click the Publish to students button.

Conclusion

You have just built your first automatically graded assignment, ready for your students to begin submitting work!

For more information about submission methods, see .

Semgrep is a code structure testing framework that is excellent for checking if students have used a specific syntax to reach their solution. AutoTest v2 offers the Code structure test block and its corresponding Positive match and Negative match blocks for running semgrep tests. For more details on setting up Code Structure Tests, read .

This guide is designed to get you started with a completed assignment but doesn't go into explicit detail about all of the features CodeGrade has to offer. For more in-depth information about the product and the various workflows that you can achieve, see or reach out to our support team at support@codegrade.com.

©️
©️
our dedicated guide
Learn more
⚙️
➕Create assignment
4KB
Fibonacci.zip
archive
Submission settings with the File uploader and Editor options enabled and a template file uploaded.
Rubric categories
A graded Code structure test in AutoTest v2
Submission Settings