#############################################################################

[main]

[main - data:]

# method (for information only: the program scans the file name)
method: DISTR_DISCR

[main - header:]

## we need UNUR_DISTR_MAXPARAMS for a test:
\#include<unuran_config.h>

/* prototypes */

\#define COMPARE_SAMPLE_SIZE  (500)
\#define VIOLATE_SAMPLE_SIZE   (20)

double pmf(int k, const UNUR_DISTR *distr);
double icdf(int k, const UNUR_DISTR *distr);
int invcdf(double x, const UNUR_DISTR *distr);

#############################################################################

[new]

#############################################################################

[set]

[set - invalid NULL ptr:
   distr = NULL; ]

unur_distr_discr_set_pv( distr, NULL, 0 );
        --> expected_setfailed --> UNUR_ERR_NULL

unur_distr_discr_set_pmf( distr, pmf );
        --> expected_setfailed --> UNUR_ERR_NULL

unur_distr_discr_set_cdf( distr, icdf );
        --> expected_setfailed --> UNUR_ERR_NULL

unur_distr_discr_set_invcdf( distr, invcdf );
        --> expected_setfailed --> UNUR_ERR_NULL

unur_distr_discr_set_pmfstr( distr, "pmf" );
        --> expected_setfailed --> UNUR_ERR_NULL

unur_distr_discr_set_cdfstr( distr, "cdf" );
        --> expected_setfailed --> UNUR_ERR_NULL

unur_distr_discr_set_pmfparams( distr, NULL, 0 );
        --> expected_setfailed --> UNUR_ERR_NULL

unur_distr_discr_set_domain( distr, 0, 10 );
        --> expected_setfailed --> UNUR_ERR_NULL

unur_distr_discr_set_mode( distr, 0 );
        --> expected_setfailed --> UNUR_ERR_NULL

unur_distr_discr_set_pmfsum( distr, 1. );
        --> expected_setfailed --> UNUR_ERR_NULL


[set - invalid distribution type:
   distr = unur_distr_cont_new(); ]

unur_distr_discr_set_pv( distr, NULL, 0 );
        --> expected_setfailed --> UNUR_ERR_DISTR_INVALID

unur_distr_discr_set_pmf( distr, pmf );
        --> expected_setfailed --> UNUR_ERR_DISTR_INVALID

unur_distr_discr_set_cdf( distr, icdf );
        --> expected_setfailed --> UNUR_ERR_DISTR_INVALID

unur_distr_discr_set_invcdf( distr, invcdf );
        --> expected_setfailed --> UNUR_ERR_DISTR_INVALID

unur_distr_discr_set_pmfstr( distr, "exp(-k)" );
        --> expected_setfailed --> UNUR_ERR_DISTR_INVALID

unur_distr_discr_set_cdfstr( distr, "exp(-k)" );
        --> expected_setfailed --> UNUR_ERR_DISTR_INVALID

unur_distr_discr_set_pmfparams( distr, NULL, 0 );
        --> expected_setfailed --> UNUR_ERR_DISTR_INVALID

unur_distr_discr_set_domain( distr, 0, 10 );
        --> expected_setfailed --> UNUR_ERR_DISTR_INVALID

unur_distr_discr_set_mode( distr, 0 );
        --> expected_setfailed --> UNUR_ERR_DISTR_INVALID

unur_distr_discr_set_pmfsum( distr, 1. );
        --> expected_setfailed --> UNUR_ERR_DISTR_INVALID


[set - invalid NULL ptr: 
   distr = unur_distr_discr_new(); ]

unur_distr_discr_set_pmf( distr, NULL );
        --> expected_setfailed --> UNUR_ERR_NULL

unur_distr_discr_set_cdf( distr, NULL );
        --> expected_setfailed --> UNUR_ERR_NULL

unur_distr_discr_set_invcdf( distr, NULL );
        --> expected_setfailed --> UNUR_ERR_NULL

unur_distr_discr_set_pmfstr( distr, NULL );
        --> expected_setfailed --> UNUR_ERR_NULL

unur_distr_discr_set_cdfstr( distr, NULL );
        --> expected_setfailed --> UNUR_ERR_NULL

unur_distr_discr_set_pmfparams( distr, NULL, 1 );
        --> expected_setfailed --> UNUR_ERR_NULL


[set - invalid parameters: 
   double pv[] = {1.,2.,3.};
   distr = unur_distr_discr_new(); ]

unur_distr_discr_set_pmfstr( distr, "" );
        --> expected_setfailed --> UNUR_ERR_DISTR_SET

unur_distr_discr_set_pmfstr( distr, "beta(2.)" );
        --> expected_setfailed --> UNUR_ERR_DISTR_SET

unur_distr_discr_set_cdfstr( distr, "" );
        --> expected_setfailed --> UNUR_ERR_DISTR_SET

unur_distr_discr_set_cdfstr( distr, "beta(2.)" );
        --> expected_setfailed --> UNUR_ERR_DISTR_SET

unur_distr_discr_set_pmfparams( distr, pv, -1 );
        --> expected_setfailed --> UNUR_ERR_DISTR_NPARAMS

unur_distr_discr_set_pmfparams( distr, pv, UNUR_DISTR_MAXPARAMS +1 );
        --> expected_setfailed --> UNUR_ERR_DISTR_NPARAMS

unur_distr_discr_set_domain( distr, 10, 1 );
        --> expected_setfailed --> UNUR_ERR_DISTR_SET

unur_distr_discr_set_pmfsum( distr, -1. );
        --> expected_setfailed --> UNUR_ERR_DISTR_SET


#############################################################################

[get]

[get - invalid NULL ptr: 
   distr = NULL; ]

unur_distr_discr_get_pv( distr, NULL );
        --> expected_zero --> UNUR_ERR_NULL

unur_distr_discr_get_pmf( distr );
        --> expected_NULL --> UNUR_ERR_NULL

unur_distr_discr_get_cdf( distr );
        --> expected_NULL --> UNUR_ERR_NULL

unur_distr_discr_get_invcdf( distr );
        --> expected_NULL --> UNUR_ERR_NULL

unur_distr_discr_get_pmfstr( distr );
        --> expected_NULL --> UNUR_ERR_NULL

unur_distr_discr_get_cdfstr( distr );
        --> expected_NULL --> UNUR_ERR_NULL

unur_distr_discr_get_pmfparams( distr, NULL );
        --> expected_zero --> UNUR_ERR_NULL

unur_distr_discr_get_pmfsum( distr );
        --> expected_INFINITY --> UNUR_ERR_NULL

unur_distr_discr_make_pv( distr );
        --> expected_zero --> UNUR_ERR_NULL


[get - invalid distribution type:
   int ia, ib;
   distr = unur_distr_cont_new(); ]

unur_distr_discr_get_pmf( distr );
        --> expected_NULL --> UNUR_ERR_DISTR_INVALID

unur_distr_discr_get_cdf( distr );
        --> expected_NULL --> UNUR_ERR_DISTR_INVALID

unur_distr_discr_get_invcdf( distr );
        --> expected_NULL --> UNUR_ERR_DISTR_INVALID

unur_distr_discr_get_pmfstr( distr );
        --> expected_NULL --> UNUR_ERR_DISTR_INVALID

unur_distr_discr_get_cdfstr( distr );
        --> expected_NULL --> UNUR_ERR_DISTR_INVALID

unur_distr_discr_get_pv( distr, NULL );
        --> expected_zero --> UNUR_ERR_DISTR_INVALID

unur_distr_discr_get_domain( distr, &ia, &ib );
        --> expected_setfailed --> UNUR_ERR_DISTR_INVALID

unur_distr_discr_get_pmfparams( distr, NULL );
        --> expected_zero --> UNUR_ERR_DISTR_INVALID

unur_distr_discr_get_pmfsum( distr );
        --> expected_INFINITY --> UNUR_ERR_DISTR_INVALID

unur_distr_discr_make_pv( distr );
        --> expected_zero --> UNUR_ERR_DISTR_INVALID


[get - parameters not unknown:
   distr = unur_distr_discr_new(); ]

unur_distr_discr_get_pmfstr( distr );
        --> expected_NULL --> UNUR_ERR_NULL

unur_distr_discr_get_cdfstr( distr );
        --> expected_NULL --> UNUR_ERR_NULL

unur_distr_discr_get_pmfsum( distr );
        --> expected_INFINITY --> UNUR_ERR_DISTR_GET

unur_distr_discr_get_mode( distr );
        --> expected_INTMAX --> UNUR_ERR_DISTR_GET

unur_distr_discr_make_pv( distr );
        --> expected_zero --> UNUR_ERR_DISTR_GET


#############################################################################

[chg]

[chg - invalid NULL ptr: 
   distr = NULL; ]

unur_distr_discr_upd_mode( distr );
        --> expected_setfailed --> UNUR_ERR_NULL

unur_distr_discr_upd_pmfsum( distr );
        --> expected_setfailed --> UNUR_ERR_NULL


[chg - invalid distribution type:
   distr = unur_distr_cont_new(); ]

unur_distr_discr_upd_mode( distr );
        --> expected_setfailed --> UNUR_ERR_DISTR_INVALID

unur_distr_discr_upd_pmfsum( distr );
        --> expected_setfailed --> UNUR_ERR_DISTR_INVALID


[chg - missing data:
   distr = unur_distr_discr_new(); ]

unur_distr_discr_upd_mode( distr );
        --> expected_setfailed --> UNUR_ERR_DISTR_DATA

unur_distr_discr_upd_pmfsum( distr );
        --> expected_setfailed --> UNUR_ERR_DISTR_DATA


##############################################################################

# [init]

#############################################################################

# [reinit]

#############################################################################

[sample]

[sample - invalid NULL ptr: 
   distr = NULL; ]

unur_distr_discr_eval_pmf( 1, distr );
        --> expected_INFINITY --> UNUR_ERR_NULL

unur_distr_discr_eval_cdf( 1, distr );
        --> expected_INFINITY --> UNUR_ERR_NULL

unur_distr_discr_eval_invcdf( 0.5, distr );
        --> expected_INTMAX --> UNUR_ERR_NULL

#.....................................................................

[sample - invalid distribution object:
   distr = unur_distr_cont_new(); ]

unur_distr_discr_eval_pmf( 1, distr );
        --> expected_INFINITY --> UNUR_ERR_DISTR_INVALID

unur_distr_discr_eval_cdf( 1, distr );
        --> expected_INFINITY --> UNUR_ERR_DISTR_INVALID

unur_distr_discr_eval_invcdf( 0.5, distr );
        --> expected_INTMAX --> UNUR_ERR_DISTR_INVALID

#.....................................................................

[sample - missing data:
   distr = unur_distr_discr_new(); ]

unur_distr_discr_eval_pmf( 1, distr );
        --> expected_INFINITY --> UNUR_ERR_DISTR_DATA

unur_distr_discr_eval_cdf( 1, distr );
        --> expected_INFINITY --> UNUR_ERR_DISTR_DATA

unur_distr_discr_eval_invcdf( 0.5, distr );
        --> expected_INTMAX --> UNUR_ERR_DISTR_DATA


#############################################################################

# [validate]

#############################################################################
#############################################################################

[verbatim]

double pmf(int k ATTRIBUTE__UNUSED, const UNUR_DISTR *distr ATTRIBUTE__UNUSED) { return 1.; }
double icdf(int k ATTRIBUTE__UNUSED, const UNUR_DISTR *distr ATTRIBUTE__UNUSED) { return 1.; }
int invcdf(double x ATTRIBUTE__UNUSED, const UNUR_DISTR *distr ATTRIBUTE__UNUSED) { return 1; }

#############################################################################
