Files
imdd_silas/Tests/generateTests.m
2026-03-12 17:26:13 +01:00

48 lines
1.5 KiB
Matlab

function generateTests()
if ismac
cd('/Users/silasoettinghaus/Documents/MATLAB/imdd_simulation');
else
cd('C:\Users\Silas\Documents\MATLAB\imdd_simulation');
end
% Define the root folders for classes and tests
classesFolder = 'Classes'; % Folder containing the class files
testsFolder = 'Tests'; % Folder where test files should be created
% Create the Test folder if it doesn't exist
if ~exist(testsFolder, 'dir')
mkdir(testsFolder);
end
% Get all .m files in the Classes folder and its subfolders
classFiles = dir(fullfile(pwd,classesFolder, '**', '*.m'));
% Iterate over all class files
for i = 1:length(classFiles)
classFilePath = fullfile(classFiles(i).folder, classFiles(i).name);
[~, className, ~] = fileparts(classFilePath);
% Create corresponding test file name
testFileName = [className, '_test.m'];
testFilePath = strrep(classFilePath, classesFolder, testsFolder); % Replace folder
testFilePath = fullfile(fileparts(testFilePath), testFileName); % Append test filename
% Check if the test file already exists
if ~exist(testFilePath, 'file')
% Create the test subfolder if it doesn't exist
testSubFolder = fileparts(testFilePath);
if ~exist(testSubFolder, 'dir')
mkdir(testSubFolder);
end
% Write the skeleton test file
createTestFile(className, testFilePath);
end
end
addpath(genpath(testsFolder))
end