Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions nifticdf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ endif()


if(NIFTI_BUILD_TESTING AND NIFTI_BUILD_APPLICATIONS)
add_executable(${NIFTI_PACKAGE_PREFIX}nifticdf_range_test nifticdf_range_test.c)
target_link_libraries(${NIFTI_PACKAGE_PREFIX}nifticdf_range_test PRIVATE ${NIFTI_CDFLIB_NAME})
add_test( NAME ${NIFTI_PACKAGE_PREFIX}nifticdf_range_test
COMMAND $<TARGET_FILE:${NIFTI_PACKAGE_PREFIX}nifticdf_range_test> )

foreach(DISTRIBUTION CORREL TTEST FTEST ZSCORE CHISQ BETA BINOM GAMMA POISSON NORMAL FTEST_NONC CHISQ_NONC LOGISTIC LAPLACE UNIFORM TTEST_NONC WEIBULL CHI INVGAUSS EXTVAL PVAL LOGPVAL LOG10PVAL )
add_test( NAME ${NIFTI_PACKAGE_PREFIX}nifti_stats_${DISTRIBUTION}_test COMMAND $<TARGET_FILE:${NIFTI_PACKAGE_PREFIX}nifti_stats> 0:4:1 ${DISTRIBUTION})
add_test( NAME q${NIFTI_PACKAGE_PREFIX}nifti_stats_${DISTRIBUTION}_test COMMAND $<TARGET_FILE:${NIFTI_PACKAGE_PREFIX}nifti_stats> -q 0:4:1 ${DISTRIBUTION})
Expand Down
2 changes: 1 addition & 1 deletion nifticdf/nifticdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1892,7 +1892,7 @@ static double T5,T6,T7,T8,T9,T10,T12,T13;
/*
Check arguments
*/
if(!(*which < 1 && *which > 4)) goto S30;
if(!(*which < 1 || *which > 4)) goto S30;
if(!(*which < 1)) goto S10;
*bound = 1.0e0;
goto S20;
Expand Down
50 changes: 50 additions & 0 deletions nifticdf/nifticdf_range_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* cdfbin must reject an out-of-range "which" selector the way its ten
siblings in nifticdf.c do: *status = -1 and *bound = the limit. */

#include <stdio.h>
#include "nifticdf.h"

static int check(int which, double expected_bound)
{
int status = 999;
double p = 0.5, q = 0.5, s = 2.0, xn = 5.0, pr = 0.5, ompr = 0.5;
double bound = -999.0;

cdfbin(&which, &p, &q, &s, &xn, &pr, &ompr, &status, &bound);

if( status != -1 || bound != expected_bound ) {
fprintf(stderr, "** cdfbin(which=%d): status=%d bound=%g,"
" expected status=-1 bound=%g\n",
which, status, bound, expected_bound);
return 1;
}
printf("cdfbin(which=%d): status=%d bound=%g\n", which, status, bound);
return 0;
}

int main(void)
{
int errs = 0;

errs += check(9, 4.0); /* above the legal range */
errs += check(0, 1.0); /* below the legal range */

/* a legal selector must still compute, not report a range error */
{
int which = 1, status = 999;
double p = 0.0, q = 0.0, s = 2.0, xn = 5.0, pr = 0.5, ompr = 0.5;
double bound = -999.0;

cdfbin(&which, &p, &q, &s, &xn, &pr, &ompr, &status, &bound);
if( status != 0 ) {
fprintf(stderr, "** cdfbin(which=1): status=%d, expected 0\n", status);
errs++;
} else {
printf("cdfbin(which=1): status=0 p=%g\n", p);
}
}

if( errs ) { fprintf(stderr, "** %d failure(s)\n", errs); return 1; }
printf("nifticdf range test passed\n");
return 0;
}
Loading