%% Assess a Model by Using |When| Decomposition
%
% This example shows how to use |When| decomposition in a Test Sequence
% block to author assessments in a test harness. 

% Copyright 2015-2020 The MathWorks, Inc.

%%
% This model implements a simple signal tracker that operates in three
% modes: |0| (Off), |1| (Slow), and |2| (Quick). 

mdl = 'sltestTestSequenceWhenExample';
open_system(mdl);

%%
% To observe the output and error of the signal tracker, simulate the
% model.

sim(mdl);
open_system([mdl '/Scope']);

%% Open the Test Harness
% The SimpleTracker subsystem has a test harness that contains a Test
% Assessment block.

sltest.harness.open([mdl '/SimpleTracker'],'SimpleTrackerHarness');

%%
% The Test Assessment block assesses the behavior of the SimpleTracker
% subsystem by using a |When| decomposition test sequence.
%
% <<../sltestTestSequenceUsingWhenAssessment.png>>
%
% The test sequence determines the appropriate verify() statements to run based on
% the value of |mode|. The |CheckError| step has a |When| decomposition
% with three substeps:
%
% * |OffMode| is active when the value of |mode| is |0| (Off).
% * |SlowMode| is active when the value of |mode| is |1| (Slow).
% * |QuickMode| is active for all other values of |mode|.

%% Run the Model Assessments
%
% To run the assessments, simulate the test harness. Open the Simulation Data
% Inspector to inspect the result of the assessments.

sim('SimpleTrackerHarness');
open_system('SimpleTrackerHarness/Scope');

%%
% <<../sltestTestSequenceUsingWhenVerifyResults.png>>

%%
% Close the test harness and main model.
close_system(mdl, 0);
