diff --git a/unitTests/unitTestClasses/TestSimulator.m b/unitTests/unitTestClasses/TestSimulator.m
index a7cc0b2551e72a7d0b6149559fa2c8667050442a..0c97974b3fab3421c966bf25c568e48df9728be7 100644
--- a/unitTests/unitTestClasses/TestSimulator.m
+++ b/unitTests/unitTestClasses/TestSimulator.m
@@ -5,56 +5,51 @@ classdef TestSimulator < UnitTest
end
properties (TestParameter)
- verifiable = {'multipleAB', 'descent6DOF', 'ballistic', 'engineCut', 'solid','HRE1', 'HRE2', 'HRE3'}
+ generalParams = {'multipleAB', 'descent6DOF', 'ballistic', 'engineCut', 'solid','HRE1', 'HRE2', 'HRE3'}
end
methods
+
+ 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 isempty(externalValues)
+ values = testCase.generalParams;
+ fprintf('\t testing with general params\n');
+ else
+ values = externalValues;
+ end
+
+ end
+
+ end
+
+
+ methods (Test)
function createTest(testCase, verifiable)
-
currentPath = fileparts(mfilename('fullpath'));
addpath(currentPath);
+
+ fileName = sprintf("referenceState_%s.mat", verifiable);
+ filePath = fullfile('data', 'testSimulator', verifiable, fileName);
-
-
- if strcmp(verifiable, 'solid')
- testCase.mission = Mission(pyxis); %marco help
- testCase.rocket = Rocket(mission);
- 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
- if strcmp(verifiable, 'engineCut')
- 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
-
- [~, ~, testCase.simulator] = mainSimulator(testCase.rocket, testCase.wind, testCase.environment);
-
-
- % Construct the file path dynamically based on the test parameter
- filePath = sprintf("data\\testSimulator\\%s\\referenceState_%s.mat", verifiable, verifiable);
% Load the reference file
- ref = load(filePath);
-
- fieldName = ['referenceState_' verifiable];
- testCase.refSimulator = ref.(fieldName);
+ 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
+
end
@@ -62,34 +57,50 @@ classdef TestSimulator < UnitTest
function saveTest(testCase, verifiable)
-
- Time = tic;
+ verifiable = testCase.setVerifiable(verifiable);
+ Time = tic;
+ mission = Mission(true);
+ rocket = Rocket(Mission);
+ motor = Motor(mission);
+ environment = Environment(mission, motor);
+ wind = Wind(mission);
+
% simulator
- [ascent, descent, ~] = mainSimulator(testCase.simulator);
+ [ascent, descent, simulatorSettings] = mainSimulator(rocket,motor, environment, wind);
stateA = ascent(end, :); % state at end of ascent
stateF = descent(end, :); % final state, at touchdown
stateF = [stateF zeros(1, 7)]; % to avoid problems in checkErrorSimulator
% saving final state
- filePath = sprintf("data\\testSimulator\\%s\\referenceState_%s.mat", verifiable, verifiable);
- save(filePath,'stateA','stateF');
+ fileName = sprintf("referenceState_%s.mat", verifiable);
+ filePath = fullfile('data', 'testSimulator', verifiable, fileName);
+ save(filePath,'stateA','stateF', 'simulatorSettings',...
+ 'mission', 'rocket',...
+ 'environment', 'wind', 'motor');
+
Time = toc(Time);
fprintf('\t %s test created in: %2.2f seconds\n',verifiable, Time)
end
- end
+
- methods (Test)
- function mainSimulator(testCase)
- addpath(genpath('../../simulator'))
- [postp.ascent, postp.descent, ~] = mainSimulator(testCase.simulator);
+
+ function mainSimulator(testCase, verifiable)
+
+ verifiable = testCase.setVerifiable(verifiable);
+ testCase.createTest(verifiable);
+
+ mainSimPath = fullfile('..', 'simulator');
+ addpath(mainSimPath);
+ [postp.ascent, postp.descent, ~] = mainSimulator(testCase.simulatorSettings);
testCase.postp = postp;
testCase.verifyEqual(testCase.postp, testCase.refSimulator, 'AbsTol', testCase.absToll, ...
'RelTol', testCase.relToll)
+
end
end