-
Notifications
You must be signed in to change notification settings - Fork 13
Test #690 unit tests #691
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test #690 unit tests #691
Conversation
QC Meeting (Henk & Michael)
|
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
========================================================================================== |
Test AMC (for backwards compatibility #574 ) |
HenkMutsaerts
left a comment
There was a problem hiding this 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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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');
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
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]); |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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');
jan-petr
left a comment
There was a problem hiding this 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'); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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]); |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
@HenkMutsaerts: I added everything you and @jan-petr asked for. If I'm not completely wrong, then the accuracy of |
HenkMutsaerts
left a comment
There was a problem hiding this 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.
Minor fix for xASL_stat_QuantileNan, fix header of StdNan unit test
Added module tests for Structural, ASL, and Population. Renamed ExploreASL_Master unit test. Added TSV export functionality to unit testing master script.
d30610e to
e431b9a
Compare

Linked issue
Check out #690
Comments
Added some small unit tests.