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

[unit-test][unitTestClasses] Updated unitTests

- Move unit test classes to the root of the unitTests folder
- Updated the paths in the unit test scripts
- Working TestSimulator
parent 5863375f
No related branches found
No related tags found
1 merge request!12Unit test
Showing
with 61 additions and 90 deletions
......@@ -4,41 +4,17 @@ classdef TestSimulator < UnitTest
% MANCA refSolid
properties
simulatorSettings
SimulatorSettings Settings % [-]
refSimulator
end
properties (TestParameter)
verifiable = {'multipleAB', 'ballistic', 'engineCut', 'solid', 'HRE'};
verifiable = {'multipleAB', 'ballistic', 'engineCut', 'HRE'};
end
methods
function createTest(testCase, verifiable)
currentPath = fileparts(mfilename('fullpath'));
addpath(genpath(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.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 (Static)
function saveTest(verifiable, mission)
methods
function saveTest(testCase, testName, mission)
Time = tic;
disp('Started saving simulator tests')
......@@ -51,30 +27,60 @@ classdef TestSimulator < UnitTest
rocket = Rocket(mission);
environment = Environment(mission, rocket.motor);
wind = WindCustom(mission);
mainSimPath = fullfile('..', 'simulator', 'simulatorConfig.m');
mainOdePath = fullfile('..', 'common', 'settings', 'odeConfig.m');
SimulatorSettings = Settings(mainSimPath, mainOdePath);
SimulatorSettings.simulator.SMonly = 0;
if strcmp(testName, 'ballistic')
SimulatorSettings.simulator.ballistic = 1;
SimulatorSettings.simulator.parafoil = 0;
end
% simulator
[stateA, stateF] = mainSimulator(rocket, wind, environment);
configPath = fullfile(currentPath, mainSimPath, 'simulator');
simulatorSettings = Settings(fullfile(configPath), 'simulator');
% simulator
[ascent, descent] = mainSimulator(rocket, wind, environment, SimulatorSettings);
stateA = ascent(end, :);
stateF = descent(end, :);
% Save final state
fileName = sprintf("referenceState_%s.mat", verifiable);
folderPath = fullfile(currentPath, 'data', 'testSimulator', verifiable);
fileName = sprintf("referenceState_%s.mat", testName);
folderPath = fullfile('data', 'testSimulator', testName);
filePath = fullfile(folderPath, fileName);
if ~exist(folderPath, "dir")
mkdir(folderPath)
end
save(filePath,'stateA','stateF', 'simulatorSettings',...
'mission', 'rocket', 'environment', 'wind');
close all;
save(filePath,'stateA','stateF', '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',testName, 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)
......@@ -86,9 +92,9 @@ classdef TestSimulator < UnitTest
addpath(genpath(mainSimPath));
% Run main simulator
[postp.stateA, postp.stateF] = mainSimulator(testCase.rocket, testCase.wind, testCase.environment, testCase.simulatorSettings);
close all;
[postp.stateA, postp.stateF] = mainSimulator(testCase.rocket, testCase.wind, testCase.environment, testCase.SimulatorSettings);
postp.stateA = postp.stateA(end, :);
postp.stateF = postp.stateF(end, :);
% Verify results
testCase.verifyEqual(postp, testCase.refSimulator, 'AbsTol', testCase.absToll, 'RelTol', testCase.relToll);
......
File moved
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File moved
File moved
# 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:
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment