From 5863375f0a63e3a0a1d8701ceacbdfa5da32021a Mon Sep 17 00:00:00 2001 From: LolloBici <lorenzo.amici@skywarder.eu> Date: Wed, 20 Nov 2024 16:40:14 +0100 Subject: [PATCH] [unit-test][unitTestClasses] creating README (settings bug) --- apogeeAnalysis/apogeeAnalysisConfig.m | 2 +- common | 2 +- unitTests/unitTestClasses/README.md | 41 +++++++ .../unitTestClasses/TestApogeeAnalysis.m | 48 +++++--- .../unitTestClasses/TestCommonFunctions.m | 109 ++++++++++-------- unitTests/unitTestClasses/TestSensitivity.m | 109 +++++++----------- unitTests/unitTestClasses/TestSimulator.m | 100 ++++++++-------- unitTests/unitTestClasses/configUnitTest.m | 3 + .../engineCutApogee/refEngineCut.mat | 4 +- .../standardApogee/refStandard.mat | 4 +- .../createDissileInput/refInput.mat | 3 + .../createDissileInput/refInputValue.mat | 3 - .../interpCoeffs/refInterpCoeffs.mat | 3 + .../testCommonFunctions/refInterpCoeffs.mat | 3 + .../refSensitivity.mat | 4 +- .../testSimulator/HRE/referenceState_HRE.mat | 4 +- .../ballistic/referenceState_ballistic.mat | 4 +- .../engineCut/referenceState_engineCut.mat | 4 +- .../multipleAB/referenceState_multipleAB.mat | 4 +- unitTests/unitTestClasses/mainUnitTest.m | 15 +-- unitTests/unitTestClasses/saveTests.m | 24 ++-- 21 files changed, 264 insertions(+), 229 deletions(-) create mode 100644 unitTests/unitTestClasses/README.md create mode 100644 unitTests/unitTestClasses/data/testCommonFunctions/createDissileInput/refInput.mat delete mode 100644 unitTests/unitTestClasses/data/testCommonFunctions/createDissileInput/refInputValue.mat create mode 100644 unitTests/unitTestClasses/data/testCommonFunctions/interpCoeffs/refInterpCoeffs.mat create mode 100644 unitTests/unitTestClasses/data/testCommonFunctions/refInterpCoeffs.mat diff --git a/apogeeAnalysis/apogeeAnalysisConfig.m b/apogeeAnalysis/apogeeAnalysisConfig.m index 564f2861..0f517bf0 100644 --- a/apogeeAnalysis/apogeeAnalysisConfig.m +++ b/apogeeAnalysis/apogeeAnalysisConfig.m @@ -16,7 +16,7 @@ analysis.isEngineCut = true; %% SELECT MOTORS selection.producer = {'Skyward'}; % it can be {'Skyward'}, OR one or more between {'Aerotech', 'Cesaroni'} selection.totalImpulseRange = [10000 15000]; % [Ns] total impulse range for the analysis -selection.motorString = 'SFT'; % Select motors containg this sting in motorName to select all the motors, set selection.motorString = ''; +selection.motorString = ''; % Select motors containg this sting in motorName to select all the motors, set selection.motorString = ''; selection.motorName = {}; % Chose motors with ignition and cutoff transient diff --git a/common b/common index 554b97ec..04e33274 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit 554b97eca558490c38b4694b7f34eb54a20b5a03 +Subproject commit 04e332747f9aeb153a4acc79d618caf51db48901 diff --git a/unitTests/unitTestClasses/README.md b/unitTests/unitTestClasses/README.md new file mode 100644 index 00000000..3bfad990 --- /dev/null +++ b/unitTests/unitTestClasses/README.md @@ -0,0 +1,41 @@ +# Unit Testing Framework for Rocket Simulations + +This repository provides a unit testing framework designed to validate key functionalities for some tools of the msa-toolkit. +It includes various test classes, scripts for configuration and execution, and a `data` folder containing reference data and inputs for the tests. + +--- + +## **Folder Structure** + +### **Key Components** +- **`data/`**: Stores all reference data and input files needed for the tests. +- **Test Classes**: Each class (e.g., `TestCommonFunctions`, `TestSimulator`). +- **Scripts**: + - **`mainUnitTest.m`**: Executes the selected tests based on the configuration. + - **`saveTests.m`**: Saves settings and reference data for future tests. + - **`configUnitTest.m`**: Allows users to configure which tests to run or save, as well as the mission parameters. + +--- + +## **How to Run Tests** + +### 1. **Automatic Testing** +Tests are executed automatically when merging a branch into the `main` branch. +This ensures all functionalities are validated before the merge. + +### 2. **Manual Testing** +To run tests manually: +1. **Configure Tests**: Open the `configUnitTest.m` script and specify: + - The tests to be executed. + - The mission parameters for the tests. +2. **Run the Tests**: Execute the `mainUnitTest.m` script: + +--- + +## **How to Save Tests** + +### 2. **Manual Testing** +1. **Configure Tests**: Open the `configUnitTest.m` script and specify: + - The tests to be saved. + - The mission parameters for the tests. +2. **Save the Tests**: Execute the `saveTests.m` script: diff --git a/unitTests/unitTestClasses/TestApogeeAnalysis.m b/unitTests/unitTestClasses/TestApogeeAnalysis.m index 4e9544b7..5f77e953 100644 --- a/unitTests/unitTestClasses/TestApogeeAnalysis.m +++ b/unitTests/unitTestClasses/TestApogeeAnalysis.m @@ -1,34 +1,44 @@ classdef TestApogeeAnalysis < UnitTest properties - referenceStandardResults struct - referenceEngineCutResults struct + refStandardResults + refEngineCutResults + apogeeAnalysisSettings end methods function createTest(testCase) - ref1 = load("data\testApogeeAnalysis\standardApogee\refStandard.mat"); - ref2 = load("data\testApogeeAnalysis\engineCutApogee\refEngineCut.mat"); - testCase.referenceStandardResults = ref1.refStandard; - testCase.referenceEngineCutResults = ref2.refEngineCut; + currentPath = fileparts(mfilename("fullpath")); + addpath(genpath(currentPath)); + + testCase.refStandardResults = load(fullfile(currentPath, "data", "testApogeeAnalysis", "standardApogee", "refStandard.mat")).refStandard; + testCase.refEngineCutResults = load(fullfile(currentPath, "data", "testApogeeAnalysis", "engineCutApogee", "refEngineCut.mat")).refEngineCut; + testCase.apogeeAnalysisSettings = load(fullfile(currentPath, "data", "testApogeeAnalysis", "engineCutApogee", "refEngineCut.mat")).apogeeAnalysisSettings; + + testCase.rocket = load(fullfile(currentPath, "data", "testApogeeAnalysis", "engineCutApogee", "refEngineCut.mat")).rocket; end + end - function saveTest(testCase) + methods (Static) + function saveTest(mission) totTime = tic; currentPath = fileparts(mfilename('fullpath')); - cd(currentPath); + configPath = fullfile(currentPath, "data", "testApogeeAnalysis"); addpath(genpath(currentPath)); disp('Started saving apogee analysis tests') - [refStandard, refEngineCut] = mainApogeeAnalysis(testCase.rocket); + rocket = Rocket(mission); + + [refStandard, refEngineCut, apogeeAnalysisSettings] = mainApogeeAnalysis(rocket); + + %apogeeAnalysisSettings = Settings("apogeeAnalysis"); - save("data\testApogeeAnalysis\standardApogee\refStandard.mat" ... - , "refStandard"); - save("data\testApogeeAnalysis\engineCutApogee\refEngineCut.mat" ... - , "refEngineCut"); + save(fullfile(configPath, "standardApogee", "refStandard.mat") , "refStandard", "apogeeAnalysisSettings", "rocket"); + save(fullfile(configPath, "engineCutApogee", "refEngineCut.mat"), "refEngineCut", "apogeeAnalysisSettings", "rocket"); clearvars -except totTime paths totTime opt + close all; time = toc(totTime); fprintf('Apogee analysis tests saved successfully in: %2.2f seconds\n\n', time) @@ -39,15 +49,21 @@ classdef TestApogeeAnalysis < UnitTest methods (Test) function apogeeAnalysis(testCase) - [standardResults, engineCutResults] = mainApogeeAnalysis(testCase.rocket); + testCase.createTest(); + + [standardResults, engineCutResults] = mainApogeeAnalysis(testCase.rocket, testCase.apogeeAnalysisSettings); + + close all; % Standard analysis tests with tolerances - testCase.verifyEqual(standardResults, testCase.referenceStandardResults, ... + testCase.verifyEqual(standardResults, testCase.refStandardResults, ... 'AbsTol', testCase.absToll, 'RelTol', testCase.relToll); % Engine cut results with tolerances - testCase.verifyEqual(engineCutResults, testCase.referenceEngineCutResults, ... + testCase.verifyEqual(engineCutResults, testCase.refEngineCutResults, ... 'AbsTol', testCase.absToll, 'RelTol', testCase.relToll); + + close all; end end end diff --git a/unitTests/unitTestClasses/TestCommonFunctions.m b/unitTests/unitTestClasses/TestCommonFunctions.m index 7a097614..2e565cc1 100644 --- a/unitTests/unitTestClasses/TestCommonFunctions.m +++ b/unitTests/unitTestClasses/TestCommonFunctions.m @@ -4,59 +4,70 @@ classdef TestCommonFunctions < UnitTest % mainUnitTests script. properties - referenceCoeffsValue double - referenceAngles double - referenceInputValue struct - coeffsValue double - angles double - testInput struct - vars struct - - t = 1.3; % [s] integration time - alpha = 5; % [-] angle of attack - mach = 0.4; % [-] mach number - beta = 2; % [-] sideslip angle - alt = 1145; % [m] altitude - c = 2; % [-] aerobrakes control variable + refCoeffsValue + refAngles + refInputValue + commonFunctionsSettings + + cutoffTime + coefficients + vars + t + alpha + mach + beta + alt + c end methods function createTest(testCase) currentPath = fileparts(mfilename('fullpath')); - cd(currentPath); - ref1 = load("data/testCommonFunctions/interpCoeffs/refCoeffsValue"); - ref2 = load("data/testCommonFunctions/interpCoeffs/refAngles"); - ref3 = load("data/testCommonFunctions/createDissileInput/refInputValue"); - - testCase.referenceCoeffsValue = ref1.refCoeffsValue; - testCase.referenceAngles = ref2.refAngles; - testCase.referenceInputValue = ref3.refInput; + addpath(genpath(currentPath)); + + testCase.refCoeffsValue = load(fullfile(currentPath, 'data', 'testCommonFunctions', 'interpCoeffs', 'refInterpCoeffs.mat')).refCoeffsValue; + testCase.refAngles = load(fullfile(currentPath, 'data', 'testCommonFunctions', 'interpCoeffs', 'refInterpCoeffs.mat')).refAngles; + testCase.refInputValue = load(fullfile(currentPath, 'data', 'testCommonFunctions', 'createDissileInput', 'refInput.mat')).refInput; - testCase.vars = struct(); - testCase.vars.mach = 0.05:0.05:1; - testCase.vars.alpha = [-10 -7.5 -5 -2.5 -1 -0.5 -0.1 0 0.1 0.5 1 2.5 5 7.5 10]; - testCase.vars.beta = [-2.5 -0.1 0 0.1 2.5]; - testCase.vars.alt = (0:400:4000); + testCase.rocket = load(fullfile(currentPath, 'data', 'testCommonFunctions', 'interpCoeffs', 'refInterpCoeffs.mat')).rocket; + testCase.vars = load(fullfile(currentPath, 'data', 'testCommonFunctions', 'createDissileInput', 'refInput.mat')).vars; + testCase.t = load(fullfile(currentPath, 'data', 'testCommonFunctions', 'interpCoeffs', 'refInterpCoeffs.mat')).t; + testCase.alpha = load(fullfile(currentPath, 'data', 'testCommonFunctions', 'interpCoeffs', 'refInterpCoeffs.mat')).alpha; + testCase.mach = load(fullfile(currentPath, 'data', 'testCommonFunctions', 'interpCoeffs', 'refInterpCoeffs.mat')).mach; + testCase.beta = load(fullfile(currentPath, 'data', 'testCommonFunctions', 'interpCoeffs', 'refInterpCoeffs.mat')).beta; + testCase.alt = load(fullfile(currentPath, 'data', 'testCommonFunctions', 'interpCoeffs', 'refInterpCoeffs.mat')).alt; + testCase.c = load(fullfile(currentPath, 'data', 'testCommonFunctions', 'interpCoeffs', 'refInterpCoeffs.mat')).c; + testCase.vars.xcg = testCase.rocket.xCg; - testCase.vars.hprot = []; - end + testCase.cutoffTime = testCase.rocket.motor.cutoffTime; + testCase.coefficients = testCase.rocket.coefficients; + + end + end + + methods (Static) - function saveTest(testCase) + function saveTest(mission, vars, t, alpha, mach, beta, alt, c) currentPath = fileparts(mfilename('fullpath')); - cd(currentPath); addpath(genpath(currentPath)); + cmnfnctnPath = fullfile(currentPath, 'data', 'testCommonFunctions'); totTime = tic; disp('Started saving common functions tests'); + + rocket = Rocket(mission); + vars.xcg = rocket.xCg; + cutoffTime = rocket.motor.cutoffTime; + coefficients = rocket.coefficients; % coefficient interpolation interpCoeffsTime = tic; - [refCoeffsValue, refAngles] = interpCoeffs(testCase.rocket.coefficients, ... - testCase.t, testCase.rocket.motor.cutoffTime, testCase.alpha, testCase.mach, testCase.beta, testCase.alt, testCase.c); + [refCoeffsValue, refAngles] = interpCoeffs(coefficients, ... + t, cutoffTime, alpha, mach, beta, alt, c); - save('data/testCommonFunctions/interpCoeffs/refCoeffsValue','refCoeffsValue'); - save('data/testCommonFunctions/interpCoeffs/refAngles','refAngles'); + save(fullfile(cmnfnctnPath, 'interpCoeffs', 'refInterpCoeffs'), 'refCoeffsValue', 'refAngles', ... + 'mission', 'rocket', 't', 'alpha', 'mach', 'beta', 'alt', 'c'); interpCoeffsTime = toc(interpCoeffsTime); fprintf('\tInterpCoeffs test created in: %2.2f seconds\n', interpCoeffsTime); @@ -64,9 +75,9 @@ classdef TestCommonFunctions < UnitTest % create dissile input createDissileInputTime = tic; - [refInput] = createDissileInput(testCase.rocket, testCase.vars); + [refInput] = createDissileInput(rocket, vars); - save('data/testCommonFunctions/createDissileInput/refInputValue','refInput'); + save(fullfile(cmnfnctnPath, 'createDissileInput', 'refInput'), 'refInput', 'mission', 'rocket', 'vars'); createDissileInputTime = toc(createDissileInputTime); fprintf('\createDissileInput test created in: %2.2f seconds\n', createDissileInputTime); @@ -82,26 +93,28 @@ classdef TestCommonFunctions < UnitTest methods (Test) function interpCoeffs(testCase) % interpCoeffs - addpath(genpath('../../common/functions')); + cmnfnctnPath = fullfile('..', 'common', 'functions'); + addpath(genpath(cmnfnctnPath)); - coeffs = testCase.rocket.coefficients; - cutoffTime = testCase.rocket.motor.cutoffTime; + testCase.createTest(); - [testCase.coeffsValue, testCase.angles] = interpCoeffs(coeffs, ... - testCase.t, cutoffTime, testCase.alpha, testCase.mach, testCase.beta, testCase.alt, testCase.c); + [coeffsValue, angles] = interpCoeffs(testCase.coefficients, ... + testCase.t, testCase.cutoffTime, testCase.alpha, testCase.mach, testCase.beta, testCase.alt, testCase.c); - - testCase.verifyEqual(testCase.coeffsValue, testCase.referenceCoeffsValue); - testCase.verifyEqual(testCase.angles, testCase.referenceAngles); + testCase.verifyEqual(coeffsValue, testCase.refCoeffsValue); + testCase.verifyEqual(angles, testCase.refAngles); end function createDissileInput(testCase) % createDissileInput - addpath(genpath('../../common/functions')); + cmnfnctnPath = fullfile('..', 'common', 'functions'); + addpath(genpath(cmnfnctnPath)); + + testCase.createTest(); - [testCase.testInput] = createDissileInput(testCase.rocket, testCase.vars); + [testInput] = createDissileInput(testCase.rocket, testCase.vars); - testCase.verifyEqual(testCase.testInput, testCase.referenceInputValue); + testCase.verifyEqual(testInput, testCase.refInputValue); end end end \ No newline at end of file diff --git a/unitTests/unitTestClasses/TestSensitivity.m b/unitTests/unitTestClasses/TestSensitivity.m index e143cfc2..e3a1f694 100644 --- a/unitTests/unitTestClasses/TestSensitivity.m +++ b/unitTests/unitTestClasses/TestSensitivity.m @@ -1,103 +1,72 @@ classdef TestSensitivity < UnitTest + + % NON FUNZIONANTE, testCase.sensitivitySettings must be of type Settings or be convertible to Settings. properties - sensitivity struct - referenceSensitivity struct - postp struct + refSensitivity + sensitivitySettings end methods function createTest(testCase) currentPath = fileparts(mfilename('fullpath')); - cd(currentPath); - ref = load("data\testSensitivityAnalysis\refSensitivity.mat", "refSensitivity"); + addpath(genpath(currentPath)); + filePath = fullfile('data', 'testSensitivityAnalysis', 'refSensitivity'); - testCase.referenceSensitivity = ref.refSensitivity; + testCase.refSensitivity = load(filePath).refSensitivity; + testCase.sensitivitySettings = load(filePath).sensitivitySettings; - %% SIMULATION PARAMETERS - testCase.sensitivity = struct(); - testCase.sensitivity.n = 300; % Number of cases - testCase.sensitivity.type = 4; - % Simulation type: - % 1-apogee only - % 2-ballistic descent - % 3-parachute descent - % 4-both ballistic and parachute descent - % 5-stability - % 6-launch mode - - %% FLAGS - testCase.sensitivity.parafoil = false; - testCase.sensitivity.parThreads = false; - - %% PLOTS - testCase.sensitivity.plots.enabled = true; - testCase.sensitivity.plots.geoPlots = true; - testCase.sensitivity.plots.ASDFormat = false; - testCase.sensitivity.plots.internalStress = false; - testCase.sensitivity.plots.confidence = [0.65 0.90]; - - % Settings for geoPlots - testCase.sensitivity.plots.offlineMap = false; - testCase.sensitivity.plots.zoomLevel = 15; - testCase.sensitivity.plots.offlineMapMargin = 10; - testCase.sensitivity.plots.offlineMapLimits = [41.8151, 41.8421; % Map corner coordinates [latNorth, latSouth; - 14.0123, 14.0129]; % lonNorth, lonSouth] - - %% UNCERTANTY PARAMETERS - testCase.sensitivity.parameters = []; - - testCase.sensitivity.parameters = createParameter("CA", 4, 1, -0.2, 0, testCase.sensitivity.parameters); - testCase.sensitivity.parameters = createParameter("thrust", 4, 1, -0.1, 0.1, testCase.sensitivity.parameters); - testCase.sensitivity.parameters = createParameter("rocketStructMass", 3, 1, -0.75, 0.75, testCase.sensitivity.parameters); - testCase.sensitivity.parameters = createParameter("omega", 1, 1, 83*pi/180, 85*pi/180, testCase.sensitivity.parameters); - testCase.sensitivity.parameters = createParameter("phi", 1, 1, 159.5*pi/180, 161.5*pi/180, testCase.sensitivity.parameters); + testCase.rocket = load(filePath, 'rocket').rocket; + testCase.environment = load(filePath, 'environment').environment; + testCase.wind = load(filePath, 'wind').wind; end - - function saveTest(testCase) + end + + methods (Static) + function saveTest(mission) totTime = tic; + + currentPath = fileparts(mfilename('fullpath')); + addpath(genpath(currentPath)); + folderPath = fullfile(currentPath, 'data', 'testSensitivityAnalysis'); + configPath = fullfile(folderPath, 'refSensitivity,m'); disp('Started saving sensitivity analysis tests') - currentPath = fileparts(mfilename('fullpath')); - cd(currentPath); - addpath(genpath(currentPath)); + rocket = Rocket(mission); + environment = Environment(mission, rocket.motor); + wind = WindCustom(mission); + + [refSensitivity] = mainSensitivity(rocket, wind, environment); - refSensitivity = struct(); - [refSensitivity.Asc, refSensitivity.DescentPara, refSensitivity.DescentBall, ... - refSensitivity.Stab, refSensitivity.LaunchMode] = mainSensitivity( ... - testCase.rocket, testCase.wind, testCase.environment); + sensitivitySettings = Settings('sensitivity'); - refSensitivity.parameters = testCase.sensitivity.parameters; + if ~exist(folderPath, "dir") + mkdir(folderPath) + end - save("data\testSensitivityAnalysis\refSensitivity.mat" ... - , "refSensitivity"); + save(configPath, "refSensitivity", 'sensitivitySettings', 'rocket', 'environment', 'wind'); time = toc(totTime); + close all clearvars -except opt paths time fprintf('Sensitivity analysis tests created in: %2.2f seconds\n\n', time) end end methods (Test) - - function testParameters(testCase) - testCase.verifyEqual(testCase.referenceSensitivity.parameters, testCase.sensitivity.parameters); - end - function sensitivityAnalysis(testCase) - addpath(genpath('../../common/functions')) - addpath(genpath('../../sensitivityAnalysis')) + testCase.createTest(); + + mainSensPath = fullfile('..', 'sensitivityAnalysis'); + addpath(mainSensPath); - %% check analysis - [post.Asc, post.DescentPara, post.DescentBall, post.Stab, post.LaunchMode] ... - = mainSensitivity(testCase.rocket, testCase.wind, testCase.environment); - - testCase.postp = post; + % check analysis + [postp] = mainSensitivity(testCase.rocket, testCase.wind, testCase.environment, testCase.sensitivitySettings); - testCase.referenceSensitivity = rmfield(testCase.referenceSensitivity, 'parameters'); + close all; - testCase.verifyEqual(testCase.postp, testCase.referenceSensitivity, 'AbsTol', testCase.absToll, ... + testCase.verifyEqual(postp, testCase.refSensitivity, 'AbsTol', testCase.absToll, ... 'RelTol', testCase.relToll); % check = obj.checkError(postp, referenceSensitivity, obj.toll); diff --git a/unitTests/unitTestClasses/TestSimulator.m b/unitTests/unitTestClasses/TestSimulator.m index f67ebf7e..d36cb949 100644 --- a/unitTests/unitTestClasses/TestSimulator.m +++ b/unitTests/unitTestClasses/TestSimulator.m @@ -1,7 +1,10 @@ classdef TestSimulator < UnitTest + % TEST FUNZIONANTE, DA RISOLVERE PATH PER simulatorConfig.m in saveTest + % MANCA refSolid + properties - simulatorSettings struct % [-] + simulatorSettings refSimulator end @@ -9,86 +12,83 @@ classdef TestSimulator < UnitTest verifiable = {'multipleAB', 'ballistic', 'engineCut', 'solid', 'HRE'}; end + methods + function createTest(testCase, verifiable) + currentPath = fileparts(mfilename('fullpath')); + addpath(genpath(currentPath)); - methods (Static) - function runSelectedTests(selectedParams) - if nargin < 1 || isempty(selectedParams) - selectedParams = {'multipleAB', 'ballistic', 'engineCut', 'solid', 'HRE'}; - fprintf('\t Running tests with default parameters\n'); - else - fprintf('\t Running tests with selected parameters: %s\n', strjoin(selectedParams, ', ')); - end - params = matlab.unittest.parameters.Parameter.fromData("Data",selectedParams); - suite = matlab.unittest.TestSuite.fromClass(?TestSimulator, 'ExternalParameters', params); - results = run(suite); - disp(results); + fileName = sprintf("referenceState_%s.mat", verifiable); + filePath = fullfile('data', 'testSimulator', verifiable, fileName); + + % Load the reference file + testCase.rocket = load(filePath, 'rocket').rocket; + testCase.environment = load(filePath, 'environment').environment; + testCase.wind = load(filePath, 'wind').wind; + + % fieldName = ['referenceState_' verifiable]; + testCase.refSimulator.stateA = load(filePath).stateA; + testCase.refSimulator.stateF = load(filePath).stateF; + + testCase.simulatorSettings = load(filePath).simulatorSettings; + + % Construct the file path dynamically based on the test parameter end end - methods - function saveTest(testCase, verifiable, mission) + + + methods (Static) + function saveTest(verifiable, mission) Time = tic; + + disp('Started saving simulator tests') + + mainSimPath = fullfile('..', '..', 'simulator'); + addpath(genpath(mainSimPath)); + currentPath = fileparts(mfilename('fullpath')); + addpath(genpath(currentPath)); + rocket = Rocket(mission); environment = Environment(mission, rocket.motor); wind = WindCustom(mission); % simulator - [ascent, descent, testCase.simulatorSettings] = mainSimulator(rocket, wind, environment); + [stateA, stateF] = mainSimulator(rocket, wind, environment); + + configPath = fullfile(currentPath, mainSimPath, 'simulator'); + + simulatorSettings = Settings(fullfile(configPath), 'simulator'); % Save final state fileName = sprintf("referenceState_%s.mat", verifiable); - folderPath = fullfile('data', 'testSimulator', verifiable); + folderPath = fullfile(currentPath, 'data', 'testSimulator', verifiable); filePath = fullfile(folderPath, fileName); if ~exist(folderPath, "dir") mkdir(folderPath) end - save(filePath,'stateA','stateF', 'testCase.simulatorSettings',... - 'mission', 'rocket',... - 'environment', 'wind'); + save(filePath,'stateA','stateF', 'simulatorSettings',... + 'mission', 'rocket', 'environment', 'wind'); + + close all; Time = toc(Time); fprintf('\t %s test created in: %2.2f seconds\n',verifiable, Time) - end - - function createTestSimulator(testCase, verifiable) - - - currentPath = fileparts(mfilename('fullpath')); - addpath(currentPath); - - fileName = sprintf("referenceState_%s.mat", verifiable); - filePath = fullfile('data', 'testSimulator', verifiable, fileName); - - % Load the reference file - 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) - - testCase.createTestSimulator(verifiable); + testCase.createTest(verifiable); mainSimPath = fullfile('..', 'simulator'); - addpath(mainSimPath); + addpath(genpath(mainSimPath)); % Run main simulator - [postp.stateA, postp.stateF, ~] = mainSimulator(testCase.rocket, testCase.wind, testCase.environment); - postp.stateA = postp.stateA(end, :); - postp.stateF = postp.stateF(end, :); + [postp.stateA, postp.stateF] = mainSimulator(testCase.rocket, testCase.wind, testCase.environment, testCase.simulatorSettings); + + close all; % Verify results testCase.verifyEqual(postp, testCase.refSimulator, 'AbsTol', testCase.absToll, 'RelTol', testCase.relToll); diff --git a/unitTests/unitTestClasses/configUnitTest.m b/unitTests/unitTestClasses/configUnitTest.m index 2713265a..4360727f 100644 --- a/unitTests/unitTestClasses/configUnitTest.m +++ b/unitTests/unitTestClasses/configUnitTest.m @@ -1,5 +1,8 @@ % config unit-test +% choose the mission +mission = Mission("2024_Lyra_Portugal_October"); + %% UNIT TESTS TO RUN % choose which folders to test opt.testSimulator = true; diff --git a/unitTests/unitTestClasses/data/testApogeeAnalysis/engineCutApogee/refEngineCut.mat b/unitTests/unitTestClasses/data/testApogeeAnalysis/engineCutApogee/refEngineCut.mat index 828f4ebc..1bb29b4a 100644 --- a/unitTests/unitTestClasses/data/testApogeeAnalysis/engineCutApogee/refEngineCut.mat +++ b/unitTests/unitTestClasses/data/testApogeeAnalysis/engineCutApogee/refEngineCut.mat @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:29ddc1cb16d6dd98cf5099d8c78af70c8e802eccdbd9b2d55ca73a5bd432af72 -size 726 +oid sha256:41d3a3832118fca2c05ace1d5dd5fa0ec4c9a7ef3576fc03f95b57ae851e2b70 +size 50239924 diff --git a/unitTests/unitTestClasses/data/testApogeeAnalysis/standardApogee/refStandard.mat b/unitTests/unitTestClasses/data/testApogeeAnalysis/standardApogee/refStandard.mat index bdc5e407..46298514 100644 --- a/unitTests/unitTestClasses/data/testApogeeAnalysis/standardApogee/refStandard.mat +++ b/unitTests/unitTestClasses/data/testApogeeAnalysis/standardApogee/refStandard.mat @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c5e51f3a573a55c2d86cb9a97f49d486983f557cdcc7e692b219b1e2146281be -size 3795 +oid sha256:db8c120bd70067997757b646cea03fbc7ddc66dab1b1683b7a63c97a6bcc0dee +size 50241818 diff --git a/unitTests/unitTestClasses/data/testCommonFunctions/createDissileInput/refInput.mat b/unitTests/unitTestClasses/data/testCommonFunctions/createDissileInput/refInput.mat new file mode 100644 index 00000000..3fd348ff --- /dev/null +++ b/unitTests/unitTestClasses/data/testCommonFunctions/createDissileInput/refInput.mat @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:78751fa078977dcf31f20f4208cd33661834932485747e7901d74965f545c48a +size 50211135 diff --git a/unitTests/unitTestClasses/data/testCommonFunctions/createDissileInput/refInputValue.mat b/unitTests/unitTestClasses/data/testCommonFunctions/createDissileInput/refInputValue.mat deleted file mode 100644 index e47a361d..00000000 --- a/unitTests/unitTestClasses/data/testCommonFunctions/createDissileInput/refInputValue.mat +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:5b3395ba396e4eeccde58350f3aa3afee96f1edf5940ad20cd98cb3bc93cbe12 -size 8402 diff --git a/unitTests/unitTestClasses/data/testCommonFunctions/interpCoeffs/refInterpCoeffs.mat b/unitTests/unitTestClasses/data/testCommonFunctions/interpCoeffs/refInterpCoeffs.mat new file mode 100644 index 00000000..a3430959 --- /dev/null +++ b/unitTests/unitTestClasses/data/testCommonFunctions/interpCoeffs/refInterpCoeffs.mat @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9a4c6be7f76a0f3d988a734258b4f4eaa58a4f9b00279630482e7471793621ff +size 50202726 diff --git a/unitTests/unitTestClasses/data/testCommonFunctions/refInterpCoeffs.mat b/unitTests/unitTestClasses/data/testCommonFunctions/refInterpCoeffs.mat new file mode 100644 index 00000000..e4f6f0ac --- /dev/null +++ b/unitTests/unitTestClasses/data/testCommonFunctions/refInterpCoeffs.mat @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ac059678dbc394536a279f7a26dd5be98899d06e3971aadeb5862c17c5223be4 +size 50202726 diff --git a/unitTests/unitTestClasses/data/testSensitivityAnalysis/refSensitivity.mat b/unitTests/unitTestClasses/data/testSensitivityAnalysis/refSensitivity.mat index e22e6128..dc89c438 100644 --- a/unitTests/unitTestClasses/data/testSensitivityAnalysis/refSensitivity.mat +++ b/unitTests/unitTestClasses/data/testSensitivityAnalysis/refSensitivity.mat @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:029d2ae81a4df579fd162bc4df3f1b3f3c01be74d619156b646dd43f837d55d5 -size 10055 +oid sha256:bec9a396baa955f6fd2d21639fdac82e82d4cdf5b7b3ddf21fef1cf37110c4d8 +size 51425920 diff --git a/unitTests/unitTestClasses/data/testSimulator/HRE/referenceState_HRE.mat b/unitTests/unitTestClasses/data/testSimulator/HRE/referenceState_HRE.mat index 1c4310d9..12b1c78d 100644 --- a/unitTests/unitTestClasses/data/testSimulator/HRE/referenceState_HRE.mat +++ b/unitTests/unitTestClasses/data/testSimulator/HRE/referenceState_HRE.mat @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:dfe2a3dae2e4eb59ec1ff106b40df8197ed5ff6cf4471a57dab2ae8978d96f6c -size 67486352 +oid sha256:64b1a57785c5010effbcd86848c436686ec4f46217dedb8bef14263a28ae9600 +size 51412338 diff --git a/unitTests/unitTestClasses/data/testSimulator/ballistic/referenceState_ballistic.mat b/unitTests/unitTestClasses/data/testSimulator/ballistic/referenceState_ballistic.mat index 73716da9..75f24828 100644 --- a/unitTests/unitTestClasses/data/testSimulator/ballistic/referenceState_ballistic.mat +++ b/unitTests/unitTestClasses/data/testSimulator/ballistic/referenceState_ballistic.mat @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:dcdf9f8da6ad8f647f3737db81e11b91d63039a13cc27197491af9dbac4b73ca -size 67499806 +oid sha256:fa392951ca33d4ab333e03664996c805215c8aa50ea1771b44cbcec97c4fbc5b +size 51461215 diff --git a/unitTests/unitTestClasses/data/testSimulator/engineCut/referenceState_engineCut.mat b/unitTests/unitTestClasses/data/testSimulator/engineCut/referenceState_engineCut.mat index 56b75241..ccc82ffa 100644 --- a/unitTests/unitTestClasses/data/testSimulator/engineCut/referenceState_engineCut.mat +++ b/unitTests/unitTestClasses/data/testSimulator/engineCut/referenceState_engineCut.mat @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:edc8a840bc0af6915ba8e94ac67f30e45f0e53744a25131fd2491411005a7bfb -size 67486352 +oid sha256:a9bf532733ce28926f48eb93aa3f108c35f8672745586cd3004d62b96c4ecc2d +size 51346297 diff --git a/unitTests/unitTestClasses/data/testSimulator/multipleAB/referenceState_multipleAB.mat b/unitTests/unitTestClasses/data/testSimulator/multipleAB/referenceState_multipleAB.mat index 5989730a..edcd85c4 100644 --- a/unitTests/unitTestClasses/data/testSimulator/multipleAB/referenceState_multipleAB.mat +++ b/unitTests/unitTestClasses/data/testSimulator/multipleAB/referenceState_multipleAB.mat @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:0ec631c8b56cbbaa75ed68a7e488408ebad1c4558a1d4f57ad1c45433b43518a -size 67486953 +oid sha256:353e173b54c360b7ae40384cb84823dde1fa20be6f6ab9c4bcb49e24ae553798 +size 51414505 diff --git a/unitTests/unitTestClasses/mainUnitTest.m b/unitTests/unitTestClasses/mainUnitTest.m index 3be54ada..9a310473 100644 --- a/unitTests/unitTestClasses/mainUnitTest.m +++ b/unitTests/unitTestClasses/mainUnitTest.m @@ -1,8 +1,6 @@ % main unit-test currentPath = fileparts(mfilename('fullpath')); -cd (currentPath); - addpath(genpath(currentPath)); configUnitTest; @@ -10,35 +8,34 @@ configUnitTest; %% TESTS beginTest = tic; - if opt.testCommonFunction test = TestCommonFunctions(); - test.createTest; testcmnfnctResults = run(test); + disp(testcmnfnctResults); end if opt.testApogeeAnalysis test = TestApogeeAnalysis(); - test.createTest; apoResults = run(test); + disp(apoResults); end if opt.testOptimization test = TestOptimization(); - test.createTest; optResults = run(test); + disp(optResults); end if opt.testSensitivity test = TestSensitivity(); - test.createTest; sensResults = run(test); + disp(sensResults); end if opt.testSimulator test = TestSimulator(); - test.runSelectedTests({}); + simResults = run(test); + disp(simResults); end - toc(beginTest) \ No newline at end of file diff --git a/unitTests/unitTestClasses/saveTests.m b/unitTests/unitTestClasses/saveTests.m index 2992b116..f0be2f42 100644 --- a/unitTests/unitTestClasses/saveTests.m +++ b/unitTests/unitTestClasses/saveTests.m @@ -1,8 +1,6 @@ % save tests -filePath = fileparts(mfilename('fullpath')); -addpath(genpath(filePath)) - +currentPath = fileparts(mfilename('fullpath')); addpath(genpath(currentPath)); configUnitTest; @@ -11,38 +9,30 @@ totTime = tic; %% CREATING SIMULATOR TESTS if opt.createTestSimulator - test = TestSimulator(); - test.saveTest(); + verifiable = 'HRE'; + TestSimulator.saveTest(verifiable, mission); end %% TEST COMMONFUNCTIONS if opt.createTestCommonFunction - test = TestCommonFunctions(); - test.saveTest(); + TestCommonFunctions.saveTest(mission); end %% TEST APOGEE ANALYSIS if opt.createTestApogeeAnalysis - test = TestApogeeAnalysis(); - test.saveTest(); + TestApogeeAnalysis.saveTest(mission); end %% SENSITIVITY ANALYSIS if opt.createTestSensitivity - test = TestSensitivity(); - test.saveTest(); + TestSensitivity.saveTest(mission); end %% OPTIMIZATION if opt.createTestOptimization - test = TestOptimization(); - test.saveTest(); + TestOptimization.saveTest(mission); end -if opt.createTestSimulator - test = TestSimulator(); - test.saveTest -end totTimeF = toc(totTime); fprintf('\n\n All unit tests created in: %2.2f seconds\n\n', totTimeF) -- GitLab