|
1 | 1 | function test_suite = test_setTargetPositionInSequence %#ok<*STOUT> |
2 | | - |
| 2 | + |
3 | 3 | initEnv(); |
4 | | - |
| 4 | + |
5 | 5 | try % assignment of 'localfunctions' is necessary in Matlab >= 2016 |
6 | 6 | test_functions = localfunctions(); %#ok<*NASGU> |
7 | 7 | catch % no problem; early Matlab versions can use initTestSuite fine |
|
10 | 10 | end |
11 | 11 |
|
12 | 12 | function test_setTargetPositionInSequenceBasic() |
13 | | - |
| 13 | + |
14 | 14 | seqLength = 12; |
15 | 15 | nbTarget = 3; |
16 | 16 | forbiddenPos = [1 5 10]; |
17 | | - |
| 17 | + |
18 | 18 | % Create a hundred draws of targer positiona and ensure that |
19 | 19 | % - the forbidden position are never drawn |
20 | 20 | % - the interval between target is superior to 1 |
21 | 21 | for i = 1:100 |
22 | 22 | chosenPositions(i, :) = setTargetPositionInSequence(seqLength, nbTarget, forbiddenPos); |
23 | 23 | end |
24 | | - |
| 24 | + |
25 | 25 | assertFalse(any(ismember(chosenPositions(:), forbiddenPos))); |
26 | | - |
| 26 | + |
27 | 27 | interval = abs(diff(chosenPositions, [], 2)); |
28 | 28 | assertTrue(all(interval(:) > 1)); |
29 | | - |
| 29 | + |
30 | 30 | end |
31 | 31 |
|
32 | 32 | function initEnv |
33 | | - |
34 | | - octaveVersion = '4.0.3'; |
35 | | - matlabVersion = '8.6.0'; |
36 | | - |
37 | | - installlist = {'io', 'statistics', 'image'}; |
38 | | - |
| 33 | + |
| 34 | + installlist = {'io', 'statistics'}; |
| 35 | + |
39 | 36 | if isOctave |
40 | | - |
41 | | - % Exit if min version is not satisfied |
42 | | - if ~compare_versions(OCTAVE_VERSION, octaveVersion, '>=') |
43 | | - error('Minimum required Octave version: %s', octaveVersion); |
44 | | - end |
45 | | - |
| 37 | + |
46 | 38 | for ii = 1:length(installlist) |
| 39 | + |
| 40 | + packageName = installlist{ii}; |
| 41 | + |
47 | 42 | try |
48 | 43 | % Try loading Octave packages |
49 | | - disp(['loading ' installlist{ii}]); |
50 | | - pkg('load', installlist{ii}); |
51 | | - |
| 44 | + disp(['loading ' packageName]); |
| 45 | + pkg('load', packageName); |
| 46 | + |
52 | 47 | catch |
53 | | - errorcount = 1; |
54 | | - while errorcount % Attempt twice in case installation fails |
55 | | - try |
56 | | - pkg('install', '-forge', installlist{ii}); |
57 | | - pkg('load', installlist{ii}); |
58 | | - errorcount = 0; |
59 | | - catch err |
60 | | - errorcount = errorcount + 1; |
61 | | - if errorcount > 2 |
62 | | - error(err.message); |
63 | | - end |
64 | | - end |
65 | | - end |
| 48 | + tryInstallFromForge(packageName); |
66 | 49 | end |
67 | 50 | end |
| 51 | + |
| 52 | + end |
| 53 | + |
| 54 | +end |
68 | 55 |
|
69 | | - else % MATLAB ---------------------------- |
70 | | - |
71 | | - if verLessThan('matlab', matlabVersion) |
72 | | - error('Sorry, minimum required version is R2017b. :('); |
| 56 | +function tryInstallFromForge(packageName) |
| 57 | + |
| 58 | + errorcount = 1; |
| 59 | + while errorcount % Attempt twice in case installation fails |
| 60 | + try |
| 61 | + pkg('install', '-forge', packageName); |
| 62 | + pkg('load', packageName); |
| 63 | + errorcount = 0; |
| 64 | + catch err |
| 65 | + errorcount = errorcount + 1; |
| 66 | + if errorcount > 2 |
| 67 | + error(err.message); |
| 68 | + end |
73 | 69 | end |
74 | | - |
75 | 70 | end |
76 | | - |
| 71 | + |
77 | 72 | end |
0 commit comments