Skip to content

Conversation

@MichaelStritt
Copy link
Contributor

Linked issue

Check out #690

Comments

Added some small unit tests.

@MichaelStritt MichaelStritt added the testing Either unit testing or full pipeline testing for bugs label Jul 1, 2021
@MichaelStritt MichaelStritt added this to the Release 1.8.0 milestone Jul 1, 2021
@MichaelStritt MichaelStritt self-assigned this Jul 1, 2021
@MichaelStritt MichaelStritt linked an issue Jul 1, 2021 that may be closed by this pull request
@MichaelStritt MichaelStritt requested a review from jan-petr July 2, 2021 08:17
@MichaelStritt
Copy link
Contributor Author

MichaelStritt commented Jul 5, 2021

QC Meeting (Henk & Michael)

  • standardize unit test names 👍 implemented in 37f8a83
  • get test name from script name 👍 implemented in 37f8a83
  • get test file type form script name as well 👍 implemented in 37f8a83
  • the image processing ones would be the most interesting ones, like xASL_spm_reslice e.g., maybe we can define test scenarios and requirements together

@MichaelStritt
Copy link
Contributor Author

Quick test run

====================================== TEST RESULTS ======================================

                        name                           unit          tests        passed
    ____________________________________________    __________    ____________    ______

    'xASL_adm_CatchNumbersFromString'               'function'    [1×3 struct]    true  
    'xASL_adm_CheckFileCount'                       'function'    [1×2 struct]    true  
    'xASL_adm_CompareLists'                         'function'    [1×2 struct]    true  
    'xASL_adm_CorrectName'                          'function'    [1×2 struct]    true  
    'xASL_adm_OrderFields'                          'function'    [1×1 struct]    true  
    'xASL_bids_BIDS2Legacy'                         'function'    [1×2 struct]    true  
    'xASL_bids_Config'                              'function'    [1×1 struct]    true  
    'xASL_bids_CreateDatasetDescriptionTemplate'    'function'    [1×2 struct]    true  
    'xASL_bids_JsonCheck'                           'function'    [1×3 struct]    true  
    'xASL_bids_VendorFieldCheck'                    'function'    [1×1 struct]    true  
    'xASL_io_ExportVTK'                             'function'    [1×5 struct]    true  
    'xASL_io_Nifti2Im'                              'function'    [1×1 struct]    true  
    'xASL_stat_PSNR'                                'function'    [1×2 struct]    true  
    'xASL_stat_QuantileNan'                         'function'    [1×1 struct]    true  
    'xASL_stat_StdNan'                              'function'    [1×1 struct]    true  
    'xASL_str2num'                                  'function'    [1×2 struct]    true  
    'xASL_test_GetLogContent'                       'function'    [1×2 struct]    true  
    'xASL_tsvRead'                                  'function'    [1×2 struct]    true  
    'xASL_tsvWrite'                                 'function'    [1×2 struct]    true  

==========================================================================================

@MichaelStritt
Copy link
Contributor Author

Test AMC (for backwards compatibility #574 )

image

Copy link
Member

@HenkMutsaerts HenkMutsaerts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice work, few minor suggestions


try
fclose('all');
catch
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also print message if you catch error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just removed it, this shouldn't fail anyway. Fix in bfbadb7

fclose(fid);
fid = fopen(fullfile(TestRepository,'UnitTesting','working_directory','test_3.txt'), 'wt');
fclose(fid);
fid1 = fopen(fullfile(TestRepository,'UnitTesting','working_directory','test_1.txt'), 'wt');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the function name in the commit title ;)
Weird why this doesn't work. In Linux there is a much easier way to create an empty file, which is called "touching" a file": system('touch test_1.txt');

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I always try to avoid system statements wherever possible, because then we have to take these Windows/Unix differences into account.

clc
fprintf('================================= TEST RESULTS =================================\n\n')
fprintf('====================================== TEST RESULTS ======================================\n\n')
disp(UnitTestsTable);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace disp or display by fprintf('%s\n', MessageToPrint);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the UnitTestsTable isn't a string, it's a table. You can't fprintf a table.


% Run your test here
y1 = xASL_stat_StdNan([0, 0, 0, 0, 0]);
y2 = xASL_stat_StdNan([0, 1, 2, 3, 4]);
Copy link
Member

@HenkMutsaerts HenkMutsaerts Jul 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MichaelStritt
I know that we are not ready to sweep across a number of parameters, but this would be the desired unit test, here we only test a limited amount of values. What do you think of creating a function xASL_ut_CreateInputValues, where you provide the upper and lower limit as well as the "resolution/number bins" of the values to test. So e.g., upper limit of 1,000,000 and lower limit of -1,000,000 with resolution 10 would create as input parameters for the unit test:

>> [-1000000:2000000/10:1000000]
ans =
  Columns 1 through 3
    -1000000     -800000     -600000
  Columns 4 through 6
     -400000     -200000           0
  Columns 7 through 9
      200000      400000      600000
  Columns 10 through 11
      800000     1000000

Also, we now do this unit test by assuming that another unit (==Matlab's std) is perfect. Whereas, this unit xASL_stat_StdNaN probably uses Matlab's std internally :) And whereas Matlab's std may differ between versions (theoretically)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, we now do this unit test by assuming that another unit (==Matlab's std) is perfect

I don't understand what you would do differently. Do you want to open an old math book and use reference values?

And whereas Matlab's std may differ between versions (theoretically)

Same here. Matlab is tested and approved software. If you don't trust Matlab to this level, you shouldn't use it at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that we are not ready to sweep across a number of parameters, but this would be the desired unit test, here we only test a limited amount of values.

Check out my comments for xASL_ut_UnitTest_function_str2num. We can implement this, but I don't think it's needed right now. Let's start as simple as possible. We should focus on testing more scripts and not on testing the few ones more thoroughly.

% Run your test here
numOutA = xASL_str2num('123');
numOutB = xASL_str2num('-123');
numOutC = xASL_str2num('123.456');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same suggestion here as for the other unit test below, why do you test 123456, why not 1234567890? But that's just my theoretical thinking probably :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the scientific point of view this is definitely a valid argument, but on the other hand we can't test for every integer/double value. In my opinion testing with one positive integer, one negative interger and a double should be enough. We can write something like...

index = 1;
for iTest = -1000:+1000
    testResult(index) = xASL_str2num(num2str(iTest));
    index = index +1;
end

... though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't expect relevant testing results here though. What could be more interesting is to test the cases where we have problems regarding rounding a bit better. So tests like:

numOutX = xASL_str2num('0.000000000001');
numOutY = xASL_str2num('-0.000000000001');

Copy link
Contributor

@jan-petr jan-petr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really great. We should start making stats on how many errors the UT discovered :)

I made some minor comments on what unusual cases to test - it's usually these that crash.

testTime = tic;

% Run your test here
strOut = xASL_adm_CorrectName('abc$%&def');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you want to have some backslashes and umlauts - these were a horror

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testTime = tic;

% Run your test here
y1 = xASL_stat_StdNan([0, 0, 0, 0, 0]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you want to test also 3D or 4D files...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testTime = tic;

% Run your test here
numOutA = xASL_str2num('123');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also stuff like 10e6 , 5.3e-6, .12, and some nonsense stuff - to see if it doesn't crash if a non-number is provided.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MichaelStritt
Copy link
Contributor Author

@HenkMutsaerts: I added everything you and @jan-petr asked for. If I'm not completely wrong, then the accuracy of xASL_stat_StdNan is really quite low. Especially if we look at the third unit test (Multidimensional test with NaN values (2D)). Can you re-approve so that we can merge the current state? Would be easier to add unit tests step by step.

Copy link
Member

@HenkMutsaerts HenkMutsaerts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

The std inaccuracy could be explained by the way of taking the mean difference. They should both do a parametric mean difference (i.e., "standard" deviation) as opposed to a non-parametric one (i.e., mean absolute difference). But one thing that we should check, is if they do sum(diff)/n or sum(diff)/(n-1). Matlab's std probably does the latter by default, which accounts for the loss of one degree of freedom (from calculating the mean diff), but I usually find sum(diff)/n easier to interpret.

I like these unit tests a lot. Would be good to still think of ways to generalize them.

@MichaelStritt MichaelStritt merged commit e431b9a into develop Jul 15, 2021
@MichaelStritt MichaelStritt deleted the test-#690_UnitTests branch July 15, 2021 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testing Either unit testing or full pipeline testing for bugs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add new unit tests

4 participants