From 8dd8b438a5e8633bb2b6a61f2d29a5cbf0c64fb3 Mon Sep 17 00:00:00 2001 From: LolloBici <lorenzo.amici@skywarder.eu> Date: Wed, 13 Nov 2024 11:33:49 +0100 Subject: [PATCH] [unit-test][unitTestClasses] fixed TestSimulator --- unitTests/unitTestClasses/TestSimulator.m | 46 +++++++++++++---------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/unitTests/unitTestClasses/TestSimulator.m b/unitTests/unitTestClasses/TestSimulator.m index 8e94a72c..f67ebf7e 100644 --- a/unitTests/unitTestClasses/TestSimulator.m +++ b/unitTests/unitTestClasses/TestSimulator.m @@ -26,16 +26,14 @@ classdef TestSimulator < UnitTest end methods - function saveTest(testCase, verifiable, mission) + function saveTest(testCase, verifiable, mission) Time = tic; rocket = Rocket(mission); 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); - end + fprintf('\t %s test created in: %2.2f seconds\n',verifiable, Time) + + end function createTestSimulator(testCase, verifiable) + + currentPath = fileparts(mfilename('fullpath')); addpath(currentPath); @@ -59,21 +62,24 @@ 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); mainSimPath = fullfile('..', 'simulator'); -- GitLab