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

[unit-test][unitTestClasses] added one reference matrix, fixed thesimulator class

parent b7047296
Branches
No related tags found
1 merge request!12Unit test
classdef TestSimulator < UnitTest classdef TestSimulator < UnitTest
properties properties
simulator struct % [-] simulatorSettings struct % [-]
refSimulator
end end
properties (TestParameter) properties (TestParameter)
generalParams = {'multipleAB', 'descent6DOF', 'ballistic', 'engineCut', 'solid','HRE1', 'HRE2', 'HRE3'} verifiable = {'multipleAB', 'descent6DOF', 'ballistic', 'engineCut', 'solid','HRE1', 'HRE2', 'HRE3'}
end end
methods methods
function values = setVerifiable(externalValues) function values = setVerifiable(testCase, externalValues)
% Function to allow user to change, if wanted, the parameters with % Function to allow user to change, if wanted, the parameters with
% which the test is run, so as to allow test running for certain % which the test is run, so as to allow test running for certain
...@@ -29,7 +30,7 @@ classdef TestSimulator < UnitTest ...@@ -29,7 +30,7 @@ classdef TestSimulator < UnitTest
methods (Test) methods (Test)
function createTest(testCase, verifiable) function createTestSimulator(testCase, verifiable)
currentPath = fileparts(mfilename('fullpath')); currentPath = fileparts(mfilename('fullpath'));
addpath(currentPath); addpath(currentPath);
...@@ -39,14 +40,13 @@ classdef TestSimulator < UnitTest ...@@ -39,14 +40,13 @@ classdef TestSimulator < UnitTest
% Load the reference file % Load the reference file
testCase.rocket = load(filePath, 'rocket'); testCase.rocket = load(filePath, 'rocket').rocket;
testCase.motor = load(filePath, 'motor'); testCase.environment = load(filePath, 'environment').environment;
testCase.environment = load(filePath, 'environment'); testCase.wind = load(filePath, 'wind').wind;
testCase.wind = load(filePath, 'wind');
% fieldName = ['referenceState_' verifiable]; % fieldName = ['referenceState_' verifiable];
testCase.refSimulator = load(filePath, 'stateA', 'stateF'); testCase.refSimulator = load(filePath, 'stateA', 'stateF');
testCase.simulatorSettings = load(filePath, 'simulatorSettings'); testCase.simulatorSettings = load(filePath, 'simulatorSettings').simulatorSettings;
% Construct the file path dynamically based on the test parameter % Construct the file path dynamically based on the test parameter
...@@ -60,15 +60,11 @@ classdef TestSimulator < UnitTest ...@@ -60,15 +60,11 @@ classdef TestSimulator < UnitTest
verifiable = testCase.setVerifiable(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, simulatorSettings] = mainSimulator(rocket,motor, environment, wind); [ascent, descent, simulatorSettings] = mainSimulator();
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
...@@ -92,13 +88,12 @@ classdef TestSimulator < UnitTest ...@@ -92,13 +88,12 @@ classdef TestSimulator < UnitTest
function mainSimulator(testCase, verifiable) function mainSimulator(testCase, verifiable)
verifiable = testCase.setVerifiable(verifiable); verifiable = testCase.setVerifiable(verifiable);
testCase.createTest(verifiable); testCase.createTestSimulator(verifiable);
mainSimPath = fullfile('..', 'simulator'); mainSimPath = fullfile('..', 'simulator');
addpath(mainSimPath); addpath(mainSimPath);
[postp.ascent, postp.descent, ~] = mainSimulator(testCase.simulatorSettings); [postp.stateA, postp.stateF, ~] = mainSimulator(testCase.rocket, testCase.wind, testCase.environment);
testCase.postp = postp; testCase.verifyEqual(postp, testCase.refSimulator, 'AbsTol', testCase.absToll, ...
testCase.verifyEqual(testCase.postp, testCase.refSimulator, 'AbsTol', testCase.absToll, ...
'RelTol', testCase.relToll) 'RelTol', testCase.relToll)
end end
......
...@@ -3,10 +3,11 @@ ...@@ -3,10 +3,11 @@
%% UNIT TESTS TO RUN %% UNIT TESTS TO RUN
% choose which folders to test % choose which folders to test
opt.testSimulator = false; opt.testSimulator = false;
opt.testCommonFunction = true; opt.testCommonFunction = false;
opt.testApogeeAnalysis = true; opt.testApogeeAnalysis = false;
opt.testOptimization = false; opt.testOptimization = false;
opt.testSensitivity = true; opt.testSensitivity = false;
opt.createTestSimulator
%% UNIT TEST TO CREATE %% UNIT TEST TO CREATE
% choose which folders to create data for % choose which folders to create data for
......
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
...@@ -42,7 +42,7 @@ end ...@@ -42,7 +42,7 @@ end
if opt.testSimulator if opt.testSimulator
test = TestSimulator(); test = TestSimulator();
test.creatTest; test.createTest;
sensResults = run(test); sensResults = run(test);
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment