From 6d74c6422e33f318e8043819267321e35b074e18 Mon Sep 17 00:00:00 2001 From: Thomas Lambert <t.lambert@uliege.be> Date: Sun, 24 Apr 2022 15:18:17 +0200 Subject: [PATCH] test: add tests for selig and lednicer --- CHANGELOG.md | 2 ++ tests/test_lednicer.m | 69 +++++++++++++++++++++++++++++++++++++++++++ tests/test_selig.m | 69 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 140 insertions(+) create mode 100644 tests/test_lednicer.m create mode 100644 tests/test_selig.m diff --git a/CHANGELOG.md b/CHANGELOG.md index a1da4f7..eaaf910 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- Unit tests for **utils.selig** and **utils.lednicer** + ### Changed ### Deprecated diff --git a/tests/test_lednicer.m b/tests/test_lednicer.m new file mode 100644 index 0000000..772123b --- /dev/null +++ b/tests/test_lednicer.m @@ -0,0 +1,69 @@ +% TEST_LEDNICER Unitary tests for the lednicer sub-function +% Note: +% Matlab package functionality is not very test-framework friendly. +% Either the whole package has to be imported in EVERY SINGLE TEST or the +% functions must be called as <package>.function() everytime. +% The second option is preferred for the tests as it has the smaller scope. +% +% ----- +% (c) Copyright 2022 University of Liege +% Author: 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_lednicer + + tests = functiontests(localfunctions); + +end + +%% Setup and teardown + +function setupOnce(testCase) + + 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) + + 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(~) + + close all; % Close all figures that would have been openend + +end + +%% Test for correct output + +function test_scalar(testCase) + % If input is scalar, output should be same scalar + + x = (0:0.1:1)'; + yup = x; + ylow = -x; + upper = [x, yup]; + lower = [x, ylow]; + + coord = af_tools.utils.lednicer(upper, lower); + + verifyEqual(testCase, coord, [upper; lower]); + +end diff --git a/tests/test_selig.m b/tests/test_selig.m new file mode 100644 index 0000000..ffa89fe --- /dev/null +++ b/tests/test_selig.m @@ -0,0 +1,69 @@ +% TEST_SELIG Unitary tests for the selig sub-function +% Note: +% Matlab package functionality is not very test-framework friendly. +% Either the whole package has to be imported in EVERY SINGLE TEST or the +% functions must be called as <package>.function() everytime. +% The second option is preferred for the tests as it has the smaller scope. +% +% ----- +% (c) Copyright 2022 University of Liege +% Author: 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_selig + + tests = functiontests(localfunctions); + +end + +%% Setup and teardown + +function setupOnce(testCase) + + 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) + + 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(~) + + close all; % Close all figures that would have been openend + +end + +%% Test for correct output + +function test_scalar(testCase) + % If input is scalar, output should be same scalar + + x = (0:0.1:1)'; + yup = x; + ylow = -x; + upper = [x, yup]; + lower = [x, ylow]; + + coord = af_tools.utils.selig(upper, lower); + + verifyEqual(testCase, coord, [flipud(upper); lower(2:end, :)]); + +end -- GitLab