Skip to content
Snippets Groups Projects
Commit 8dd8b438 authored by Lorenzo Amici's avatar Lorenzo Amici Committed by Marco Luigi Gaibotti
Browse files

[unit-test][unitTestClasses] fixed TestSimulator

parent cc762306
Branches
No related tags found
1 merge request!12Unit test
......@@ -32,10 +32,8 @@ classdef TestSimulator < UnitTest
environment = Environment(mission, rocket.motor);
wind = WindCustom(mission);
% Run simulator
[ascent, descent, simulatorSettings] = mainSimulator(rocket, wind, environment);
stateA = ascent(end, :); % State at end of ascent
stateF = descent(end, :); % Final state, at touchdown
% simulator
[ascent, descent, testCase.simulatorSettings] = mainSimulator(rocket, wind, environment);
% Save final state
fileName = sprintf("referenceState_%s.mat", verifiable);
......@@ -45,13 +43,18 @@ classdef TestSimulator < UnitTest
if ~exist(folderPath, "dir")
mkdir(folderPath)
end
save(filePath, 'stateA', 'stateF', 'simulatorSettings', 'mission', 'rocket', 'environment', 'wind');
save(filePath,'stateA','stateF', 'testCase.simulatorSettings',...
'mission', 'rocket',...
'environment', 'wind');
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
function createTestSimulator(testCase, verifiable)
currentPath = fileparts(mfilename('fullpath'));
addpath(currentPath);
......@@ -59,20 +62,23 @@ classdef TestSimulator < UnitTest
filePath = fullfile('data', 'testSimulator', verifiable, fileName);
% Load the reference file
loadedData = load(filePath);
testCase.rocket = loadedData.rocket;
testCase.environment = loadedData.environment;
testCase.wind = loadedData.wind;
testCase.refSimulator = struct('stateA', loadedData.stateA, 'stateF', loadedData.stateF);
testCase.simulatorSettings = loadedData.simulatorSettings;
testCase.rocket = load(filePath, 'rocket').rocket;
testCase.environment = load(filePath, 'environment').environment;
testCase.wind = load(filePath, 'wind').wind;
% fieldName = ['referenceState_' verifiable];
testCase.refSimulator = load(filePath, 'stateA', 'stateF');
testCase.simulatorSettings = load(filePath, 'simulatorSettings').simulatorSettings;
% Construct the file path dynamically based on the test parameter
end
end
methods (Test)
function mainSimulatorTest(testCase, verifiable)
if nargin < 2 || isempty(verifiable)
error('The "verifiable" parameter must be provided when not using TestParameter.');
end
testCase.createTestSimulator(verifiable);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment