Main Content

Write Assessments for Script-Type Learner Solutions

When you write tests to assess solutions for script-type problems, MATLAB® Grader™ provides assessment methods for checking variable equality and the presence or absence of specific keywords and functions.

The following concepts and procedures can help in writing assessments:

  • MATLAB Grader Test Types—Provided methods to help assess variable equality and the presence or absence of specific functions and keywords.

  • The Execution Model—Explains how assessments are run and assessment results are marked.

You can examine some examples of assessments in Example: Assessments for the "Symbolic Taylor Expansion" Coding Problem.

Read about factors that affect the assessment of learner solutions in Test Learner Solutions.

MATLAB Grader Test Types

You can easily create the most common assessments without writing code. To create an assessment, select the Test Type and specify what is being tested:

  • Variable Equals Reference Solution — Check whether the indicated variable exists in the learner solution and is equal to the same variable in the reference solution. A tolerance is applied for numeric data types only.

  • Function or Keyword Is Present — Check for the presence of specific functions or keywords in the learner solution.

  • Function or Keyword Is Absent — Check that certain functions or keywords are not present in the learner solution.

Convert any test to MATLAB code by clicking Convert Test To Code.

If you prefer to write your own assessment code, select the test type MATLAB Code. You can incorporate the tests listed above using the built-in assessment functions assessVariableEqual, assessFunctionPresence, and assessFunctionAbsence.

Execution Model

The execution model explains how assessments are run and assessment results are marked in MATLAB Grader.

  • When the learner submits a script-type solution to be assessed, both the reference solution and the learner submission are run. Your assessments then evaluate the learner solution.

  • Each assessment runs sequentially and independently of the other assessments. If the learner solution fails one assessment, subsequent assessments are still run.

  • Variables created in one assessment are not available in the next one. Define all the required variables in each assessment.

  • An assessment can access variables in the reference solution by using the syntax referenceVariables.variable_name.

  • An assessment can access variables in the learner solution by using the syntax variable_name.

  • If the code terminates without errors, the assessment is marked correct. If the code returns an error, the assessment is marked incorrect.

  • If the learner solution contains a syntax error, all assessments for that solution are marked incorrect.

If the assessment is a pretest, the learner can view the assessment code by clicking the arrow to the left of the test name, regardless of whether the solution passed or failed the assessment.

Each assessment for a given coding problem impacts the execution time for running the solution and the assessments. For more details, see Time Limits for Submissions.

Example: Assessments for the "Symbolic Taylor Expansion" Coding Problem

This section uses code examples from Symbolic Taylor Expansion, which you can find on your MATLAB Grader home page in the MathWorks® Collections under Getting Started with MATLAB Grader.

In this example, learners are asked to write a script to compute the Taylor series approximation of f(x)=e to the -x sin(x)cos(x) at x = 0 for n = 8 using symbolic variables.

Test for Presence of Taylor Function

In this assessment, the instructor checks for the presence of a specific function and provides appropriate feedback if the learner solution fails the assessment.

Example of test type function or keyword is present

Test If Variable Is Defined Correctly

This assessment checks if the named variable has the same value in the learner and reference solutions and provides appropriate feedback if the learner solution fails the assessment.

Example of test type variable equals reference solution

Test If Learner Code Is Correct (MATLAB Code)

This assessment uses MATLAB Code and a built-in assessment function to test the learner solution. The instructor also specifies appropriate feedback to display to the learner if their solution fails the assessment.

Example of MATLAB code used to calculate and then assess variable equality

Try the Example Script Problem

The example used in this topic is from Symbolic Taylor Expansion, which you can find in the MathWorks Collections under Getting Started with MATLAB Grader.

To try solving the problem as a learner would, open the problem and then click Learner Preview. Enter your code in the solution box and then click Submit to run the assessments (no submission is actually recorded). Try both correct and incorrect code to see the feedback you get.

Related Topics