Skip to content

Commit

Permalink
Format check (#677)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvanzulli authored and jorgepz committed Dec 23, 2024
1 parent a3eb75e commit 0fd7926
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 126 deletions.
12 changes: 1 addition & 11 deletions miss_hit.cfg
Original file line number Diff line number Diff line change
@@ -1,44 +1,34 @@
# Style guide configuration for MISS_HIT
# Reference: https://florianschanda.github.io/miss_hit/style_checker.html

# Format check parameters:
# Maximum allowed length for a single line of code (in characters)
# Helps maintain code readability without unnecessary horizontal scrolling.
line_length: 200

# Number of spaces a single tab corresponds to
# Ensures consistent indentation throughout the codebase.
tab_width: 2

# Regular expression for function names
# Enforces CamelCase naming convention: each word starts with an uppercase letter, no underscores.
regex_function_name: "[A-Z][a-zA-Z0-9]*"

# Regular expression for script file names
# Enforces CamelCase naming convention for file names: no spaces, starts with an uppercase letter.
regex_script_name: "[A-Z][a-zA-Z0-9]*"

# Regular expression for parameter (variable) names
# Enforces snake_case naming for function parameters (unchanged for clarity and consistency).
regex_parameter_name: "[a-zA-Z]+(_[a-zA-Z]+)*"

# Copyright owner entity
# Adds a copyright notice with the specified entity name.
copyright_entity: "ONSAS"

# Metrics for code quality

# "cnest" (Control Nesting Depth): Maximum allowed nesting level of control structures (e.g., loops, conditionals)
# Helps reduce code complexity and improve maintainability.
metric "cnest": limit 6

# "file_length": Maximum allowed number of lines in a single file
# Keeps files manageable and easier to navigate.
metric "file_length": limit 1000

# "cyc" (Cyclomatic Complexity): Maximum allowed complexity of a single function
# A lower value ensures that functions remain simple and focused.
metric "cyc": limit 35

# "parameters": Maximum allowed number of parameters for a single function
# Encourages simpler function signatures and improves readability.
metric "parameters": limit 7
60 changes: 31 additions & 29 deletions test/gaussIntegrationTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,55 @@

function resultBoolean = gaussIntegrationTest()

addpath( genpath( [ pwd filesep '..' filesep 'src'] ));
addpath(genpath([pwd filesep '..' filesep 'src']));

plots_boolean = true ;
plots_boolean = true;

point_nums_to_test = [ 1:10 12 14 16 28 ] ;
% point_nums_to_test = [ 1:10 ]
int_values = zeros( size(point_nums_to_test) ) ;
point_nums_to_test = [1:10 12 14 16 28];
% point_nums_to_test = [ 1:10 ]
int_values = zeros(size(point_nums_to_test));

a = -1.5 ; b = 1 ;
%analyInt = -50*.5 + -50*1*.5 + 100*.5*.5 + 100*.5 ;
analyInt = 20 * ( b^5/5 - a^5/5 ) ;
a = -1.5;
b = 1;
% analyInt = -50*.5 + -50*1*.5 + 100*.5*.5 + 100*.5 ;
analyInt = 20 * (b^5 / 5 - a^5 / 5);

xs = -1.5:.02:1;
ys = 0;
for i=1:length(xs)
for i = 1:length(xs)
ys(i) = test_fun_to_integrate(xs(i));
end

if plots_boolean
figure
plot( xs, ys, 'g-x' )
title('test_fun_to_integrate')
figure;
plot(xs, ys, 'g-x');
title('test_fun_to_integrate');
end

for j=1:length( point_nums_to_test)
[xIntPoints, wIntPoints] = gaussPointsAndWeights ( point_nums_to_test(j) ) ;
for j = 1:length(point_nums_to_test)
[xIntPoints, wIntPoints] = gaussPointsAndWeights (point_nums_to_test(j));

for k=1:length(xIntPoints)
for k = 1:length(xIntPoints)
int_values(j) = int_values(j) + ...
wIntPoints(k) * test_fun_to_integrate( (b-a)/2 * xIntPoints(k) + (a+b)/2 ) * ( (b-a) /2 ) ;
wIntPoints(k) * test_fun_to_integrate((b - a) / 2 * xIntPoints(k) + (a + b) / 2) * ((b - a) / 2);
end
end

if plots_boolean
% numericalInt = quadl( 'test_fun_to_integrate', a, b )
figure
plot(point_nums_to_test, int_values,'b-x')
hold on, grid on
plot(point_nums_to_test, analyInt*ones(size(point_nums_to_test)),'r-o')
% numericalInt = quadl( 'test_fun_to_integrate', a, b )
figure;
plot(point_nums_to_test, int_values, 'b-x');
hold on;
grid on;
plot(point_nums_to_test, analyInt * ones(size(point_nums_to_test)), 'r-o');
end

int_values(3:end)
analyInt*ones(1,length(point_nums_to_test)-2)
int_values(3:end);
analyInt * ones(1, length(point_nums_to_test) - 2);

resultBoolean = max( abs( int_values(3:end) - analyInt*ones(1,length(point_nums_to_test)-2) ) ) / abs( analyInt ) < 1e-8 ;
resultBoolean = max(abs(int_values(3:end) - analyInt * ones(1, length(point_nums_to_test) - 2))) / abs(analyInt) < 1e-8;

% ========================================================================================
% ========================================================================================
function ys = test_fun_to_integrate( xinput )
ys = 20 * xinput .^ 4 ;
% ========================================================================================
% ========================================================================================
function ys = test_fun_to_integrate(xinput)
ys = 20 * xinput.^4;
82 changes: 44 additions & 38 deletions test/runTestProblems_local.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,49 +18,53 @@
% This functions reads a text file with the norms of the forces at
% each iteration of the code execution and generates a series of plots

close all, clear all;
addpath( genpath( [ pwd filesep '..' filesep 'src' filesep ]) ); octaveBoolean = isThisOctave ;
close all;
clear all;
addpath(genpath([pwd filesep '..' filesep 'src' filesep]));
octaveBoolean = isThisOctave;

setenv('TESTS_RUN','yes')
setenv('TESTS_RUN', 'yes');

keyfiles = { ...
'addedMassPendulum/addedMassPendulum.m' ...
; 'beamLinearVibration/beamLinearVibration.m' ...
; 'beamTrussJoint/beamTrussJoint.m' ...
; 'cantileverModalAnalysis/cantileverModalAnalysis.m' ...
; 'cantileverPlate/cantileverPlate.m' ...
; 'cantileverSelfWeight/cantileverSelfWeight.m' ...
; 'dragBeamReconfiguration/dragBeamReconfiguration.m' ...
; 'eulerColumn/eulerColumn.m' ...
; 'frameLinearAnalysis/frameLinearAnalysis.m' ...
; 'linearAerodynamics/linearAerodynamics.m' ...
; 'nonLinearPendulum/nonLinearPendulum.m' ...
; 'platePatchTest/platePatchTest.m' ...
; 'ringPlaneStrain/ringPlaneStrain.m' ...
; 'simplePropeller/simplePropeller.m' ...
; 'springMass/springMass.m' ...
; 'staticVonMisesTruss/staticVonMisesTruss.m' ...
; 'staticPlasticVonMisesTruss/staticPlasticVonMisesTruss.m' ...
; 'uniaxialCompression/uniaxialCompression.m' ...
; 'uniaxialExtension/uniaxialExtension.m' ...
; 'uniformCurvatureCantilever/uniformCurvatureCantilever.m' ...
; 'VIVCantilever/VIVCantilever.m' ...
}
'addedMassPendulum/addedMassPendulum.m' ...
; 'beamLinearVibration/beamLinearVibration.m' ...
; 'beamTrussJoint/beamTrussJoint.m' ...
; 'cantileverModalAnalysis/cantileverModalAnalysis.m' ...
; 'cantileverPlate/cantileverPlate.m' ...
; 'cantileverSelfWeight/cantileverSelfWeight.m' ...
; 'dragBeamReconfiguration/dragBeamReconfiguration.m' ...
; 'eulerColumn/eulerColumn.m' ...
; 'frameLinearAnalysis/frameLinearAnalysis.m' ...
; 'linearAerodynamics/linearAerodynamics.m' ...
; 'nonLinearPendulum/nonLinearPendulum.m' ...
; 'platePatchTest/platePatchTest.m' ...
; 'ringPlaneStrain/ringPlaneStrain.m' ...
; 'simplePropeller/simplePropeller.m' ...
; 'springMass/springMass.m' ...
; 'staticVonMisesTruss/staticVonMisesTruss.m' ...
; 'staticPlasticVonMisesTruss/staticPlasticVonMisesTruss.m' ...
; 'uniaxialCompression/uniaxialCompression.m' ...
; 'uniaxialExtension/uniaxialExtension.m' ...
; 'uniformCurvatureCantilever/uniformCurvatureCantilever.m' ...
; 'VIVCantilever/VIVCantilever.m' ...
};

current = 1 ; verifBoolean = 1 ; testDir = pwd ;
current = 1;
verifBoolean = 1;
testDir = pwd;

num_tests = length(keyfiles) ;
num_tests = length(keyfiles);
while (current <= num_tests) && (verifBoolean == 1)

% run current example
fprintf([' === running script: ' keyfiles{current} '\n' ]);
fprintf([' === running script: ' keyfiles{current} '\n']);

aux_time = cputime();

% save key files data to avoid clear all commands
save( '-mat', 'exData.mat', 'current', 'keyfiles', 'testDir', 'aux_time' );
save('-mat', 'exData.mat', 'current', 'keyfiles', 'testDir', 'aux_time');

run( [ pwd filesep '..' filesep 'examples' filesep keyfiles{current} ] ) ;
run([pwd filesep '..' filesep 'examples' filesep keyfiles{current}]);

if verifBoolean
status = 'PASSED';
Expand All @@ -69,19 +73,21 @@
end

% reload key files data and increment current
load('exData.mat') ; num_tests = length(keyfiles) ;
load('exData.mat');
num_tests = length(keyfiles);

aux_time = cputime() - aux_time ; keyfiles{current,2} = aux_time ;
aux_time = cputime() - aux_time;
keyfiles{current, 2} = aux_time;

fprintf([' === test problem %2i: %s in %8.1e s === \n\n'], current, status, aux_time );
fprintf([' === test problem %2i: %s in %8.1e s === \n\n'], current, status, aux_time);

current = current + 1 ;
current = current + 1;
delete('exData.mat');
cd ( testDir )
cd (testDir);
end

if verifBoolean ==1
fprintf('all test examples PASSED!\n')
if verifBoolean == 1
fprintf('all test examples PASSED!\n');
else
error('test examples not passed.')
error('test examples not passed.');
end
96 changes: 48 additions & 48 deletions test/runTestProblems_moxunit_disp.m
Original file line number Diff line number Diff line change
@@ -1,101 +1,101 @@
% function for testing ONSAS using moxunit
% ----------------------------------------
function test_suite=runTestProblems_moxunit_disp
function test_suite = runTestProblems_moxunit_disp
% initialize tests
try
test_functions=localfunctions()
test_functions = localfunctions();
catch
end

% set auxiliar environment variable
setenv('TESTS_RUN', 'yes')
setenv('TESTS_RUN', 'yes');

% initialize the MOxUnit test suite
initTestSuite;

function test_1
beamLinearVibration
assertEqual( verifBoolean, true );
beamLinearVibration;
assertEqual(verifBoolean, true);

function test_2
cantileverModalAnalysis
assertEqual( verifBoolean, true );
cantileverModalAnalysis;
assertEqual(verifBoolean, true);

function test_3
cantileverSelfWeight
assertEqual( verifBoolean, true );
cantileverSelfWeight;
assertEqual(verifBoolean, true);

function test_4
dragBeamReconfiguration
assertEqual( verifBoolean, true );
dragBeamReconfiguration;
assertEqual(verifBoolean, true);

function test_5
eulerColumn
assertEqual( verifBoolean, true );
eulerColumn;
assertEqual(verifBoolean, true);

function test_6
frameLinearAnalysis
assertEqual( verifBoolean, true );
frameLinearAnalysis;
assertEqual(verifBoolean, true);

function test_7
linearAerodynamics
assertEqual( verifBoolean, true );
linearAerodynamics;
assertEqual(verifBoolean, true);

function test_8
ringPlaneStrain
assertEqual( verifBoolean, true );
ringPlaneStrain;
assertEqual(verifBoolean, true);

function test_9
nonLinearPendulum
assertEqual( verifBoolean, true );
nonLinearPendulum;
assertEqual(verifBoolean, true);

function test_10
springMass
assertEqual( verifBoolean, true );
springMass;
assertEqual(verifBoolean, true);

function test_11
simplePropeller
assertEqual( verifBoolean, true );
simplePropeller;
assertEqual(verifBoolean, true);

function test_12
staticVonMisesTruss
assertEqual( verifBoolean, true );
staticVonMisesTruss;
assertEqual(verifBoolean, true);

function test_13
uniaxialCompression
assertEqual( verifBoolean, true );
uniaxialCompression;
assertEqual(verifBoolean, true);

function test_14
uniaxialExtension
assertEqual( verifBoolean, true);
uniaxialExtension;
assertEqual(verifBoolean, true);

function test_15
uniformCurvatureCantilever
assertEqual( verifBoolean, true);
function test_15
uniformCurvatureCantilever;
assertEqual(verifBoolean, true);

function test_16
VIVCantilever
assertEqual( verifBoolean, true );
VIVCantilever;
assertEqual(verifBoolean, true);

function test_17
beamTrussJoint
assertEqual( verifBoolean, true );
beamTrussJoint;
assertEqual(verifBoolean, true);

function test_18
staticPlasticVonMisesTruss
assertEqual( verifBoolean, true );
staticPlasticVonMisesTruss;
assertEqual(verifBoolean, true);

function test_19
platePatchTest
assertEqual( verifBoolean, true );
platePatchTest;
assertEqual(verifBoolean, true);

function test_20
cantileverPlate
assertEqual( verifBoolean, true );
cantileverPlate;
assertEqual(verifBoolean, true);

function test_21
addedMassPendulum
assertEqual( verifBoolean, true );
addedMassPendulum;
assertEqual(verifBoolean, true);

function test_22
assertEqual( gaussIntegrationTest, true);
assertEqual(gaussIntegrationTest, true);

0 comments on commit 0fd7926

Please sign in to comment.