Skip to content
Snippets Groups Projects
Verified Commit dc49c400 authored by Thomas Lambert's avatar Thomas Lambert :helicopter:
Browse files

test: add test for trimtorange, fix special cases

parent c3630ad5
No related branches found
No related tags found
No related merge requests found
......@@ -10,16 +10,23 @@ function [alphaTrim, clTrim, cdTrim] = trimtorange(range, alpha, cl, cd)
narginchk(2,4);
for i = 1:size(alpha,2)
if nargin >= 3
clTrim(:,i) = cl(alpha(:,i) >= range(1) & alpha(:,i) <= range(2), i);
clTrim(:,i) = cl(alpha(:,i) >= range(1) & alpha(:,i) <= range(end), i);
if nargin == 4
cdTrim(:,i) = cd(alpha(:,i) >= range(1) & alpha(:,i) <= range(2), i);
cdTrim(:,i) = cd(alpha(:,i) >= range(1) & alpha(:,i) <= range(end), i);
else
nargoutchk(1,2);
end
else
nargoutchk(1,1);
end
alphaTrim(:,i) = alpha(alpha(:,i) >= range(1) & alpha(:,i) <= range(2), i);
alphaTrim(:,i) = alpha(alpha(:,i) >= range(1) & alpha(:,i) <= range(end), i);
end
% If impossible to trim, just return the input
if isempty(alphaTrim)
alphaTrim = alpha;
clTrim = cl;
cdTrim = cd;
end
end
\ No newline at end of file
......@@ -25,10 +25,9 @@ Each function contains a complete description in its preamble. Type `help
1. Either clone this repository or download a `.zip` version of the source code.
2. Place the `+af_tools/` folder somewhere on your Matlab Path such as:
- in you current project
- in a folder that is already in Matlab's path (e.g. `/Documents/Matlab/`).
- somewhere else, but then [explicitly add it to Matlab's Path][matlabDoc_path].
- in you current project
- in a folder that is already in Matlab's path (e.g. `/Documents/Matlab/`).
- somewhere else, but then [explicitly add it to Matlab's Path][matlabDoc_path].
#### Remark
......@@ -188,8 +187,9 @@ import af_tools.nacaairfoil
### plotpolars
Plots the following polars: $`C_l-\alpha`$, $`C_d-\alpha`$, $`C_m-\alpha`$
$`C_l/C_d-\alpha`$, $`C_l-C_d`$.
Plots the following polars: $`C_l-\alpha`$&nbsp;&nbsp;,&nbsp;&nbsp;
`C_d-\alpha`$ &nbsp;&nbsp;,&nbsp;&nbsp; $`C_m-\alpha`$&nbsp;&nbsp;,&nbsp;&nbsp;
$`C_l/C_d-\alpha`$&nbsp;&nbsp;,&nbsp;&nbsp; $`C_l-C_d`$.
```matlab
import af_tools.plotpolars
......
% TEST_TRIMTORANGE Unitary tests for the trimtorange sub-function
% Note:
% The function needs to be imported at each test, because apparently Matlab
% does not pass it from setupOnce() or setup().
% For some reasons, the whole package needs to be imported, not just the
% function under testing.
% -----
% Copyright 2022 Thomas Lambert <t.lambert@uliege.be>
% ULiege - Aeroelasticity and Experimental Aerodynamics
% Apache 2.0 License
% https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox
% ------------------------------------------------------------------------------
%% Main test function
function tests = test_trimtorange
tests = functiontests(localfunctions);
end
%% Setup and teardown
function setupOnce(testCase) % do not change function name
addpath('../.'); % Add repository to Matlab Path
addpath('./test_utils'); % Add utils to Matlab Path
% Set random number generator settings.
testCase.TestData.currentRNG = rng;
end
function teardownOnce(testCase) % do not change function name
rmpath('../.'); % Remove repository from Matlab Path
rmpath('./test_utils'); % Remove utils from Matlab Path
% Restore the random number generator settings.
s = testCase.TestData.currentRNG;
rng(s)
end
function teardown(~) % do not change function name
close all; % Close all figures that would have been openend
end
%% Arguments and error tests
function test_nargout(testCase)
% Ensure that the function throws an error too many output
import af_tools.utils.*
range = [-5;5];
dummy = -10:10;
[~, ~] = verifyError(testCase, @() trimtorange(range, dummy), 'MATLAB:nargoutchk:tooManyOutputs');
[~, ~, ~] = verifyError(testCase, @() trimtorange(range, dummy, dummy), 'MATLAB:nargoutchk:tooManyOutputs');
end
%% Test for correct output
function test_rangeInAOA(testCase)
% Ensure proper output if range is fully contained in alpha
import af_tools.utils.*
range = [-1,1]';
alpha = (-10:10)';
cl = alpha + 10;
cd = alpha - 10;
expAlphaTrim = (-1:1)';
[alphaTrim, clTrim, cdTrim] = trimtorange(range, alpha, cl, cd);
verifyEqual(testCase, alphaTrim, expAlphaTrim);
verifyEqual(testCase, clTrim, expAlphaTrim+10);
verifyEqual(testCase, cdTrim, expAlphaTrim-10);
end
function test_rangeOutAOA(testCase)
% If range is all out of AOA, just return the input
import af_tools.utils.*
range = [-20,-15]';
alpha = (-10:10)';
cl = alpha + 10;
cd = alpha - 10;
[alphaTrim, clTrim, cdTrim] = trimtorange(range, alpha, cl, cd);
verifyEqual(testCase, alphaTrim, alpha);
verifyEqual(testCase, clTrim, cl);
verifyEqual(testCase, cdTrim, cd);
end
function test_rangePartOutAOA(testCase)
% Ensure proper output if range is partially out of alpha
import af_tools.utils.*
range = (-20:0)';
alpha = (-10:10)';
cl = alpha + 10;
cd = alpha - 10;
expAlphaTrim = (-10:0)';
[alphaTrim, clTrim, cdTrim] = trimtorange(range, alpha, cl, cd);
verifyEqual(testCase, alphaTrim, expAlphaTrim);
verifyEqual(testCase, clTrim, expAlphaTrim+10);
verifyEqual(testCase, cdTrim, expAlphaTrim-10);
end
function test_rangeEqualAOA(testCase)
% Ensure proper output if range is equal to alpha
import af_tools.utils.*
alpha = (-10:10)';
range = (-10:10)';
cl = (20:40)';
cd = (-20:0)';
[alphaTrim, clTrim, cdTrim] = trimtorange(range, alpha, cl, cd);
verifyEqual(testCase, alphaTrim, alpha);
verifyEqual(testCase, clTrim, cl);
verifyEqual(testCase, cdTrim, cd);
end
function test_scalarRange(testCase)
% Ensure proper output if range is a scalar
import af_tools.utils.*
range = (0)';
alpha = (-10:10)';
cl = alpha + 10;
cd = alpha - 10;
expAlphaTrim = 0;
[alphaTrim, clTrim, cdTrim] = trimtorange(range, alpha, cl, cd);
verifyEqual(testCase, alphaTrim, expAlphaTrim);
verifyEqual(testCase, clTrim, expAlphaTrim+10);
verifyEqual(testCase, cdTrim, expAlphaTrim-10);
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment