Skip to content
Snippets Groups Projects
Commit b7047296 authored by Gabriele Ghia's avatar Gabriele Ghia Committed by Marco Luigi Gaibotti
Browse files

[unit-test][unitTestClasses] fixed TestSimulator, and added dynamic(optional)parameters

parent 28b32adf
No related branches found
No related tags found
1 merge request!12Unit test
...@@ -5,56 +5,51 @@ classdef TestSimulator < UnitTest ...@@ -5,56 +5,51 @@ classdef TestSimulator < UnitTest
end end
properties (TestParameter) properties (TestParameter)
verifiable = {'multipleAB', 'descent6DOF', 'ballistic', 'engineCut', 'solid','HRE1', 'HRE2', 'HRE3'} generalParams = {'multipleAB', 'descent6DOF', 'ballistic', 'engineCut', 'solid','HRE1', 'HRE2', 'HRE3'}
end end
methods methods
function createTest(testCase, verifiable)
currentPath = fileparts(mfilename('fullpath'));
addpath(currentPath);
function values = setVerifiable(externalValues)
% Function to allow user to change, if wanted, the parameters with
% which the test is run, so as to allow test running for certain
% conditions only
if strcmp(verifiable, 'solid') if isempty(externalValues)
testCase.mission = Mission(pyxis); %marco help values = testCase.generalParams;
testCase.rocket = Rocket(mission); fprintf('\t testing with general params\n');
testCase.environment = Environment(mission);
else
if strcmp(verifiable, 'HRE1')
testCase.rocket.airbrakes.extension = 0;
testCase.rocket.updateAll
else
if strcmp(verifiable, 'HRE2')
testCase.rocket.airbrakes.extension = 0.5;
testCase.rocket.updateAll
else
if strcmp(verifiable, 'HRE3')
testCase.rocket.airbrakes.extension = 1;
testCase.rocket.updateAll
else else
if strcmp(verifiable, 'engineCut') values = externalValues;
settings.timeEngineCut = (0.75) * settings.tb; % [s] Moment in time in wich the engine will be cut off
settings = settingsEngineCut(settings); %%HELP MAUCO
end end
end end
end
end
end end
[~, ~, testCase.simulator] = mainSimulator(testCase.rocket, testCase.wind, testCase.environment);
methods (Test)
function createTest(testCase, verifiable)
currentPath = fileparts(mfilename('fullpath'));
addpath(currentPath);
fileName = sprintf("referenceState_%s.mat", verifiable);
filePath = fullfile('data', 'testSimulator', verifiable, fileName);
% Construct the file path dynamically based on the test parameter
filePath = sprintf("data\\testSimulator\\%s\\referenceState_%s.mat", verifiable, verifiable);
% Load the reference file % Load the reference file
ref = load(filePath); testCase.rocket = load(filePath, 'rocket');
testCase.motor = load(filePath, 'motor');
testCase.environment = load(filePath, 'environment');
testCase.wind = load(filePath, 'wind');
% fieldName = ['referenceState_' verifiable];
testCase.refSimulator = load(filePath, 'stateA', 'stateF');
testCase.simulatorSettings = load(filePath, 'simulatorSettings');
% Construct the file path dynamically based on the test parameter
fieldName = ['referenceState_' verifiable];
testCase.refSimulator = ref.(fieldName);
end end
...@@ -62,34 +57,50 @@ classdef TestSimulator < UnitTest ...@@ -62,34 +57,50 @@ classdef TestSimulator < UnitTest
function saveTest(testCase, verifiable) function saveTest(testCase, verifiable)
verifiable = testCase.setVerifiable(verifiable);
Time = tic; Time = tic;
mission = Mission(true);
rocket = Rocket(Mission);
motor = Motor(mission);
environment = Environment(mission, motor);
wind = Wind(mission);
% simulator % simulator
[ascent, descent, ~] = mainSimulator(testCase.simulator); [ascent, descent, simulatorSettings] = mainSimulator(rocket,motor, environment, wind);
stateA = ascent(end, :); % state at end of ascent stateA = ascent(end, :); % state at end of ascent
stateF = descent(end, :); % final state, at touchdown stateF = descent(end, :); % final state, at touchdown
stateF = [stateF zeros(1, 7)]; % to avoid problems in checkErrorSimulator stateF = [stateF zeros(1, 7)]; % to avoid problems in checkErrorSimulator
% saving final state % saving final state
filePath = sprintf("data\\testSimulator\\%s\\referenceState_%s.mat", verifiable, verifiable); fileName = sprintf("referenceState_%s.mat", verifiable);
save(filePath,'stateA','stateF'); filePath = fullfile('data', 'testSimulator', verifiable, fileName);
save(filePath,'stateA','stateF', 'simulatorSettings',...
'mission', 'rocket',...
'environment', 'wind', 'motor');
Time = toc(Time); Time = toc(Time);
fprintf('\t %s test created in: %2.2f seconds\n',verifiable, Time) fprintf('\t %s test created in: %2.2f seconds\n',verifiable, Time)
end end
end
methods (Test)
function mainSimulator(testCase)
addpath(genpath('../../simulator')) function mainSimulator(testCase, verifiable)
[postp.ascent, postp.descent, ~] = mainSimulator(testCase.simulator);
verifiable = testCase.setVerifiable(verifiable);
testCase.createTest(verifiable);
mainSimPath = fullfile('..', 'simulator');
addpath(mainSimPath);
[postp.ascent, postp.descent, ~] = mainSimulator(testCase.simulatorSettings);
testCase.postp = postp; testCase.postp = postp;
testCase.verifyEqual(testCase.postp, testCase.refSimulator, 'AbsTol', testCase.absToll, ... testCase.verifyEqual(testCase.postp, testCase.refSimulator, 'AbsTol', testCase.absToll, ...
'RelTol', testCase.relToll) 'RelTol', testCase.relToll)
end end
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment