diff --git a/tests/test_extendpolar.m b/tests/test_extendpolar.m index ace761cdb48f0ba34c50cbd1b2b7dca114711a97..d1920996f948e6284b28b18bffe821b83cd7dda3 100644 --- a/tests/test_extendpolar.m +++ b/tests/test_extendpolar.m @@ -64,66 +64,6 @@ function test_nargin(testCase) end -function test_invalidInputsType(testCase) - % Error if base inputs are of the wrong type - - empty = []; - scal = 0; - logi = true; - char = 'test'; - Struct = struct; - - % 1. Polar (struct) or alpha (numeric) - verifyError(testCase, @() af_tools.extendpolar(empty), 'MATLAB:parsepolarinputs:expectedNonempty'); - verifyError(testCase, @() af_tools.extendpolar(logi), 'MATLAB:parsepolarinputs:invalidType'); - verifyError(testCase, @() af_tools.extendpolar(char), 'MATLAB:parsepolarinputs:invalidType'); - - % 2. cl (numeric) - verifyError(testCase, @() af_tools.extendpolar(scal, logi), 'MATLAB:parsepolarinputs:invalidType'); - verifyError(testCase, @() af_tools.extendpolar(scal, char), 'MATLAB:parsepolarinputs:invalidType'); - verifyError(testCase, @() af_tools.extendpolar(scal, Struct), 'MATLAB:parsepolarinputs:invalidType'); - - % 3. cd (numeric) - verifyError(testCase, @() af_tools.extendpolar(scal, scal, logi), 'MATLAB:parsepolarinputs:invalidType'); - verifyError(testCase, @() af_tools.extendpolar(scal, scal, char), 'MATLAB:parsepolarinputs:invalidType'); - verifyError(testCase, @() af_tools.extendpolar(scal, scal, Struct), 'MATLAB:parsepolarinputs:invalidType'); - -end - -function test_invalidInputSize(testCase) - % Error if cl and cd do not have the same number of rows than alpha - - dummy = (1:20)'; - wrong = rand(8, 4); - - verifyError(testCase, @() af_tools.extendpolar(dummy, wrong, dummy), 'MATLAB:parsepolarinputs:incorrectNumrows'); - verifyError(testCase, @() af_tools.extendpolar(dummy, dummy, wrong), 'MATLAB:parsepolarinputs:incorrectNumrows'); - -end - -function test_invalidAlphaInput(testCase) - % Error if alpha is not increasing (row directions) - - dummy = -(1:20)'; - - verifyError(testCase, @() af_tools.extendpolar(dummy), 'MATLAB:parsepolarinputs:expectedIncreasing'); - -end - -function test_invalidPolarInput(testCase) - % Error if missing fields in the polar - - Dummy = dummysinglepolar(); - DummyAlpha = rmfield(Dummy, 'alpha'); - DummyCl = rmfield(Dummy, 'cl'); - DummyCd = rmfield(Dummy, 'cd'); - - verifyError(testCase, @() af_tools.extendpolar(DummyAlpha), 'MATLAB:nonExistentField'); - verifyError(testCase, @() af_tools.extendpolar(DummyCl), 'MATLAB:nonExistentField'); - verifyError(testCase, @() af_tools.extendpolar(DummyCd), 'MATLAB:nonExistentField'); - -end - function test_invalidOptions(testCase) % Error if invalid option name or missing parameter value @@ -191,7 +131,7 @@ function test_noZero(testCase) Polar = dummysinglepolar(); % Shift alpha so it is all positive - Polar.alpha = Polar.alpha(:) + abs(Polar.alpha(1)) + 0.1; + Polar.aoa = Polar.aoa(:) + abs(Polar.aoa(1)) + 0.1; verifyError(testCase, @() af_tools.extendpolar(Polar), 'MATLAB:extendpolar:noZero'); @@ -199,25 +139,25 @@ end %% Test if function returns expected outputs -function test_correctAlphaSizeSinglePolar(testCase) - % Verify if the output alpha has the correct size +function test_correctAoaSizeSinglePolar(testCase) + % Verify if the output aoa has the correct size % Should not re-expand polar that already covers the full range Polar = dummysinglepolar(); - stepAlpha = min(diff(Polar.alpha)); - fullRange = (-pi:stepAlpha:pi)'; + stepAoa = min(diff(Polar.aoa)); + fullRange = (-pi:stepAoa:pi)'; - [alphaExt, clExt, cdExt] = af_tools.extendpolar(Polar); - [alphaExt2, clExt2, cdExt2] = af_tools.extendpolar(alphaExt, clExt, cdExt); + [aoaExt, clExt, cdExt] = af_tools.extendpolar(Polar); + [aoaExt2, clExt2, cdExt2] = af_tools.extendpolar(aoaExt, clExt, cdExt); - verifyEqual(testCase, alphaExt, fullRange, 'AbsTol', 1e-9); + verifyEqual(testCase, aoaExt, fullRange, 'AbsTol', 1e-9); - verifyEqual(testCase, alphaExt2, alphaExt); + verifyEqual(testCase, aoaExt2, aoaExt); verifyEqual(testCase, clExt2, clExt); verifyEqual(testCase, cdExt2, cdExt); - verifyEqual(testCase, size(clExt2), size(alphaExt)); - verifyEqual(testCase, size(cdExt2), size(alphaExt)); + verifyEqual(testCase, size(clExt2), size(aoaExt)); + verifyEqual(testCase, size(cdExt2), size(aoaExt)); end @@ -226,7 +166,7 @@ function test_correctAlphaSizeDoublePolar(testCase) % Should not re-expand polar that already covers the full range Polar = dummydoublepolar(); - stepAlpha = min(diff(Polar.alpha)); + stepAlpha = min(diff(Polar.aoa)); fullRange = (-pi:stepAlpha:pi)'; [alphaExt, clExt, cdExt] = af_tools.extendpolar(Polar); diff --git a/tests/test_findcllinearrange.m b/tests/test_findcllinearrange.m index a1efd6db9e8f25678ac92e776fc154d10b6bf553..79ae70be48cce13d77e68b63f76ab014ad7d7b5a 100644 --- a/tests/test_findcllinearrange.m +++ b/tests/test_findcllinearrange.m @@ -62,61 +62,6 @@ function test_nargin(testCase) end -function test_invalidInputsType(testCase) - % Error if base inputs are of the wrong type - - empty = []; - scal = 0; - logi = true; - char = 'test'; - Struct = struct; - - % 1. Polar (struct) or alpha (numeric) - verifyError(testCase, @() af_tools.findcllinearrange(empty), 'MATLAB:parsepolarinputs:expectedNonempty'); - verifyError(testCase, @() af_tools.findcllinearrange(logi), 'MATLAB:parsepolarinputs:invalidType'); - verifyError(testCase, @() af_tools.findcllinearrange(char), 'MATLAB:parsepolarinputs:invalidType'); - - % 2. cl (numeric) - verifyError(testCase, @() af_tools.findcllinearrange(scal, logi), 'MATLAB:parsepolarinputs:invalidType'); - verifyError(testCase, @() af_tools.findcllinearrange(scal, char), 'MATLAB:parsepolarinputs:invalidType'); - verifyError(testCase, @() af_tools.findcllinearrange(scal, Struct), 'MATLAB:parsepolarinputs:invalidType'); - -end - -function test_invalidInputSize(testCase) - % Error if cl and cd do not have the same number of rows than alpha - - dummy = (1:20)'; - wrong = rand(8, 4); - - verifyError(testCase, @() af_tools.findcllinearrange(dummy, wrong), 'MATLAB:parsepolarinputs:incorrectNumrows'); - -end - -function test_invalidAlphaInput(testCase) - % Error if alpha is not increasing (row directions) - - dummy = -(1:20)'; - - verifyError(testCase, @() af_tools.findcllinearrange(dummy), 'MATLAB:parsepolarinputs:expectedIncreasing'); - -end - -function test_invalidPolarInput(testCase) - % Error if missing fields in the polar - - Dummy = dummysinglepolar(); - DummyAlpha = rmfield(Dummy, 'alpha'); - DummyCl = rmfield(Dummy, 'cl'); - DummyCd = rmfield(Dummy, 'cd'); - - verifyError(testCase, @() af_tools.findcllinearrange(DummyAlpha), 'MATLAB:nonExistentField'); - verifyError(testCase, @() af_tools.findcllinearrange(DummyCl), 'MATLAB:nonExistentField'); - verifyError(testCase, @() af_tools.findcllinearrange(DummyCd), 'MATLAB:nonExistentField'); - -end - -% ------------------------------------------------------------------------------ function test_noLinearRange(testCase) % Ensure that the function throws an exception if no linear range was found diff --git a/tests/test_findstall.m b/tests/test_findstall.m index a0309899606f4dd001a847091c2b6a3da736ae64..847c73b24737e163ffd2d463e27c70bb14adaf21 100644 --- a/tests/test_findstall.m +++ b/tests/test_findstall.m @@ -63,67 +63,6 @@ function test_nargin(testCase) end -function test_invalidInputsType(testCase) - % Error if base inputs are of the wrong type - - empty = []; - scal = 0; - logi = true; - char = 'test'; - Struct = struct; - - % 1. Polar (struct) or alpha (numeric) - verifyError(testCase, @() af_tools.findstall(empty), 'MATLAB:parsepolarinputs:expectedNonempty'); - verifyError(testCase, @() af_tools.findstall(logi), 'MATLAB:parsepolarinputs:invalidType'); - verifyError(testCase, @() af_tools.findstall(char), 'MATLAB:parsepolarinputs:invalidType'); - - % 2. cl (numeric) - verifyError(testCase, @() af_tools.findstall(scal, logi), 'MATLAB:parsepolarinputs:invalidType'); - verifyError(testCase, @() af_tools.findstall(scal, char), 'MATLAB:parsepolarinputs:invalidType'); - verifyError(testCase, @() af_tools.findstall(scal, Struct), 'MATLAB:parsepolarinputs:invalidType'); - - % 3. cd (numeric) - verifyError(testCase, @() af_tools.findstall(scal, scal, logi), 'MATLAB:parsepolarinputs:invalidType'); - verifyError(testCase, @() af_tools.findstall(scal, scal, char), 'MATLAB:parsepolarinputs:invalidType'); - verifyError(testCase, @() af_tools.findstall(scal, scal, Struct), 'MATLAB:parsepolarinputs:invalidType'); - -end - -function test_invalidInputSize(testCase) - % Error if cl and cd do not have the same number of rows than alpha - - dummy = (1:20)'; - wrong = rand(8, 4); - - verifyError(testCase, @() af_tools.findstall(dummy, wrong, dummy), 'MATLAB:parsepolarinputs:incorrectNumrows'); - verifyError(testCase, @() af_tools.findstall(dummy, dummy, wrong), 'MATLAB:parsepolarinputs:incorrectNumrows'); - -end - -function test_invalidAlphaInput(testCase) - % Error if alpha is not increasing (row directions) - - dummy = -(1:20)'; - - verifyError(testCase, @() af_tools.findstall(dummy), 'MATLAB:parsepolarinputs:expectedIncreasing'); - -end - -function test_invalidPolarInput(testCase) - % Error if missing fields in the polar - - Dummy = dummysinglepolar(); - DummyAlpha = rmfield(Dummy, 'alpha'); - DummyCl = rmfield(Dummy, 'cl'); - DummyCd = rmfield(Dummy, 'cd'); - - verifyError(testCase, @() af_tools.findstall(DummyAlpha), 'MATLAB:nonExistentField'); - verifyError(testCase, @() af_tools.findstall(DummyCl), 'MATLAB:nonExistentField'); - verifyError(testCase, @() af_tools.findstall(DummyCd), 'MATLAB:nonExistentField'); - -end - -% ----------------------------------------------- function test_noStall(testCase) % Error if impossible to find the stall diff --git a/tests/test_findzerolift.m b/tests/test_findzerolift.m index dde699e13c310f9b1229fa688ff566e0a60a8eaa..d66eab3af4d4618e4aa3e7e0d256e03a3b7fb11c 100644 --- a/tests/test_findzerolift.m +++ b/tests/test_findzerolift.m @@ -62,67 +62,6 @@ function test_nargin(testCase) end -function test_invalidInputsType(testCase) - % Error if base inputs are of the wrong type - - empty = []; - scal = 0; - logi = true; - char = 'test'; - Struct = struct; - - % 1. Polar (struct) or alpha (numeric) - verifyError(testCase, @() af_tools.findzerolift(empty), 'MATLAB:parsepolarinputs:expectedNonempty'); - verifyError(testCase, @() af_tools.findzerolift(logi), 'MATLAB:parsepolarinputs:invalidType'); - verifyError(testCase, @() af_tools.findzerolift(char), 'MATLAB:parsepolarinputs:invalidType'); - - % 2. cl (numeric) - verifyError(testCase, @() af_tools.findzerolift(scal, logi), 'MATLAB:parsepolarinputs:invalidType'); - verifyError(testCase, @() af_tools.findzerolift(scal, char), 'MATLAB:parsepolarinputs:invalidType'); - verifyError(testCase, @() af_tools.findzerolift(scal, Struct), 'MATLAB:parsepolarinputs:invalidType'); - - % 3. cd (numeric) - verifyError(testCase, @() af_tools.findzerolift(scal, scal, logi), 'MATLAB:parsepolarinputs:invalidType'); - verifyError(testCase, @() af_tools.findzerolift(scal, scal, char), 'MATLAB:parsepolarinputs:invalidType'); - verifyError(testCase, @() af_tools.findzerolift(scal, scal, Struct), 'MATLAB:parsepolarinputs:invalidType'); - -end - -function test_invalidInputSize(testCase) - % Error if cl and cd do not have the same number of rows than alpha - - dummy = (1:20)'; - wrong = rand(8, 4); - - verifyError(testCase, @() af_tools.findzerolift(dummy, wrong, dummy), 'MATLAB:parsepolarinputs:incorrectNumrows'); - verifyError(testCase, @() af_tools.findzerolift(dummy, dummy, wrong), 'MATLAB:parsepolarinputs:incorrectNumrows'); - -end - -function test_invalidAlphaInput(testCase) - % Error if alpha is not increasing (row directions) - - dummy = -(1:20)'; - - verifyError(testCase, @() af_tools.findzerolift(dummy), 'MATLAB:parsepolarinputs:expectedIncreasing'); - -end - -function test_invalidPolarInput(testCase) - % Error if missing fields in the polar - - Dummy = dummysinglepolar(); - DummyAlpha = rmfield(Dummy, 'alpha'); - DummyCl = rmfield(Dummy, 'cl'); - DummyCd = rmfield(Dummy, 'cd'); - - verifyError(testCase, @() af_tools.findzerolift(DummyAlpha), 'MATLAB:nonExistentField'); - verifyError(testCase, @() af_tools.findzerolift(DummyCl), 'MATLAB:nonExistentField'); - verifyError(testCase, @() af_tools.findzerolift(DummyCd), 'MATLAB:nonExistentField'); - -end - -% ------------------------------------------------------------------------------ function test_noPositiveCl(testCase) % Error if Cl is never positive (impossible to find zero) diff --git a/tests/test_formatairfoilcoord.m b/tests/test_formatairfoilcoord.m index 1e0e0e083ba7a4e8deeebf3af2963981855baaf6..b5c63816ceae84ba1f029b98ff72674627ef575b 100644 --- a/tests/test_formatairfoilcoord.m +++ b/tests/test_formatairfoilcoord.m @@ -65,28 +65,6 @@ function test_nargin(testCase) end -function test_invalidInputsType(testCase) - % Error if base inputs are of the wrong type - - empty = []; - scal = 0; - logi = true; - Struct = struct; - - % 1. inputDir (char vector or string) - verifyError(testCase, @() af_tools.formatairfoilcoord(empty), 'MATLAB:parsefileinputs:invalidType'); - verifyError(testCase, @() af_tools.formatairfoilcoord(scal), 'MATLAB:parsefileinputs:invalidType'); - verifyError(testCase, @() af_tools.formatairfoilcoord(logi), 'MATLAB:parsefileinputs:invalidType'); - verifyError(testCase, @() af_tools.formatairfoilcoord(Struct), 'MATLAB:parsefileinputs:invalidType'); - - % 2. inputFile (char, string, cell of chars) - verifyError(testCase, @() af_tools.formatairfoilcoord(scal, empty), 'MATLAB:parsefileinputs:invalidType'); - verifyError(testCase, @() af_tools.formatairfoilcoord(scal, scal), 'MATLAB:parsefileinputs:invalidType'); - verifyError(testCase, @() af_tools.formatairfoilcoord(scal, logi), 'MATLAB:parsefileinputs:invalidType'); - verifyError(testCase, @() af_tools.formatairfoilcoord(scal, Struct), 'MATLAB:parsefileinputs:invalidType'); - -end - function test_invalidOptions(testCase) % Error if invalid option name or missing parameter value @@ -161,25 +139,6 @@ function test_invalidOptionsVal(testCase) end -% ------------------------------------- -function test_fileNotFound(testCase) - % Error if valid inputDir not found - - testDir = [pwd, '/test_utils/']; - invalidDir = 'invaliddirectory'; - - verifyWarning(testCase, @() af_tools.formatairfoilcoord({[testDir, 'clarky.dat'], [testDir, 'testdummy.dat']}), ... - 'MATLAB:parsefileinputs:FileNotFound'); - % remove warning first warning about FileNotFound before it throws the error - warning('off', 'MATLAB:parsefileinputs:FileNotFound'); - verifyError(testCase, @() af_tools.formatairfoilcoord([testDir, 'randomFile']), ... - 'MATLAB:parsefileinputs:noFilesFound'); - verifyError(testCase, @() af_tools.formatairfoilcoord(invalidDir), 'MATLAB:parsefileinputs:noFilesFound'); - - warning on; % Reactivate warnings - -end - %% Test if function returns expected outputs function test_correctOrder(testCase) diff --git a/tests/test_nacaairfoil.m b/tests/test_nacaairfoil.m index 6b14f2ad03028f031e230ec19ff71a0ba325c8a5..6e56db1afe0aff3d52519202d0eb508e6b09f217 100644 --- a/tests/test_nacaairfoil.m +++ b/tests/test_nacaairfoil.m @@ -62,49 +62,6 @@ function test_nargin(testCase) end -function test_invalidBaseInputs(testCase) - % Error if base inputs are of the wrong type - - empty = []; - scal = 0; - logi = true; - char = 'test'; - Struct = struct; - vect = 1:10; - - % 1. Digits (char or str) - verifyError(testCase, @() af_tools.nacaairfoil(empty), 'MATLAB:parsenacainputs:invalidType'); - verifyError(testCase, @() af_tools.nacaairfoil(scal), 'MATLAB:parsenacainputs:invalidType'); - verifyError(testCase, @() af_tools.nacaairfoil(logi), 'MATLAB:parsenacainputs:invalidType'); - verifyError(testCase, @() af_tools.nacaairfoil(Struct), 'MATLAB:parsenacainputs:invalidType'); - - % 2. nPoints (numeric, above 2) - verifyError(testCase, @() af_tools.nacaairfoil('0012', empty), 'MATLAB:parsenacainputs:expectedScalar'); - verifyError(testCase, @() af_tools.nacaairfoil('0012', logi), 'MATLAB:parsenacainputs:invalidType'); - verifyError(testCase, @() af_tools.nacaairfoil('0012', char), 'MATLAB:parsenacainputs:invalidType'); - verifyError(testCase, @() af_tools.nacaairfoil('0012', Struct), 'MATLAB:parsenacainputs:invalidType'); - verifyError(testCase, @() af_tools.nacaairfoil('0012', vect), 'MATLAB:parsenacainputs:expectedScalar'); - -end - -function test_invalidDigits(testCase) - % Error if digits is not an actual NACA 4 or 5 digit - - verifyError(testCase, @() af_tools.nacaairfoil('012'), 'MATLAB:parsenacainputs:wrongNumberOfDigits'); - verifyError(testCase, @() af_tools.nacaairfoil('012345'), 'MATLAB:parsenacainputs:wrongNumberOfDigits'); - verifyError(testCase, @() af_tools.nacaairfoil('oo12'), 'MATLAB:parsenacainputs:invalidDigits'); - verifyError(testCase, @() af_tools.nacaairfoil('24312'), 'MATLAB:parsenacainputs:invalid5Digits'); - -end - -function test_warningLowNPoints(testCase) - % Warns user if low number of points - - verifyWarning(testCase, @() af_tools.nacaairfoil('0012', 5, 'spacing', 'halfcosine'), ... - 'MATLAB:parsenacainputs:lowNPoints'); - -end - function test_invalidOptions(testCase) % Error if invalid option name or missing parameter value diff --git a/tests/test_nacacamber.m b/tests/test_nacacamber.m index 417bc60d26c6a9035031a56debaa7c6c797375a8..6e1b4cbde60619a00b3b66e5836b931c68e86112 100644 --- a/tests/test_nacacamber.m +++ b/tests/test_nacacamber.m @@ -61,41 +61,6 @@ function test_nargin(testCase) end -function test_invalidBaseInputs(testCase) - % Error if base inputs are of the wrong type - - empty = []; - scal = 0; - logi = true; - char = 'test'; - Struct = struct; - vect = 1:10; - - % 1. Digits (char or str) - verifyError(testCase, @() af_tools.nacacamber(empty), 'MATLAB:parsenacainputs:invalidType'); - verifyError(testCase, @() af_tools.nacacamber(scal), 'MATLAB:parsenacainputs:invalidType'); - verifyError(testCase, @() af_tools.nacacamber(logi), 'MATLAB:parsenacainputs:invalidType'); - verifyError(testCase, @() af_tools.nacacamber(Struct), 'MATLAB:parsenacainputs:invalidType'); - - % 2. nPoints (numeric, above 2) - verifyError(testCase, @() af_tools.nacacamber('0012', empty), 'MATLAB:parsenacainputs:expectedScalar'); - verifyError(testCase, @() af_tools.nacacamber('0012', logi), 'MATLAB:parsenacainputs:invalidType'); - verifyError(testCase, @() af_tools.nacacamber('0012', char), 'MATLAB:parsenacainputs:invalidType'); - verifyError(testCase, @() af_tools.nacacamber('0012', Struct), 'MATLAB:parsenacainputs:invalidType'); - verifyError(testCase, @() af_tools.nacacamber('0012', vect), 'MATLAB:parsenacainputs:expectedScalar'); - -end - -function test_invalidDigits(testCase) - % Error if digits is not an actual NACA 4 or 5 digit - - verifyError(testCase, @() af_tools.nacacamber('012'), 'MATLAB:parsenacainputs:wrongNumberOfDigits'); - verifyError(testCase, @() af_tools.nacacamber('012345'), 'MATLAB:parsenacainputs:wrongNumberOfDigits'); - verifyError(testCase, @() af_tools.nacacamber('oo12'), 'MATLAB:parsenacainputs:invalidDigits'); - verifyError(testCase, @() af_tools.nacacamber('24312'), 'MATLAB:parsenacainputs:invalid5Digits'); - -end - function test_warningLowNPoints(testCase) % Warns user if low number of points diff --git a/tests/test_parsepolarinputs.m b/tests/test_parsepolarinputs.m index 20cacaf67d0c3828bafca4564cdfcdec282067e0..2de57b4692d8d95c20baf76403d381c191b3e85c 100644 --- a/tests/test_parsepolarinputs.m +++ b/tests/test_parsepolarinputs.m @@ -148,27 +148,24 @@ function test_invalidAlphaInputWhenNoOpts(testCase) end function test_invalidPolarInputWhenNoOpts(testCase) - % Error if missing fields in the polar + % Polar should always have alpha EMPTY_OPTS = {}; Dummy = dummysinglepolar(); - DummyAlpha = rmfield(Dummy, 'alpha'); - DummyCl = rmfield(Dummy, 'cl'); - DummyCd = rmfield(Dummy, 'cd'); - DummyCm = rmfield(Dummy, 'cm'); - verifyError(testCase, @() af_tools.utils.parsepolarinputs(EMPTY_OPTS, DummyAlpha), 'MATLAB:nonExistentField'); - verifyError(testCase, @() af_tools.utils.parsepolarinputs(EMPTY_OPTS, DummyCl), 'MATLAB:nonExistentField'); - verifyError(testCase, @() af_tools.utils.parsepolarinputs(EMPTY_OPTS, DummyCd), 'MATLAB:nonExistentField'); - verifyError(testCase, @() af_tools.utils.parsepolarinputs(EMPTY_OPTS, DummyCm), 'MATLAB:nonExistentField'); + DummyAlpha = Dummy; + DummyAlpha.aoa = []; + + verifyError(testCase, @() af_tools.utils.parsepolarinputs(EMPTY_OPTS, DummyAlpha), ... + 'MATLAB:parsepolarinputs:expectedNonempty'); end function test_invalidInputTypeWithOpts(testCase) % Error if any input is of the wrong type - EMPTY_OPTS = {'option1', 'option2'}; + NONEMPTY_OPTS = {'option1', 'option2'}; empty = []; scal = 0; logi = true; @@ -176,38 +173,38 @@ function test_invalidInputTypeWithOpts(testCase) Struct = struct; % 1. Polar (struct) or alpha (numeric) - verifyError(testCase, @() af_tools.utils.parsepolarinputs(EMPTY_OPTS, empty), ... + verifyError(testCase, @() af_tools.utils.parsepolarinputs(NONEMPTY_OPTS, empty), ... 'MATLAB:parsepolarinputs:expectedNonempty'); - verifyError(testCase, @() af_tools.utils.parsepolarinputs(EMPTY_OPTS, logi), ... + verifyError(testCase, @() af_tools.utils.parsepolarinputs(NONEMPTY_OPTS, logi), ... 'MATLAB:parsepolarinputs:invalidType'); - verifyError(testCase, @() af_tools.utils.parsepolarinputs(EMPTY_OPTS, char), ... + verifyError(testCase, @() af_tools.utils.parsepolarinputs(NONEMPTY_OPTS, char), ... 'MATLAB:parsepolarinputs:invalidType'); % 2. cl (numeric) - verifyError(testCase, @() af_tools.utils.parsepolarinputs(EMPTY_OPTS, scal, logi), ... + verifyError(testCase, @() af_tools.utils.parsepolarinputs(NONEMPTY_OPTS, scal, logi), ... 'MATLAB:parsepolarinputs:invalidType'); - verifyError(testCase, @() af_tools.utils.parsepolarinputs(EMPTY_OPTS, scal, char), ... + verifyError(testCase, @() af_tools.utils.parsepolarinputs(NONEMPTY_OPTS, scal, char), ... 'MATLAB:parsepolarinputs:invalidType'); - verifyError(testCase, @() af_tools.utils.parsepolarinputs(EMPTY_OPTS, scal, Struct), ... + verifyError(testCase, @() af_tools.utils.parsepolarinputs(NONEMPTY_OPTS, scal, Struct), ... 'MATLAB:parsepolarinputs:invalidType'); % 3. cd (numeric) - verifyError(testCase, @() af_tools.utils.parsepolarinputs(EMPTY_OPTS, scal, scal, logi), ... + verifyError(testCase, @() af_tools.utils.parsepolarinputs(NONEMPTY_OPTS, scal, scal, logi), ... 'MATLAB:parsepolarinputs:invalidType'); - verifyError(testCase, @() af_tools.utils.parsepolarinputs(EMPTY_OPTS, scal, scal, char), ... + verifyError(testCase, @() af_tools.utils.parsepolarinputs(NONEMPTY_OPTS, scal, scal, char), ... 'MATLAB:parsepolarinputs:invalidType'); - verifyError(testCase, @() af_tools.utils.parsepolarinputs(EMPTY_OPTS, scal, scal, Struct), ... + verifyError(testCase, @() af_tools.utils.parsepolarinputs(NONEMPTY_OPTS, scal, scal, Struct), ... 'MATLAB:parsepolarinputs:invalidType'); % 4. cm (numeric) verifyError(testCase, ... - @() af_tools.utils.parsepolarinputs(EMPTY_OPTS, scal, scal, scal, logi), ... + @() af_tools.utils.parsepolarinputs(NONEMPTY_OPTS, scal, scal, scal, logi), ... 'MATLAB:parsepolarinputs:invalidType'); verifyError(testCase, ... - @() af_tools.utils.parsepolarinputs(EMPTY_OPTS, scal, scal, scal, char), ... + @() af_tools.utils.parsepolarinputs(NONEMPTY_OPTS, scal, scal, scal, char), ... 'MATLAB:parsepolarinputs:invalidType'); verifyError(testCase, ... - @() af_tools.utils.parsepolarinputs(EMPTY_OPTS, scal, scal, scal, Struct), ... + @() af_tools.utils.parsepolarinputs(NONEMPTY_OPTS, scal, scal, scal, Struct), ... 'MATLAB:parsepolarinputs:invalidType'); end @@ -215,18 +212,18 @@ end function test_invalidInputSizeWithOpts(testCase) % Error if cl, cd and cm do not have the same number of rows than alpha - EMPTY_OPTS = {'option1', 'option2'}; + NONEMPTY_OPTS = {'option1', 'option2'}; dummy = (1:20)'; wrong = rand(8, 4); verifyError(testCase, ... - @() af_tools.utils.parsepolarinputs(EMPTY_OPTS, dummy, wrong, dummy, dummy), ... + @() af_tools.utils.parsepolarinputs(NONEMPTY_OPTS, dummy, wrong, dummy, dummy), ... 'MATLAB:parsepolarinputs:incorrectNumrows'); verifyError(testCase, ... - @() af_tools.utils.parsepolarinputs(EMPTY_OPTS, dummy, dummy, wrong, dummy), ... + @() af_tools.utils.parsepolarinputs(NONEMPTY_OPTS, dummy, dummy, wrong, dummy), ... 'MATLAB:parsepolarinputs:incorrectNumrows'); verifyError(testCase, ... - @() af_tools.utils.parsepolarinputs(EMPTY_OPTS, dummy, dummy, dummy, wrong), ... + @() af_tools.utils.parsepolarinputs(NONEMPTY_OPTS, dummy, dummy, dummy, wrong), ... 'MATLAB:parsepolarinputs:incorrectNumrows'); end @@ -234,10 +231,10 @@ end function test_invalidAlphaInputWithOpts(testCase) % Error if alpha is not increasing (row directions) - EMPTY_OPTS = {'option1', 'option2'}; + NONEMPTY_OPTS = {'option1', 'option2'}; dummy = -(1:20)'; - verifyError(testCase, @() af_tools.utils.parsepolarinputs(EMPTY_OPTS, dummy), ... + verifyError(testCase, @() af_tools.utils.parsepolarinputs(NONEMPTY_OPTS, dummy), ... 'MATLAB:parsepolarinputs:expectedIncreasing'); end @@ -245,18 +242,14 @@ end function test_invalidPolarInputWithOpts(testCase) % Error if missing fields in the polar - EMPTY_OPTS = {'option1', 'option2'}; + NONEMPTY_OPTS = {'option1', 'option2'}; Dummy = dummysinglepolar(); - DummyAlpha = rmfield(Dummy, 'alpha'); - DummyCl = rmfield(Dummy, 'cl'); - DummyCd = rmfield(Dummy, 'cd'); - DummyCm = rmfield(Dummy, 'cm'); + DummyAlpha = Dummy; + DummyAlpha.aoa = []; - verifyError(testCase, @() af_tools.utils.parsepolarinputs(EMPTY_OPTS, DummyAlpha), 'MATLAB:nonExistentField'); - verifyError(testCase, @() af_tools.utils.parsepolarinputs(EMPTY_OPTS, DummyCl), 'MATLAB:nonExistentField'); - verifyError(testCase, @() af_tools.utils.parsepolarinputs(EMPTY_OPTS, DummyCd), 'MATLAB:nonExistentField'); - verifyError(testCase, @() af_tools.utils.parsepolarinputs(EMPTY_OPTS, DummyCm), 'MATLAB:nonExistentField'); + verifyError(testCase, @() af_tools.utils.parsepolarinputs(NONEMPTY_OPTS, DummyAlpha), ... + 'MATLAB:parsepolarinputs:expectedNonempty'); end @@ -272,7 +265,8 @@ function test_emptyInputsInPolar(testCase) EMPTY_OPTS = {}; AOA = 1:10; - EmptyPolar = struct('alpha', AOA, 'cl', [], 'cd', [], 'cm', []); + EmptyPolar = af_tools.Polar; + EmptyPolar.aoa = AOA'; [alpha, c_l, c_d, c_m, idxOpts] = af_tools.utils.parsepolarinputs(EMPTY_OPTS, EmptyPolar); diff --git a/tests/test_plotpolars.m b/tests/test_plotpolars.m index 3c7120f487f2f0b7d7754d031392f1dfe40d5fba..c75c0c12f2ba9038e5d56601b838bf1fac888f9b 100644 --- a/tests/test_plotpolars.m +++ b/tests/test_plotpolars.m @@ -61,74 +61,3 @@ function test_nargin(testCase) verifyError(testCase, @() af_tools.plotpolars(dummy, dummy, dummy, dummy, 1), 'MATLAB:narginchk:tooManyInputs'); end - -function test_invalidInputsType(testCase) - % Error if base inputs are of the wrong type - - empty = []; - scal = 0; - logi = true; - char = 'test'; - Struct = struct; - - % 1. Polar (struct) or alpha (numeric) - verifyError(testCase, @() af_tools.plotpolars(empty), 'MATLAB:parsepolarinputs:expectedNonempty'); - verifyError(testCase, @() af_tools.plotpolars(logi), 'MATLAB:parsepolarinputs:invalidType'); - verifyError(testCase, @() af_tools.plotpolars(char), 'MATLAB:parsepolarinputs:invalidType'); - - % 2. cl (numeric) - verifyError(testCase, @() af_tools.plotpolars(scal, logi), 'MATLAB:parsepolarinputs:invalidType'); - verifyError(testCase, @() af_tools.plotpolars(scal, char), 'MATLAB:parsepolarinputs:invalidType'); - verifyError(testCase, @() af_tools.plotpolars(scal, Struct), 'MATLAB:parsepolarinputs:invalidType'); - - % 3. cd (numeric) - verifyError(testCase, @() af_tools.plotpolars(scal, scal, logi), 'MATLAB:parsepolarinputs:invalidType'); - verifyError(testCase, @() af_tools.plotpolars(scal, scal, char), 'MATLAB:parsepolarinputs:invalidType'); - verifyError(testCase, @() af_tools.plotpolars(scal, scal, Struct), 'MATLAB:parsepolarinputs:invalidType'); - - % 4. cm (numeric) - verifyError(testCase, @() af_tools.plotpolars(scal, scal, scal, logi), 'MATLAB:parsepolarinputs:invalidType'); - verifyError(testCase, @() af_tools.plotpolars(scal, scal, scal, char), 'MATLAB:parsepolarinputs:invalidType'); - verifyError(testCase, @() af_tools.plotpolars(scal, scal, scal, Struct), 'MATLAB:parsepolarinputs:invalidType'); - -end - -function test_invalidInputSize(testCase) - % Error if cl, cd and cm do not have the same number of rows than alpha - - dummy = (1:20)'; - wrong = rand(8, 4); - - verifyError(testCase, @() af_tools.plotpolars(dummy, wrong, dummy, dummy), ... - 'MATLAB:parsepolarinputs:incorrectNumrows'); - verifyError(testCase, @() af_tools.plotpolars(dummy, dummy, wrong, dummy), ... - 'MATLAB:parsepolarinputs:incorrectNumrows'); - verifyError(testCase, @() af_tools.plotpolars(dummy, dummy, dummy, wrong), ... - 'MATLAB:parsepolarinputs:incorrectNumrows'); - -end - -function test_invalidAlphaInput(testCase) - % Error if alpha is not increasing (row directions) - - dummy = -(1:20)'; - - verifyError(testCase, @() af_tools.plotpolars(dummy), 'MATLAB:parsepolarinputs:expectedIncreasing'); - -end - -function test_invalidPolarInput(testCase) - % Error if missing fields in the polar - - Dummy = dummysinglepolar(); - DummyAlpha = rmfield(Dummy, 'alpha'); - DummyCl = rmfield(Dummy, 'cl'); - DummyCd = rmfield(Dummy, 'cd'); - DummyCm = rmfield(Dummy, 'cm'); - - verifyError(testCase, @() af_tools.plotpolars(DummyAlpha), 'MATLAB:nonExistentField'); - verifyError(testCase, @() af_tools.plotpolars(DummyCl), 'MATLAB:nonExistentField'); - verifyError(testCase, @() af_tools.plotpolars(DummyCd), 'MATLAB:nonExistentField'); - verifyError(testCase, @() af_tools.plotpolars(DummyCm), 'MATLAB:nonExistentField'); - -end diff --git a/tests/test_xf2mat.m b/tests/test_xf2mat.m index de7b0eeb6a505348fb8eb334243cac6c90842596..f0bde3afdc628848aa24f9d5e4b9b1381195bb6c 100644 --- a/tests/test_xf2mat.m +++ b/tests/test_xf2mat.m @@ -64,28 +64,6 @@ function test_nargin(testCase) end -function test_invalidInputsType(testCase) - % Error if base inputs are of the wrong type - - empty = []; - scal = 0; - logi = true; - Struct = struct; - - % 1. inputDir (char vector or string) - verifyError(testCase, @() af_tools.xf2mat(empty), 'MATLAB:parsefileinputs:invalidType'); - verifyError(testCase, @() af_tools.xf2mat(scal), 'MATLAB:parsefileinputs:invalidType'); - verifyError(testCase, @() af_tools.xf2mat(logi), 'MATLAB:parsefileinputs:invalidType'); - verifyError(testCase, @() af_tools.xf2mat(Struct), 'MATLAB:parsefileinputs:invalidType'); - - % 2. inputFile (char, string, cell of chars) - verifyError(testCase, @() af_tools.xf2mat(scal, empty), 'MATLAB:parsefileinputs:invalidType'); - verifyError(testCase, @() af_tools.xf2mat(scal, scal), 'MATLAB:parsefileinputs:invalidType'); - verifyError(testCase, @() af_tools.xf2mat(scal, logi), 'MATLAB:parsefileinputs:invalidType'); - verifyError(testCase, @() af_tools.xf2mat(scal, Struct), 'MATLAB:parsefileinputs:invalidType'); - -end - function test_invalidOptions(testCase) % Error if invalid option name or missing parameter value @@ -128,21 +106,6 @@ function test_invalidOptionsVal(testCase) end -% ------------------------------------- -function test_fileNotFound(testCase) - % Error if valid inputDir not found - - testdir = [pwd, '/test_utils/']; - - verifyWarning(testCase, @() af_tools.xf2mat({[testdir, 'xflr*'], [testdir, 'randomFile']}), ... - 'MATLAB:parsefileinputs:FileNotFound'); - % Remove warning first warning about FileNotFound before it throws the error - warning('off', 'MATLAB:parsefileinputs:FileNotFound'); - verifyError(testCase, @() af_tools.xf2mat([testdir, 'randomFile']), 'MATLAB:parsefileinputs:noFilesFound'); - warning on; % Reactivate warnings - -end - %% Test if function returns expected outputs function test_correctNbOfPolars(testCase) @@ -152,14 +115,14 @@ function test_correctNbOfPolars(testCase) Polar = af_tools.xf2mat(testfiles); - verifyEqual(testCase, size(Polar.alpha, 2), 3); - verifyEqual(testCase, size(Polar.alpha, 2), 3); - verifyEqual(testCase, size(Polar.alpha, 2), 3); - verifyEqual(testCase, size(Polar.alpha, 2), 3); + verifyEqual(testCase, size(Polar.aoa, 2), 3); + verifyEqual(testCase, size(Polar.aoa, 2), 3); + verifyEqual(testCase, size(Polar.aoa, 2), 3); + verifyEqual(testCase, size(Polar.aoa, 2), 3); - verifyEqual(testCase, size(Polar.alpha, 2), size(Polar.cl, 2)); - verifyEqual(testCase, size(Polar.alpha, 2), size(Polar.cl, 2)); - verifyEqual(testCase, size(Polar.alpha, 2), size(Polar.cl, 2)); + verifyEqual(testCase, size(Polar.aoa, 2), size(Polar.cl, 2)); + verifyEqual(testCase, size(Polar.aoa, 2), size(Polar.cl, 2)); + verifyEqual(testCase, size(Polar.aoa, 2), size(Polar.cl, 2)); end @@ -170,9 +133,9 @@ function test_correctDimensions(testCase) Polar = af_tools.xf2mat(testfiles); - verifyEqual(testCase, size(Polar.alpha, 1), size(Polar.cl, 1)); - verifyEqual(testCase, size(Polar.alpha, 1), size(Polar.cd, 1)); - verifyEqual(testCase, size(Polar.alpha, 1), size(Polar.cm, 1)); + verifyEqual(testCase, size(Polar.aoa, 1), size(Polar.cl, 1)); + verifyEqual(testCase, size(Polar.aoa, 1), size(Polar.cd, 1)); + verifyEqual(testCase, size(Polar.aoa, 1), size(Polar.cm, 1)); end @@ -194,14 +157,13 @@ function test_correctOutputValues(testCase) Polar = af_tools.xf2mat(testfile); - verifyEqual(testCase, Polar.alpha(1), deg2rad(-20)); + verifyEqual(testCase, Polar.aoa(1), deg2rad(-20)); verifyEqual(testCase, Polar.cl(1), -0.4490); verifyEqual(testCase, Polar.cd(1), 0.19678); verifyEqual(testCase, Polar.cm(1), 0.0070); verifyEqual(testCase, Polar.reynolds, 1e6); verifyEqual(testCase, Polar.mach, 0.1); verifyEqual(testCase, Polar.nCrit, 9); - verifyEqual(testCase, Polar.origin, {'XFOIL'}); verifyEqual(testCase, Polar.airfoil, {'NACA_2412'}); end