eval_test_list

Version 1.0.0 (2.91 KB) by Matlab Pro
- e-z running a test list
1 Download
Updated 21 May 2024

View License

eval_test_list - e-z running a test list
Description
eval_test_list makes it super easy to run a set of tests on variables
Could be super handy to validate varaiables pass/fail certain rules
Syntax
out = eval_test_list(tests)
out = eval_test_list(tests, breakOn1stFailure)
out = eval_test_list(tests, breakOn1stFailure, showActualVarsInsideExpression)
out = eval_test_list(tests, breakOn1stFailure, showActualVarsInsideExpression, concatenate_expresssion_and_actual_vars)
Inputs & Outputs
legend:
P/F = Pass/Fail (logical)
ex = expression
inputs
obligatory inputs:
tests - cellarray containing expression(s) to test
optional inputs:
breakOn1stFailure - optional (true)
when=true : out = [failed ex]
when=false: continue evaluating all tests
out = [ex,P/F]
showActualVarsInsideExpression - optional (true)
when=true : out = [ex,P/F,ex with actual numbers]
concatenate_expresssion_and_actual_vars - optional (true)
when=true : out = [ex,P/F,ex with actual numbers]
when=false : out = [[ex :: ,ex with actual numbers],P/F]
output
out - cellarray . If no error: empty
otherwise: error information (see examples)
Examples
% Paremeter for all next examples:
scenario = -99;
start_address = 22;
end_address = 4;
tests = { ...
'start_address <= end_address', ...
'isnumeric(scenario)', ...
'isnumeric(start_address)', ...
'isnumeric(end_address)', ...
'scenario >= 0', ...
'start_address >= 0', ...
'end_address >= 0' , ...
'scenario < 100'};
% Example 1a
===============
When running ..
err = eval_test_list(tests);
output:
err = 'Expression that failed: "start_address <= end_address" :: ("22 <= 4")'
% Example 1b
breakOn1stFailure = true;
showActualVarsOnErrorMessage = false;
When running ..
err = eval_test_list(tests,breakOn1stFailure, showActualVarsOnErrorMessage)
output:
err = 'start_address <= end_address'
% Example 2
breakOn1stFailure = false;
When running ..
err = eval_test_list(tests,breakOn1stFailure);
output:
err =
{'Expression that failed: "start_address <= end_address" :: ("22 <= 4")' } {[0]}
{'Expression that failed: "isnumeric(scenario)" :: ("isnumeric(-99)")' } {[1]}
{'Expression that failed: "isnumeric(start_address)" :: ("isnumeric(22)")'} {[1]}
{'Expression that failed: "isnumeric(end_address)" :: ("isnumeric(4)")' } {[1]}
{'Expression that failed: "scenario >= 0" :: ("-99 >= 0")' } {[0]}
{'Expression that failed: "start_address >= 0" :: ("22 >= 0")' } {[1]}
{'Expression that failed: "end_address >= 0" :: ("4 >= 0")' } {[1]}
{'Expression that failed: "scenario < 100" :: ("-99 < 100")' } {[1]}
Example 3
breakOn1stFailure = false;
showActualVarsOnErrorMessage = false;
When running ..
err = eval_test_list(tests,breakOn1stFailure, showActualVarsOnErrorMessage)
output:
err =
{'start_address <= end_address'} {[0]}
{'isnumeric(scenario)' } {[1]}
{'isnumeric(start_address)' } {[1]}
{'isnumeric(end_address)' } {[1]}
{'scenario >= 0' } {[0]}
{'start_address >= 0' } {[1]}
{'end_address >= 0' } {[1]}
{'scenario < 100' } {[1]}
Example 4
breakOn1stFailure = false;
showActualVarsInsideExpression = true;
concatenate_expresssion_and_actual_vars = false;
When running ..
err = eval_test_list(tests,breakOn1stFailure, showActualVarsInsideExpression, concatenate_expresssion_and_actual_vars)
output:
err =
{'start_address <= end_address'} {[0]} {'22 <= 4' }
{'isnumeric(scenario)' } {[1]} {'isnumeric(-99)'}
{'isnumeric(start_address)' } {[1]} {'isnumeric(22)' }
{'isnumeric(end_address)' } {[1]} {'isnumeric(4)' }
{'scenario >= 0' } {[0]} {'-99 >= 0' }
{'start_address >= 0' } {[1]} {'22 >= 0' }
{'end_address >= 0' } {[1]} {'4 >= 0' }
{'scenario < 100' } {[1]} {'-99 < 100' }
Inspired by the function: v2struct

Cite As

Matlab Pro (2024). eval_test_list (https://www.mathworks.com/matlabcentral/fileexchange/166216-eval_test_list), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2022b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.0