|
| 1 | +% To run this test, you must first install a MINQ clone and add |
| 2 | +% /path/to/MINQ/m/minq5 |
| 3 | +% /path/to/MINQ/m/minq8 |
| 4 | +% to the MATLAB path. |
| 5 | +% |
| 6 | +% From MATLAB and the directory containing this file, execute |
| 7 | +% >> runtests |
| 8 | +% |
| 9 | +% If you would like to run this from a different folder that includes these |
| 10 | +% tests as a subfolder, then from that folder execute |
| 11 | +% >> runtests("IncludeSubfolders", true) |
| 12 | +% |
| 13 | +% To execute the test suite with coverage enabled and to generate an HTML-format |
| 14 | +% coverage report, execute from /path/to/IBCDFO/pounders/m |
| 15 | +% >> runtests("IncludeSubfolders", true, "ReportCoverageFor", pwd) |
| 16 | +% |
| 17 | + |
| 18 | +classdef TestCreateTrspSolver < matlab.unittest.TestCase |
| 19 | + properties (Constant) |
| 20 | + WARNING_SIMPLE = 'POUNDERS:simpleTrspSolver' |
| 21 | + ERROR_BAD_SOLVER = 'POUNDERS:badValue' |
| 22 | + % These should match the values used in create_trsp_solver(). |
| 23 | + SOLVER_SIMPLE = 1 |
| 24 | + SOLVER_MINQ5 = 2 |
| 25 | + SOLVER_MINQ8 = 3 |
| 26 | + end |
| 27 | + |
| 28 | + properties |
| 29 | + oldpath |
| 30 | + solvers |
| 31 | + emitWarnings |
| 32 | + end |
| 33 | + |
| 34 | + methods (TestMethodSetup) |
| 35 | + function setUp(testCase) |
| 36 | + testCase.solvers = [testCase.SOLVER_SIMPLE, ... |
| 37 | + testCase.SOLVER_MINQ5, ... |
| 38 | + testCase.SOLVER_MINQ8]; |
| 39 | + |
| 40 | + testCase.emitWarnings = struct([]); |
| 41 | + testCase.emitWarnings(1).solver = testCase.SOLVER_SIMPLE; |
| 42 | + testCase.emitWarnings(1).warnID = testCase.WARNING_SIMPLE; |
| 43 | + |
| 44 | + warning("on"); |
| 45 | + |
| 46 | + [here_path, ~, ~] = fileparts(mfilename('fullpath')); |
| 47 | + testCase.oldpath = addpath(fullfile(here_path, '..')); |
| 48 | + end |
| 49 | + end |
| 50 | + |
| 51 | + methods (TestMethodTeardown) |
| 52 | + function tearDown(testCase) |
| 53 | + path(testCase.oldpath); |
| 54 | + end |
| 55 | + end |
| 56 | + |
| 57 | + methods (Test) |
| 58 | + function testErrors(testCase) |
| 59 | + badSolvers = [min(testCase.solvers) - 1, ... |
| 60 | + max(testCase.solvers) + 1]; |
| 61 | + for i = 1:length(badSolvers) |
| 62 | + bad = badSolvers(i); |
| 63 | + testCase.assertError(@() create_trsp_solver(bad), ... |
| 64 | + testCase.ERROR_BAD_SOLVER); |
| 65 | + end |
| 66 | + end |
| 67 | + |
| 68 | + function testWarnings(testCase) |
| 69 | + for i = 1:length(testCase.emitWarnings) |
| 70 | + idx = testCase.emitWarnings(i).solver; |
| 71 | + warnID = testCase.emitWarnings(i).warnID; |
| 72 | + testCase.assertWarning(@() create_trsp_solver(idx), warnID); |
| 73 | + end |
| 74 | + end |
| 75 | + |
| 76 | + function testSuccessful(testCase) |
| 77 | + % Expected emission of specific warnings tested in testWarnings. |
| 78 | + % Ignore only those to silence expected warnings without |
| 79 | + % inadvertently silencing unintended warnings. |
| 80 | + warning("off", testCase.WARNING_SIMPLE); |
| 81 | + for i = 1:length(testCase.solvers) |
| 82 | + idx = testCase.solvers(i); |
| 83 | + solve_trsp = create_trsp_solver(idx); |
| 84 | + testCase.assertTrue(isa(solve_trsp, 'function_handle')); |
| 85 | + end |
| 86 | + warning("on", testCase.WARNING_SIMPLE); |
| 87 | + end |
| 88 | + end |
| 89 | + |
| 90 | +end |
0 commit comments