Main Content

## Write Assessments for Script-Based Learner Solutions

For script-based solutions, you can easily create the most common assessments without writing code. Create an assessment by selecting the Test Type and specifying the solution code you are testing:

• `Variable Equals Reference Solution` — Check whether a variable in the learner solution equals the same variable in the reference solution within tolerance.

• `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.

• `MATLAB Code` — Write the assessment using MATLAB® code.

The code behind the first three actions uses the same assessment functions as the functions used to check a function-based solution. You can click to see the code.

### Execution Model

• When the learner submits a script-based solution for assessment, both the learner solution and the reference solution are run first. Your assessments then evaluate the learner solution.

• Each assessment runs sequentially and independently of the other assessments. If one assessment fails, the subsequent assessments 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 refer to variables in the reference solution by referring to `referenceVariables.``variable_name` in your code.

• If code terminates without errors, the assessment result shows a passed status. Otherwise, the assessment results show a failed status.

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

### Examples

#### The Fibonacci Sequence and For Loops

In this example, learners are asked to write a script that generates the first 50 values in the Fibonacci sequence, placing the result in the vector `x`. The learner should use a `for` loop.

Reference Solution

```% Initialize x as a row vector of zeros x = zeros(1,50); % Assign the first two elements of x to contain the first two values % of the Fibonacci sequence x(1) = 1; x(2) = 1; % Write a FOR loop to compute the remaining values for i = 3:50 x(i) = x(i-1)+x(i-2); end % The statement below will print out the first five values of x. disp(x(1:5)) ```

Assessment Tests

• Test 1: Check whether the learner solution uses a `for` loop: • Test 2: Check whether vector `x` has the correct value: Get trial now