blob: 93b49f07edc96bba53caa46ba181d8e07fcb75a0 [file] [log] [blame]
/* -----------------------------------------------------------------------------
* Test probability functions.
* -------------------------------------------------------------------------- */
-- bernoulli_cdf
SELECT assert(
bernoulli_cdf(NULL, 1) IS NULL AND
bernoulli_cdf(1, NULL) IS NULL,
'Bernoulli CDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(bernoulli_cdf('NaN', 1) ) AND
isnan(bernoulli_cdf(1, 'NaN') ) ,
'Bernoulli CDF: Wrong handling of NaNs.'
);
SELECT assert(
bernoulli_cdf(0, 0.3) = 0.7 AND
bernoulli_cdf(0.7, 0.3) = 0.7 AND
bernoulli_cdf(0.8, 0.3) = 0.7 AND
bernoulli_cdf(1, 0.3) = 1 AND
bernoulli_cdf(2, 0.3) = 1 AND
bernoulli_cdf('Inf', 0.3) = 1 AND
bernoulli_cdf('-Inf', 0.3) = 0 AND
bernoulli_cdf(-0.1, 0.3) = 0,
'Bernoulli CDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT bernoulli_cdf(0.5, -1)$$) AND
check_if_raises_error($$SELECT bernoulli_cdf(0.5, 2)$$) ,
'Bernoulli CDF: succ_prob out of range [0,1] does not raise error.'
);
-- bernoulli_pmf
SELECT assert(
bernoulli_pmf(NULL, 1) IS NULL AND
bernoulli_pmf(1, NULL) IS NULL,
'Bernoulli PMF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(bernoulli_pmf(1, 'NaN') ) ,
'Bernoulli PMF: Wrong handling of NaNs.'
);
SELECT assert(
bernoulli_pmf(0, 1) = 0 AND
bernoulli_pmf(1, 1) = 1 AND
bernoulli_pmf(0, 0.3) = 0.7 AND
bernoulli_pmf(1, 0.3) = 0.3 AND
bernoulli_pmf(2, 0.3) = 0 AND
bernoulli_pmf(-1, 0.3) = 0 AND
bernoulli_pmf(-1, 0.3) = 0,
'Bernoulli PMF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT bernoulli_pmf(5, -1)$$) AND
check_if_raises_error($$SELECT bernoulli_pmf(5, 2)$$) ,
'Bernoulli PMF: succ_prob out of range [0,1] does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT bernoulli_pmf(0.5, 0.3)$$),
'Bernoulli PMF: random variable not in {0,1} does not raise error.'
);
-- bernoulli_quantile
SELECT assert(
bernoulli_quantile(NULL, 1) IS NULL AND
bernoulli_quantile(1, NULL) IS NULL,
'Bernoulli Quantile: Wrong handling of NULLs.'
);
SELECT assert(
isnan(bernoulli_quantile('NaN', 1) ) AND
isnan(bernoulli_quantile(1, 'NaN') ) ,
'Bernoulli Quantile: Wrong handling of NaNs.'
);
SELECT assert(
bernoulli_quantile(0, 1) = 0 AND
bernoulli_quantile(1, 1) = 1 AND
bernoulli_quantile(0, 0.3) = 0 AND
bernoulli_quantile(0.7, 0.3) = 0 AND
bernoulli_quantile(0.8, 0.3) = 1 AND
bernoulli_quantile(1, 0.3) = 1,
'Bernoulli Quantile: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT bernoulli_quantile(0.5, -1)$$) AND
check_if_raises_error($$SELECT bernoulli_quantile(0.5, 2)$$) ,
'Bernoulli Quantile: succ_prob out of range [0,1] does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT bernoulli_quantile(-1, 1)$$) AND
check_if_raises_error($$SELECT bernoulli_quantile(2, 1)$$) ,
'Bernoulli Quantile: CDF out of range [0,1] does not raise error.'
);
-- beta_cdf
SELECT assert(
beta_cdf(NULL, 1, 1) IS NULL AND
beta_cdf(1, NULL, 1) IS NULL AND
beta_cdf(1, 1, NULL) IS NULL,
'Beta CDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(beta_cdf('NaN', 1, 1) ) AND
isnan(beta_cdf(1, 'NaN', 1) ) AND
isnan(beta_cdf(1, 1, 'NaN') ),
'Beta CDF: Wrong handling of NaNs.'
);
SELECT assert(
beta_cdf(-1, 1, 1) = 0 AND
beta_cdf(0, 1, 1) = 0 AND
beta_cdf(1, 1, 1) = 1 AND
beta_cdf('Inf', 1, 1) = 1 AND
relative_error(beta_cdf(0.5, 1, 1), 0.5) < 1e-5 AND
beta_cdf(-1, 1, 2) = 0 AND
beta_cdf(0, 1, 2) = 0 AND
beta_cdf(1, 1, 2) = 1 AND
beta_cdf('Inf', 1, 2) = 1 AND
relative_error(beta_cdf(1, 1, 2), 1) < 1e-5,
'Beta CDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT beta_cdf(0.5, 0, 1)$$) AND
check_if_raises_error($$SELECT beta_cdf(0.5, 1, 0)$$) AND
check_if_raises_error($$SELECT beta_cdf(0.5, -1, 1)$$) AND
check_if_raises_error($$SELECT beta_cdf(0.5, 1, -1)$$),
'Beta CDF: parameters less or equal to 0 does not raise error.'
);
-- beta_pdf
SELECT assert(
beta_pdf(NULL, 1, 1) IS NULL AND
beta_pdf(1, NULL, 1) IS NULL AND
beta_pdf(1, 1, NULL) IS NULL,
'Beta PDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(beta_pdf('NaN', 1, 1) ) AND
isnan(beta_pdf(1, 'NaN', 1) ) AND
isnan(beta_pdf(1, 1, 'NaN') ),
'Beta PDF: Wrong handling of NaNs.'
);
SELECT assert(
beta_pdf(-1, 1, 1) = 0 AND
beta_pdf(-0.1, 1, 1) = 0 AND
beta_pdf(1.1, 1, 1) = 0 AND
beta_pdf('Inf', 1, 1) = 0 AND
relative_error(beta_pdf(0.5, 1, 1), 1) < 1e-5 AND
beta_pdf(0, 0.5, 1) = 'Inf' AND
beta_pdf(1, 0.5, 1) = 0.5 AND
beta_pdf(0, 1, 0.5) = 0.5 AND
beta_pdf(1, 1, 0.5) = 'Inf' AND
beta_pdf(0, 0.5, 0.5) = 'Inf' AND
beta_pdf(1, 0.5, 0.5) = 'Inf' AND
beta_pdf(-1, 2, 1) = 0 AND
beta_pdf(-0.1, 2, 1) = 0 AND
beta_pdf(1.1, 2, 1) = 0 AND
beta_pdf('Inf', 2, 1) = 0 AND
relative_error(beta_pdf(0.5, 2, 1), 1) < 1e-5 ,
'Beta PDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT beta_pdf(0.5, 0, 1)$$) AND
check_if_raises_error($$SELECT beta_pdf(0.5, 1, 0)$$) AND
check_if_raises_error($$SELECT beta_pdf(0.5, -1, 1)$$) AND
check_if_raises_error($$SELECT beta_pdf(0.5, 1, -1)$$),
'Beta PDF: parameters less or equal to 0 does not raise error.'
);
-- beta_quantile
SELECT assert(
beta_quantile(NULL, 1, 1) IS NULL AND
beta_quantile(1, NULL, 1) IS NULL AND
beta_quantile(1, 1, NULL) IS NULL,
'Beta Quantile: Wrong handling of NULLs.'
);
SELECT assert(
isnan(beta_quantile('NaN', 1, 1) ) AND
isnan(beta_quantile(1, 'NaN', 1) ) AND
isnan(beta_quantile(1, 1, 'NaN') ),
'Beta Quantile: Wrong handling of NaNs.'
);
SELECT assert(
beta_quantile(0, 1, 1) = 0 AND
beta_quantile(1, 1, 1) = 1 AND
relative_error(beta_quantile(0.8, 1, 1), 0.8) < 1e-5 AND
beta_quantile(0, 2, 1) = 0 AND
beta_quantile(1, 2, 1) = 1 AND
relative_error(beta_quantile(0.8, 2, 1), 0.8944272) < 1e-5 ,
'Beta Quantile: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT beta_quantile(0.5, 0, 1)$$) AND
check_if_raises_error($$SELECT beta_quantile(0.5, 1, 0)$$) AND
check_if_raises_error($$SELECT beta_quantile(0.5, -1, 1)$$) AND
check_if_raises_error($$SELECT beta_quantile(0.5, 1, -1)$$),
'Beta Quantile: parameters less or equal to 0 does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT beta_quantile(-1, 1, 1)$$) AND
check_if_raises_error($$SELECT beta_quantile(2, 1, 1)$$) ,
'Beta Quantile: CDF out of range [0,1] does not raise error.'
);
-- binomial_cdf
SELECT assert(
binomial_cdf(NULL, 1, 1) IS NULL AND
binomial_cdf(1, NULL, 1) IS NULL AND
binomial_cdf(1, 1, NULL) IS NULL,
'Binomial CDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(binomial_cdf('NaN', 1, 1) ) AND
isnan(binomial_cdf(1, 1, 'NaN') ),
'Binomial CDF: Wrong handling of NaNs.'
);
SELECT assert(
relative_error(binomial_cdf(3, 11, 0.4), 0.2962843) < 1e-5 AND
binomial_cdf(3, 11, 0.4) = binomial_cdf(3.2, 11, 0.4) AND
binomial_cdf(11, 11, 0.4) = 1 AND
binomial_cdf(12, 11, 0.4) = 1 AND
binomial_cdf('-Inf',11, 0.4) = 0 AND
binomial_cdf('Inf', 11, 0.4) = 1 AND
binomial_cdf(0, 0, 0.4) = 1 AND
binomial_cdf(1, 0, 0.4) = 1 AND
binomial_cdf(-1, 0, 0.4) = 0 AND
binomial_cdf('-Inf', 0, 0.4) = 0 AND
binomial_cdf('Inf', 0, 0.4) = 1,
'Binomial CDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT binomial_cdf(0, 1, 2)$$) AND
check_if_raises_error($$SELECT binomial_cdf(0, 1, -1)$$),
'Binomial CDF: succ_prob out of range [0,1] does not raise error.'
);
-- binomial_pmf
SELECT assert(
binomial_pmf(NULL, 1, 1) IS NULL AND
binomial_pmf(1, NULL, 1) IS NULL AND
binomial_pmf(1, 1, NULL) IS NULL,
'Binomial PMF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(binomial_pmf(1, 1, 'NaN') ),
'Binomial PMF: Wrong handling of NaNs.'
);
SELECT assert(
relative_error(binomial_pmf(3, 11, 0.4), 0.1773674) < 1e-5 AND
binomial_pmf(12, 11, 0.4) = 0 AND
binomial_pmf(-1, 11, 0.4) = 0 AND
binomial_pmf(0, 0, 0.4) = 1 AND
binomial_pmf(1, 0, 0.4) = 0 AND
binomial_pmf(-1, 0, 0.4) = 0,
'Binomial PMF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT binomial_pmf(0, 1, 2)$$) AND
check_if_raises_error($$SELECT binomial_pmf(0, 1, -1)$$),
'Binomial PMF: succ_prob out of range [0,1] does not raise error.'
);
-- binomial_quantile
SELECT assert(
binomial_quantile(NULL, 1, 1) IS NULL AND
binomial_quantile(1, NULL, 1) IS NULL AND
binomial_quantile(1, 1, NULL) IS NULL,
'Binomial quantile: Wrong handling of NULLs.'
);
SELECT assert(
isnan(binomial_quantile('NaN', 1, 1) ) AND
isnan(binomial_quantile(1, 1, 'NaN') ),
'Binomial quantile: Wrong handling of NaNs.'
);
SELECT assert(
relative_error(binomial_quantile(0.2962843, 11, 0.4), 3) < 1e-5 AND
binomial_quantile(0, 11, 0.4) = 0 AND
binomial_quantile(1, 11, 0.4) = 11 AND
binomial_quantile(0.5, 20, 1) = 20 AND
binomial_quantile(0.5, 20, 0) = 0,
'Binomial quantile: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT binomial_quantile(-1, 1, 0.4)$$) AND
check_if_raises_error($$SELECT binomial_quantile(2, 1, 0.4)$$),
'Binomial quantile: succ_prob out of range [0,1] does not raise error.'
);
-- cauchy_cdf
SELECT assert(
cauchy_cdf(NULL, 1, 1) IS NULL AND
cauchy_cdf(1, NULL, 1) IS NULL AND
cauchy_cdf(1, 1, NULL) IS NULL,
'Cauchy CDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(cauchy_cdf('NaN', 1, 1) ) AND
isnan(cauchy_cdf(1, 'NaN', 1) ) AND
isnan(cauchy_cdf(1, 1, 'NaN') ),
'Cauchy CDF: Wrong handling of NaNs.'
);
SELECT assert(
cauchy_cdf('-Inf', 1, 2) = 0 AND
cauchy_cdf('Inf', 1, 2) = 1 AND
relative_error(cauchy_cdf(2, 1, 2), 0.6475836) < 1e-5 AND
relative_error(cauchy_cdf(-2, 1, 2), 0.187167) < 1e-5,
'Cauchy CDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT cauchy_cdf(0.5, 1, 0)$$) AND
check_if_raises_error($$SELECT cauchy_cdf(0.5, 1, -1)$$),
'Cauchy CDF: scale less than or equal to 0 does not raise error.'
);
-- cauchy_pdf
SELECT assert(
cauchy_pdf(NULL, 1, 1) IS NULL AND
cauchy_pdf(1, NULL, 1) IS NULL AND
cauchy_pdf(1, 1, NULL) IS NULL,
'Cauchy PDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(cauchy_pdf('NaN', 1, 1) ) AND
isnan(cauchy_pdf(1, 'NaN', 1) ) AND
isnan(cauchy_pdf(1, 1, 'NaN') ),
'Cauchy PDF: Wrong handling of NaNs.'
);
SELECT assert(
cauchy_pdf('-Inf', 1, 2) = 0 AND
cauchy_pdf('Inf', 1, 2) = 0 AND
relative_error(cauchy_pdf(2, 1, 2), 0.127324) < 1e-5 AND
relative_error(cauchy_pdf(-2, 1, 2), 0.04897075) < 1e-5,
'Cauchy PDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT cauchy_pdf(0.5, 1, 0)$$) AND
check_if_raises_error($$SELECT cauchy_pdf(0.5, 1, -1)$$),
'Cauchy PDF: scale less than or equal to 0 does not raise error.'
);
-- cauchy_quantile
SELECT assert(
cauchy_quantile(NULL, 1, 1) IS NULL AND
cauchy_quantile(1, NULL, 1) IS NULL AND
cauchy_quantile(1, 1, NULL) IS NULL,
'Cauchy Quantile: Wrong handling of NULLs.'
);
SELECT assert(
isnan(cauchy_quantile('NaN', 1, 1) ) AND
isnan(cauchy_quantile(1, 'NaN', 1) ) AND
isnan(cauchy_quantile(1, 1, 'NaN') ),
'Cauchy Quantile: Wrong handling of NaNs.'
);
SELECT assert(
cauchy_quantile(0, 1, 1) = '-Inf' AND
cauchy_quantile(1, 1, 1) = 'Inf' AND
relative_error(cauchy_quantile(0.6475836, 1, 2), 2) < 1e-5 AND
relative_error(cauchy_quantile(0.187167, 1, 2), -2) < 1e-5,
'Cauchy Quantile: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT cauchy_quantile(0.5, 1, 0)$$) AND
check_if_raises_error($$SELECT cauchy_quantile(0.5, 1, -1)$$),
'Cauchy Quantile: scale less than or equal to 0 does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT cauchy_quantile(-1, 1, 1)$$) AND
check_if_raises_error($$SELECT cauchy_quantile(2, 1, 1)$$),
'Cauchy Quantile: succ_prob out of range [0,1] does not raise error.'
);
-- chi_squared_cdf
SELECT assert(
chi_squared_cdf(NULL, 1) IS NULL AND
chi_squared_cdf(1, NULL) IS NULL,
'Chi-Squared CDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(chi_squared_cdf('NaN', 1) ) AND
isnan(chi_squared_cdf(1, 'NaN') ),
'Chi-Squared CDF: Wrong handling of NaNs.'
);
SELECT assert(
chi_squared_cdf(-1, 1) = 0 AND
chi_squared_cdf(0, 1) = 0 AND
chi_squared_cdf('Inf', 1) = 1 AND
relative_error(chi_squared_cdf(1, 1), 0.6826895) < 1e-5,
'Chi-Squared CDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT chi_squared_cdf(1.5, 0)$$),
'Chi-Squared CDF: degree of freedom equal to 0 does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT chi_squared_cdf(1.5, -1)$$),
'Chi-Squared CDF: degree of freedom less than 0 does not raise error.'
);
-- chi_squared_pdf
SELECT assert(
chi_squared_pdf(NULL, 1) IS NULL AND
chi_squared_pdf(1, NULL) IS NULL,
'Chi-Squared PDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(chi_squared_pdf('NaN', 1) ) AND
isnan(chi_squared_pdf(1, 'NaN') ),
'Chi-Squared PDF: Wrong handling of NaNs.'
);
SELECT assert(
chi_squared_pdf(-1, 1) = 0 AND
chi_squared_pdf(0, 1) = 'Inf' AND
chi_squared_pdf(0, 2) = 0.5 AND
chi_squared_pdf(0, 3) = 0 AND
chi_squared_pdf('Inf', 1) = 0 AND
relative_error(chi_squared_pdf(1, 1), 0.2419707) < 1e-5,
'Chi-Squared PDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT chi_squared_pdf(1.5, 0)$$),
'Chi-Squared PDF: freedom equal to 0 does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT chi_squared_pdf(1.5, -1)$$),
'Chi-Squared PDF: degree of freedom less than 0 does not raise error.'
);
-- chi_squared_quantile
SELECT assert(
chi_squared_quantile(NULL, 1) IS NULL AND
chi_squared_quantile(1, NULL) IS NULL,
'Chi-Squared Quantile: Wrong handling of NULLs.'
);
SELECT assert(
isnan(chi_squared_quantile('NaN', 1) ) AND
isnan(chi_squared_quantile(1, 'NaN') ),
'Chi-Squared Quantile: Wrong handling of NaNs.'
);
SELECT assert(
chi_squared_quantile(0, 1) = 0 AND
chi_squared_quantile(0, 2) = 0 AND
chi_squared_quantile(0, 3) = 0 AND
chi_squared_quantile(1, 1) = 'Inf' AND
relative_error(chi_squared_quantile(0.5, 1), 0.4549364) < 1e-5,
'Chi-Squared Quantile: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT chi_squared_quantile(-1, 2)$$),
'Chi-Squared Quantile: non-positive CDF does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT chi_squared_quantile(1.5, 0)$$),
'Chi-Squared Quantile: freedom equal to 0 does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT chi_squared_quantile(1.5, -1)$$),
'Chi-Squared Quantile freedom less than 0 does not raise error.'
);
-- exponential_cdf
SELECT assert(
exponential_cdf(NULL, 1) IS NULL AND
exponential_cdf(1, NULL) IS NULL,
'Exponential CDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan( exponential_cdf('NaN', 1) ) AND
isnan( exponential_cdf(1, 'NaN') ),
'Exponential CDF: Wrong handling of NaNs.'
);
SELECT assert(
relative_error(exponential_cdf(1, 1) , 0.6321206) < 1e-5 AND
exponential_cdf(-1, 1) = 0 AND
exponential_cdf(0, 1) = 0 AND
exponential_cdf('Inf', 1) = 1,
'Exponential CDF: Wrong values for regular values.'
);
SELECT assert(
check_if_raises_error($$SELECT exponential_cdf(1, 0)$$) AND
check_if_raises_error($$SELECT exponential_cdf(1, -1)$$) AND
check_if_raises_error($$SELECT exponential_cdf(0.5, 'Inf')$$),
'Exponential CDF: lambda ouside of (0, infinity) does not raise error.'
);
-- exponential_pdf
SELECT assert(
exponential_pdf(NULL, 1) IS NULL AND
exponential_pdf(1, NULL) IS NULL,
'Exponential PDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan( exponential_pdf('NaN', 1) ) AND
isnan( exponential_pdf(1, 'NaN') ),
'Exponential PDF: Wrong handling of NaNs.'
);
SELECT assert(
relative_error(exponential_pdf(1, 1), 0.3678794) < 1e-5 AND
exponential_pdf(-1, 1) = 0 AND
exponential_pdf(0, 1) = 1 AND
exponential_pdf('Inf', 1) = 0,
'Exponential PDF: Wrong values for regular values.'
);
SELECT assert(
check_if_raises_error($$SELECT exponential_pdf(1, 0)$$) AND
check_if_raises_error($$SELECT exponential_pdf(1, -1)$$) AND
check_if_raises_error($$SELECT exponential_pdf(0.5, 'Inf')$$),
'Exponential PDF: lambda ouside of (0, infinity) does not raise error.'
);
-- exponential_quantile
SELECT assert(
exponential_quantile(NULL, 1) IS NULL AND
exponential_quantile(1, NULL) IS NULL,
'Exponential quantile: Wrong handling of NULLs.'
);
SELECT assert(
isnan( exponential_quantile('NaN', 1) ) AND
isnan( exponential_quantile(1, 'NaN') ),
'Exponential quantile: Wrong handling of NaNs.'
);
SELECT assert(
relative_error(exponential_quantile(0.6321206, 1) , 1) < 1e-5 AND
exponential_quantile(0, 1) = 0 AND
exponential_quantile(1, 1) = 'Inf',
'Exponential quantile: Wrong values for regular values.'
);
SELECT assert(
check_if_raises_error($$SELECT exponential_quantile(1, 0)$$) AND
check_if_raises_error($$SELECT exponential_quantile(1, -1)$$) AND
check_if_raises_error($$SELECT exponential_quantile(0.5, 'Inf')$$),
'Exponential quantile: lambda outside of (0, infinity) does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT exponential_quantile(-1, 1)$$) AND
check_if_raises_error($$SELECT exponential_quantile(2, 1)$$),
'Exponential quantile: succ_prob out of range [0,1] does not raise error.'
);
-- extreme_value_cdf
SELECT assert(
extreme_value_cdf(NULL, 1, 1) IS NULL AND
extreme_value_cdf(1, NULL, 1) IS NULL AND
extreme_value_cdf(1, 1, NULL) IS NULL,
'Extreme Value CDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(extreme_value_cdf('NaN', 1, 1) ) AND
isnan(extreme_value_cdf(1, 'NaN', 1) ) AND
isnan(extreme_value_cdf(1, 1, 'NaN') ),
'Extreme Value CDF: Wrong handling of NaNs.'
);
SELECT assert(
extreme_value_cdf('-Inf', 1, 2) = 0 AND
extreme_value_cdf('Inf', 1, 2) = 1 AND
relative_error(extreme_value_cdf(3, 1, 2), 0.6922006) < 1e-5 AND
relative_error(extreme_value_cdf(2, 1, 2), 0.5452392) < 1e-5 AND
relative_error(extreme_value_cdf(0, 1, 2), 0.1922956) < 1e-5 AND
relative_error(extreme_value_cdf(-1, 1, 2), 0.06598804) < 1e-5,
'Extreme Value CDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT extreme_value_cdf(0.5, 1, 0)$$) AND
check_if_raises_error($$SELECT extreme_value_cdf(0.5, 1, -1)$$) AND
check_if_raises_error($$SELECT extreme_value_cdf(0.5, 'Inf', 1)$$) AND
check_if_raises_error($$SELECT extreme_value_cdf(0.5, '-Inf', 1)$$) AND
check_if_raises_error($$SELECT extreme_value_cdf(0.5, 0, 'Inf')$$),
'Extreme Value CDF: scale outside of (0, infinity) does not raise error.'
);
-- extreme_value_pdf
SELECT assert(
extreme_value_pdf(NULL, 1, 1) IS NULL AND
extreme_value_pdf(1, NULL, 1) IS NULL AND
extreme_value_pdf(1, 1, NULL) IS NULL,
'Extreme Value PDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(extreme_value_pdf('NaN', 1, 1) ) AND
isnan(extreme_value_pdf(1, 'NaN', 1) ) AND
isnan(extreme_value_pdf(1, 1, 'NaN') ),
'Extreme Value PDF: Wrong handling of NaNs.'
);
SELECT assert(
extreme_value_pdf('-Inf', 1, 1) = 0 AND
extreme_value_pdf('Inf', 1, 1) = 0 AND
relative_error(extreme_value_pdf(3, 1, 2), 0.1273232) < 1e-5 AND
relative_error(extreme_value_pdf(2, 1, 2), 0.1653521) < 1e-5 AND
relative_error(extreme_value_pdf(0, 1, 2), 0.158521) < 1e-5 AND
relative_error(extreme_value_pdf(-1, 1, 2), 0.08968704) < 1e-5,
'Extreme Value PDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT extreme_value_pdf(0.5, 1, 0)$$) AND
check_if_raises_error($$SELECT extreme_value_pdf(0.5, 1, -1)$$) AND
check_if_raises_error($$SELECT extreme_value_pdf(0.5, 'Inf', 1)$$) AND
check_if_raises_error($$SELECT extreme_value_pdf(0.5, '-Inf', 1)$$) AND
check_if_raises_error($$SELECT extreme_value_pdf(0.5, 0, 'Inf')$$),
'Extreme Value PDF: scale outside of (0, infinity) does not raise error.'
);
-- extreme_value_quantile
SELECT assert(
extreme_value_quantile(NULL, 1, 1) IS NULL AND
extreme_value_quantile(1, NULL, 1) IS NULL AND
extreme_value_quantile(1, 1, NULL) IS NULL,
'Extreme Value Quantile: Wrong handling of NULLs.'
);
SELECT assert(
isnan(extreme_value_quantile('NaN', 1, 1) ) AND
isnan(extreme_value_quantile(1, 'NaN', 1) ) AND
isnan(extreme_value_quantile(1, 1, 'NaN') ),
'Extreme Value Quantile: Wrong handling of NaNs.'
);
SELECT assert(
extreme_value_quantile(0, 1, 1) = '-Inf' AND
extreme_value_quantile(1, 1, 1) = 'Inf' AND
relative_error(extreme_value_quantile(0.6922006, 1, 2), 3) < 1e-5 AND
relative_error(extreme_value_quantile(0.5452392, 1, 2), 2) < 1e-5 AND
abs(extreme_value_quantile(0.1922956, 1, 2)) < 1e-5 AND
relative_error(extreme_value_quantile(0.06598804, 1, 2), -1) < 1e-5,
'Extreme Value Quantile: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT extreme_value_quantile(0.5, 1, 0)$$) AND
check_if_raises_error($$SELECT extreme_value_quantile(0.5, 1, -1)$$) AND
check_if_raises_error($$SELECT extreme_value_quantile(0.5, 'Inf', 1)$$) AND
check_if_raises_error($$SELECT extreme_value_quantile(0.5, '-Inf', 1)$$) AND
check_if_raises_error($$SELECT extreme_value_quantile(0.5, 0, 'Inf')$$),
'Extreme Value Quantile: scale outside of (0, infinity) does not raise error.'
);
-- fisher_f_cdf
SELECT assert(
fisher_f_cdf(NULL, 1, 1) IS NULL AND
fisher_f_cdf(1, NULL, 1) IS NULL AND
fisher_f_cdf(1, 1, NULL) IS NULL,
'Fisher F CDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(fisher_f_cdf('NaN', 1, 1) ) AND
isnan(fisher_f_cdf(1, 'NaN', 1) ) AND
isnan(fisher_f_cdf(1, 1, 'NaN') ),
'Fisher F CDF: Wrong handling of NaNs.'
);
SELECT assert(
fisher_f_cdf(-1, 1, 1) = 0 AND
fisher_f_cdf(0, 1, 1) = 0 AND
fisher_f_cdf('Inf', 1, 1) = 1 AND
relative_error(fisher_f_cdf(1, 1, 1), 0.5) < 1e-5 AND
fisher_f_cdf(-1, 1, 2) = 0 AND
fisher_f_cdf(0, 1, 2) = 0 AND
fisher_f_cdf('Inf', 1, 2) = 1 AND
relative_error(fisher_f_cdf(1, 1, 2), 0.5773503) < 1e-5,
'Fisher F CDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT fisher_f_cdf(1.5, 0, 1)$$) AND
check_if_raises_error($$SELECT fisher_f_cdf(1.5, 1, 0)$$) AND
check_if_raises_error($$SELECT fisher_f_cdf(1.5, -1, 1)$$) AND
check_if_raises_error($$SELECT fisher_f_cdf(1.5, 1, -1)$$),
'Fisher F CDF: parameters less or equal to 0 does not raise error.'
);
-- fisher_f_pdf
SELECT assert(
fisher_f_pdf(NULL, 1, 1) IS NULL AND
fisher_f_pdf(1, NULL, 1) IS NULL AND
fisher_f_pdf(1, 1, NULL) IS NULL,
'Fisher F PDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(fisher_f_pdf('NaN', 1, 1) ) AND
isnan(fisher_f_pdf(1, 'NaN', 1) ) AND
isnan(fisher_f_pdf(1, 1, 'NaN') ),
'Fisher F PDF: Wrong handling of NaNs.'
);
SELECT assert(
fisher_f_pdf(-1, 1, 1) = 0 AND
fisher_f_pdf(0, 1, 1) = 'Inf' AND
fisher_f_pdf('Inf', 1, 1) = 0 AND
relative_error(fisher_f_pdf(1, 1, 1), 0.1591549) < 1e-5 AND
fisher_f_pdf(-1, 2, 1) = 0 AND
fisher_f_pdf(0, 2, 1) = 1 AND
fisher_f_pdf('Inf', 2, 1) = 0 AND
relative_error(fisher_f_pdf(1, 2, 1), 0.1924501) < 1e-5 AND
fisher_f_pdf(-1, 3, 1) = 0 AND
fisher_f_pdf(0, 3, 1) = 0 AND
fisher_f_pdf('Inf', 3, 1) = 0 AND
relative_error(fisher_f_pdf(1, 3, 1), 0.2067483) < 1e-5,
'Fisher F PDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT fisher_f_pdf(1.5, 0, 1)$$) AND
check_if_raises_error($$SELECT fisher_f_pdf(1.5, 1, 0)$$) AND
check_if_raises_error($$SELECT fisher_f_pdf(1.5, -1, 1)$$) AND
check_if_raises_error($$SELECT fisher_f_pdf(1.5, 1, -1)$$),
'Fisher F PDF: parameters less or equal to 0 does not raise error.'
);
-- fisher_f_quantile
SELECT assert(
fisher_f_quantile(NULL, 1, 1) IS NULL AND
fisher_f_quantile(1, NULL, 1) IS NULL AND
fisher_f_quantile(1, 1, NULL) IS NULL,
'Fisher F Quantile: Wrong handling of NULLs.'
);
SELECT assert(
isnan(fisher_f_quantile('NaN', 1, 1) ) AND
isnan(fisher_f_quantile(1, 'NaN', 1) ) AND
isnan(fisher_f_quantile(1, 1, 'NaN') ) AND
isnan(fisher_f_quantile(.5, 1, 'NaN') ),
'Fisher F Quantile: Wrong handling of NaNs.'
);
SELECT assert(
fisher_f_quantile(0, 1, 1) = 0 AND
fisher_f_quantile(1, 1, 1) = 'Inf' AND
relative_error(fisher_f_quantile(0.8, 1, 1), 9.472136) < 1e-5 AND
fisher_f_quantile(0, 2, 1) = 0 AND
fisher_f_quantile(1, 2, 1) = 'Inf' AND
relative_error(fisher_f_quantile(0.8, 2, 1), 12) < 1e-5 AND
fisher_f_quantile(0, 3, 1) = 0 AND
fisher_f_quantile(1, 3, 1) = 'inf' AND
relative_error(fisher_f_quantile(0.8, 3, 1), 13.06393) < 1e-5,
'Fisher F Quantile: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT fisher_f_quantile(1.5, 0, 1)$$) AND
check_if_raises_error($$SELECT fisher_f_quantile(1.5, 1, 0)$$) AND
check_if_raises_error($$SELECT fisher_f_quantile(1.5, -1, 1)$$) AND
check_if_raises_error($$SELECT fisher_f_quantile(1.5, 1, -1)$$),
'Fisher F Quantile: parameters less or equal to 0 does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT fisher_f_quantile(-1, 1, 1)$$) AND
check_if_raises_error($$SELECT fisher_f_quantile(2, 1, 1)$$) ,
'Fisher F Quantile: CDF out of range [0,1] does not raise error.'
);
-- gamma_cdf
SELECT assert(
gamma_cdf(NULL, 1, 1) IS NULL AND
gamma_cdf(1, NULL, 1) IS NULL AND
gamma_cdf(1, 1, NULL) IS NULL,
'Gamma CDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(gamma_cdf('NaN', 1, 1) ) AND
isnan(gamma_cdf(1, 'NaN', 1) ) AND
isnan(gamma_cdf(1, 1, 'NaN') ),
'Gamma CDF: Wrong handling of NaNs.'
);
SELECT assert(
relative_error(gamma_cdf(0.5, 0.5, 2), 0.5204999) < 1e-5 AND
gamma_cdf(0, 0.5, 2) = 0 AND
gamma_cdf(-1, 0.5, 2) = 0 AND
relative_error(gamma_cdf(0.5, 1, 2), 0.2211992) < 1e-5 AND
gamma_cdf(0, 1, 2) = 0 AND
gamma_cdf(-1, 1, 2) = 0,
'Gamma CDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT gamma_cdf(0.5, 0, 1)$$) AND
check_if_raises_error($$SELECT gamma_cdf(0.5, 1, 0)$$) AND
check_if_raises_error($$SELECT gamma_cdf(0.5, -1, 1)$$) AND
check_if_raises_error($$SELECT gamma_cdf(0.5, 1, -1)$$) ,
'Gamma CDF: scale or shape less than or equal to 0 does not raise error.'
);
-- gamma_pdf
SELECT assert(
gamma_pdf(NULL, 1, 1) IS NULL AND
gamma_pdf(1, NULL, 1) IS NULL AND
gamma_pdf(1, 1, NULL) IS NULL,
'Gamma PDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(gamma_pdf('NaN', 1, 1) ) AND
isnan(gamma_pdf(1, 'NaN', 1) ) AND
isnan(gamma_pdf(1, 1, 'NaN') ),
'Gamma PDF: Wrong handling of NaNs.'
);
SELECT assert(
relative_error(gamma_pdf(0.5, 0.5, 2), 0.4393913) < 1e-5 AND
gamma_pdf(0, 0.5, 2) = 'Inf' AND
gamma_pdf(-1, 0.5, 2) = 0 AND
relative_error(gamma_pdf(0.5, 1, 2), 0.3894004) < 1e-5 AND
gamma_pdf(0, 1, 2) = 0.5 AND
gamma_pdf(-1, 1, 2) = 0 ,
'Gamma PDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT gamma_pdf(0.5, 0, 1)$$) AND
check_if_raises_error($$SELECT gamma_pdf(0.5, 1, 0)$$) AND
check_if_raises_error($$SELECT gamma_pdf(0.5, -1, 1)$$) AND
check_if_raises_error($$SELECT gamma_pdf(0.5, 1, -1)$$) ,
'Gamma PDF: scale or shape less than or equal to 0 does not raise error.'
);
-- gamma_quantile
SELECT assert(
gamma_quantile(NULL, 1, 1) IS NULL AND
gamma_quantile(1, NULL, 1) IS NULL AND
gamma_quantile(1, 1, NULL) IS NULL,
'Gamma Quantile: Wrong handling of NULLs.'
);
SELECT assert(
isnan(gamma_quantile('NaN', 1, 1) ) AND
isnan(gamma_quantile(1, 'NaN', 1) ) AND
isnan(gamma_quantile(1, 1, 'NaN') ),
'Gamma Quantile: Wrong handling of NaNs.'
);
SELECT assert(
relative_error(gamma_quantile(0.5, 1, 2), 1.386294) < 1e-5 AND
gamma_quantile(0, 1, 2) = 0 AND
gamma_quantile(1, 1, 2) = 'Inf' ,
'Gamma Quantile: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT gamma_quantile(0.5, 0, 1)$$) AND
check_if_raises_error($$SELECT gamma_quantile(0.5, 1, 0)$$) AND
check_if_raises_error($$SELECT gamma_quantile(0.5, -1, 1)$$) AND
check_if_raises_error($$SELECT gamma_quantile(0.5, 1, -1)$$) ,
'Gamma Quantile: scale or shape less than or equal to 0 does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT gamma_quantile(-1, 1, 1)$$) AND
check_if_raises_error($$SELECT gamma_quantile(2, 1, 1)$$) ,
'Gamma Quantile: CDF out of range [0,1] does not raise error.'
);
-- geometric_cdf
SELECT assert(
geometric_cdf(NULL, 1) IS NULL AND
geometric_cdf(1, NULL) IS NULL,
'Geometric CDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(geometric_cdf('NaN', 1) ) AND
isnan(geometric_cdf(1, 'NaN') ) ,
'Geometric CDF: Wrong handling of NaNs.'
);
SELECT assert(
geometric_cdf(0, 0.3) = 0.3 AND
geometric_cdf(0.7, 0.3) = 0.3 AND
relative_error(geometric_cdf(1, 0.3), 0.51) < 1e-5 AND
relative_error(geometric_cdf(2, 0.3), 0.657) < 1e-5 AND
geometric_cdf('Inf', 0.3) = 1 AND
geometric_cdf('-Inf', 0.3) = 0 AND
geometric_cdf(-0.1, 0.3) = 0,
'Geometric CDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT geometric_cdf(5, -1)$$) AND
check_if_raises_error($$SELECT geometric_cdf(5, 2)$$) ,
'Geometric CDF: succ_prob out of range [0,1] does not raise error.'
);
-- geometric_pmf
SELECT assert(
geometric_pmf(NULL, 1) IS NULL AND
geometric_pmf(1, NULL) IS NULL,
'Geometric PMF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(geometric_pmf(1, 'NaN') ) ,
'Geometric PMF: Wrong handling of NaNs.'
);
SELECT assert(
geometric_pmf(0, 0.3) = 0.3 AND
relative_error(geometric_pmf(1, 0.3), 0.21) < 1e-5 AND
relative_error(geometric_pmf(2, 0.3), 0.147) < 1e-5 AND
geometric_pmf(-1, 0.3) = 0 ,
'Geometric PMF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT geometric_pmf(5, -1)$$) AND
check_if_raises_error($$SELECT geometric_pmf(5, 2)$$) ,
'Geometric PMF: succ_prob out of range [0,1] does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT geometric_pmf(0.5, 0.3)$$),
'Geometric PMF: random variable not in {.., -1, 0, 1, 2, ...} does not raise error.'
);
-- geometric_quantile
SELECT assert(
geometric_quantile(NULL, 1) IS NULL AND
geometric_quantile(1, NULL) IS NULL,
'Geometric Quantile: Wrong handling of NULLs.'
);
SELECT assert(
isnan(geometric_quantile('NaN', 1) ) AND
isnan(geometric_quantile(1, 'NaN') ) ,
'Geometric Quantile: Wrong handling of NaNs.'
);
SELECT assert(
geometric_quantile(0.3, 0.3) = 0 AND
relative_error(geometric_quantile(0.51, 0.3), 1) < 1e-5 AND
relative_error(geometric_quantile(0.657, 0.3), 2) < 1e-5 AND
geometric_quantile(0, 0.3) = 0 AND
geometric_quantile(1, 0.3) = 'Inf',
'Geometric Quantile: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT geometric_quantile(0.5, -1)$$) AND
check_if_raises_error($$SELECT geometric_quantile(0.5, 2)$$) ,
'Geometric Quantile: succ_prob out of range [0,1] does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT geometric_quantile(-1, 1)$$) AND
check_if_raises_error($$SELECT geometric_quantile(2, 1)$$) ,
'Geometric Quantile: CDF out of range [0,1] does not raise error.'
);
-- hypergeometric cdf
SELECT assert(
hypergeometric_cdf(NULL, 50, 30, 500) IS NULL AND
hypergeometric_cdf(1, NULL, 30, 500) IS NULL AND
hypergeometric_cdf(1, 50, NULL, 500) IS NULL AND
hypergeometric_cdf(1, 50, 30, NULL) IS NULL,
'Hypergeomitric CDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(hypergeometric_cdf('NaN', 50, 30, 500)) ,
'Hypergeomitric CDF: Wrong handling of NaNs.'
);
SELECT assert(
hypergeometric_cdf(-1 ,50, 30, 500) = 0 AND
relative_error(hypergeometric_cdf(0 ,50, 30, 500), 0.03832346) < 1e-5 AND
hypergeometric_cdf(0.7 ,50, 30, 500) = hypergeometric_cdf(0 ,50, 30, 500) AND
relative_error(hypergeometric_cdf(10 ,50, 30, 500), 0.9999567) < 1e-5 AND
hypergeometric_cdf(30 ,50, 30, 500) = 1 AND
hypergeometric_cdf('-Inf' ,50, 30, 500) = 0 AND
hypergeometric_cdf('Inf' ,50, 30, 500) = 1,
'Hypergeomitric CDF: Wrong handling of regular values.'
);
SELECT assert(
check_if_raises_error($$select hypergeometric_cdf(0, 30, 50, -1)$$) AND
check_if_raises_error($$select hypergeometric_cdf(0, 30, 50, 0)$$),
'Hypergeometric CDF: total less than or equal to 0 does not raise error.'
);
SELECT assert(
check_if_raises_error($$select hypergeometric_cdf(0, -1, 50, 500)$$) AND
NOT check_if_raises_error($$select hypergeometric_cdf(0, 0, 50, 500)$$) AND
NOT check_if_raises_error($$select hypergeometric_cdf(0, 500, 50, 500)$$) AND
check_if_raises_error($$select hypergeometric_cdf(0, 501, 50, 500)$$),
'Hypergeometric CDF: defective out of range [0,total] does not raise error.'
);
SELECT assert(
check_if_raises_error($$select hypergeometric_cdf(0, 30, -1, 500)$$) AND
NOT check_if_raises_error($$select hypergeometric_cdf(0, 30, 0, 500)$$) AND
NOT check_if_raises_error($$select hypergeometric_cdf(0, 30, 500, 500)$$) AND
check_if_raises_error($$select hypergeometric_cdf(0, 30, 501, 500)$$),
'Hypergeometric CDF: sample_count out of range [0,total] does not raise error.'
);
-- hypergeometric PMF
SELECT assert(
hypergeometric_pmf(NULL, 50, 30, 500) IS NULL AND
hypergeometric_pmf(1, NULL, 30, 500) IS NULL AND
hypergeometric_pmf(1, 50, NULL, 500) IS NULL AND
hypergeometric_pmf(1, 50, 30, NULL) IS NULL,
'Hypergeomitric PDF: Wrong handling of NULLs.'
);
SELECT assert(
hypergeometric_pmf(-1 ,50, 30, 500) = 0 AND
relative_error(hypergeometric_pmf(0 ,50, 30, 500), 0.03832346) < 1e-5 AND
relative_error(hypergeometric_pmf(10,50, 30, 500), 0.0002206837) < 1e-5 AND
hypergeometric_pmf(31,50, 30, 500) = 0,
'Hypergeomitric PDF: Wrong handling of regular values.'
);
SELECT assert(
check_if_raises_error($$select hypergeometric_pmf(0, 30, 50, -1)$$) AND
check_if_raises_error($$select hypergeometric_pmf(0, 30, 50, 0)$$),
'Hypergeometric PMF: total less than or equal to 0 does not raise error.'
);
SELECT assert(
check_if_raises_error($$select hypergeometric_pmf(0, -1, 50, 500)$$) AND
NOT check_if_raises_error($$select hypergeometric_pmf(0, 0, 50, 500)$$) AND
NOT check_if_raises_error($$select hypergeometric_pmf(0, 500, 50, 500)$$) AND
check_if_raises_error($$select hypergeometric_pmf(0, 501, 50, 500)$$),
'Hypergeometric PMF: defective out of range [0,total] does not raise error.'
);
SELECT assert(
check_if_raises_error($$select hypergeometric_pmf(0, 30, -1, 500)$$) AND
NOT check_if_raises_error($$select hypergeometric_pmf(0, 30, 0, 500)$$) AND
NOT check_if_raises_error($$select hypergeometric_pmf(0, 30, 500, 500)$$) AND
check_if_raises_error($$select hypergeometric_pmf(0, 30, 501, 500)$$),
'Hypergeometric PMF: sample_count out of range [0,total] does not raise error.'
);
-- hypergeometric quantile
SELECT assert(
hypergeometric_quantile(NULL, 50, 30, 500) IS NULL AND
hypergeometric_quantile(1, NULL, 30, 500) IS NULL AND
hypergeometric_quantile(1, 50, NULL, 500) IS NULL AND
hypergeometric_quantile(1, 50, 30, NULL) IS NULL,
'Hypergeomitric Quantile: Wrong handling of NULLs.'
);
SELECT assert(
isnan(hypergeometric_quantile('NaN', 50, 30, 500)),
'Hypergeomitric Quantile: Wrong handling of NaNs.'
);
SELECT assert(
hypergeometric_quantile(0, 50, 30, 500) = 0 AND
abs(hypergeometric_quantile(0.03832346, 50, 30, 500)) < 1e-5 AND
relative_error(hypergeometric_quantile(0.9999567, 50, 30, 500), 10) < 1e-5 AND
hypergeometric_quantile(1 ,50, 30, 500) = 30 ,
'Hypergeomitric Quantile: Wrong handling of regular values.'
);
SELECT assert(
check_if_raises_error($$select hypergeometric_quantile(0, 30, 50, -1)$$) AND
check_if_raises_error($$select hypergeometric_quantile(0, 30, 50, 0)$$),
'Hypergeometric Quantile: total less than or equal to 0 does not raise error.'
);
SELECT assert(
check_if_raises_error($$select hypergeometric_quantile(0, -1, 50, 500)$$) AND
NOT check_if_raises_error($$select hypergeometric_quantile(0, 0, 50, 500)$$) AND
NOT check_if_raises_error($$select hypergeometric_quantile(0, 500, 50, 500)$$) AND
check_if_raises_error($$select hypergeometric_quantile(0, 501, 50, 500)$$),
'Hypergeometric Quantile: defective out of range [0,total] does not raise error.'
);
SELECT assert(
check_if_raises_error($$select hypergeometric_quantile(0, 30, -1, 500)$$) AND
NOT check_if_raises_error($$select hypergeometric_quantile(0, 30, 0, 500)$$) AND
NOT check_if_raises_error($$select hypergeometric_quantile(0, 30, 500, 500)$$) AND
check_if_raises_error($$select hypergeometric_quantile(0, 30, 501, 500)$$),
'Hypergeometric Quantile: sample_count out of range [0,total] does not raise error.'
);
SELECT assert(
check_if_raises_error($$select hypergeometric_quantile(-1, 30, 50, 500)$$) AND
check_if_raises_error($$select hypergeometric_quantile(1.1, 30, 50, 500)$$),
'Hypergeometric Quantile: CDF out of range [0,1] does not raise error.'
);
-- inverse_gamma_cdf
SELECT assert(
inverse_gamma_cdf(NULL, 1, 1) IS NULL AND
inverse_gamma_cdf(1, NULL, 1) IS NULL AND
inverse_gamma_cdf(1, 1, NULL) IS NULL,
'Inverse Gamma CDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(inverse_gamma_cdf('NaN', 1, 1) ) AND
isnan(inverse_gamma_cdf(1, 'NaN', 1) ) AND
isnan(inverse_gamma_cdf(1, 1, 'NaN') ),
'Inverse Gamma CDF: Wrong handling of NaNs.'
);
SELECT assert(
relative_error(inverse_gamma_cdf(0.5, 1, 2), 0.01831564) < 1e-5 AND
inverse_gamma_cdf('Inf', 1, 2) = 1 AND
inverse_gamma_cdf('-Inf', 1, 2) = 0 AND
inverse_gamma_cdf(-1, 1, 2) = 0,
'Inverse Gamma CDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT inverse_gamma_cdf(0.5, 0, 1)$$) AND
check_if_raises_error($$SELECT inverse_gamma_cdf(0.5, 1, 0)$$) AND
check_if_raises_error($$SELECT inverse_gamma_cdf(0.5, -1, 1)$$) AND
check_if_raises_error($$SELECT inverse_gamma_cdf(0.5, 1, -1)$$) ,
'Inverse Gamma CDF: scale or shape less than or equal to 0 does not raise error.'
);
-- inverse_gamma_pdf
SELECT assert(
inverse_gamma_pdf(NULL, 1, 1) IS NULL AND
inverse_gamma_pdf(1, NULL, 1) IS NULL AND
inverse_gamma_pdf(1, 1, NULL) IS NULL,
'Inverse Gamma PDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(inverse_gamma_pdf('NaN', 1, 1) ) AND
isnan(inverse_gamma_pdf(1, 'NaN', 1) ) AND
isnan(inverse_gamma_pdf(1, 1, 'NaN') ),
'Inverse Gamma PDF: Wrong handling of NaNs.'
);
SELECT assert(
relative_error(inverse_gamma_pdf(0.5, 1, 2), 0.1465251) < 1e-5 AND
inverse_gamma_pdf('Inf', 1, 2) = 0 AND
inverse_gamma_pdf('-Inf', 1, 2) = 0 AND
inverse_gamma_pdf(-1, 1, 2) = 0,
'Inverse Gamma PDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT inverse_gamma_pdf(0.5, 0, 1)$$) AND
check_if_raises_error($$SELECT inverse_gamma_pdf(0.5, 1, 0)$$) AND
check_if_raises_error($$SELECT inverse_gamma_pdf(0.5, -1, 1)$$) AND
check_if_raises_error($$SELECT inverse_gamma_pdf(0.5, 1, -1)$$) ,
'Inverse Gamma PDF: scale or shape less than or equal to 0 does not raise error.'
);
-- inverse_gamma_quantile
SELECT assert(
inverse_gamma_quantile(NULL, 1, 1) IS NULL AND
inverse_gamma_quantile(1, NULL, 1) IS NULL AND
inverse_gamma_quantile(1, 1, NULL) IS NULL,
'Inverse Gamma Quantile: Wrong handling of NULLs.'
);
SELECT assert(
isnan(inverse_gamma_quantile('NaN', 1, 1) ) AND
isnan(inverse_gamma_quantile(1, 'NaN', 1) ) AND
isnan(inverse_gamma_quantile(1, 1, 'NaN') ),
'Inverse Gamma Quantile: Wrong handling of NaNs.'
);
SELECT assert(
inverse_gamma_quantile(0, 1, 2) = 0 AND
relative_error(inverse_gamma_quantile(0.01831564, 1, 2), 0.5) < 1e-5 AND
inverse_gamma_quantile(1, 1, 2) = 'Inf',
'Inverse Gamma Quantile: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT inverse_gamma_quantile(0.5, 0, 1)$$) AND
check_if_raises_error($$SELECT inverse_gamma_quantile(0.5, 1, 0)$$) AND
check_if_raises_error($$SELECT inverse_gamma_quantile(0.5, -1, 1)$$) AND
check_if_raises_error($$SELECT inverse_gamma_quantile(0.5, 1, -1)$$) ,
'Inverse Gamma Quantile: scale or shape less than or equal to 0 does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT inverse_gamma_quantile(-1, 1, 1)$$) AND
check_if_raises_error($$SELECT inverse_gamma_quantile(2, 1, 1)$$) ,
'Inverse Gamma Quantile: CDF out of range [0,1] does not raise error.'
);
-- laplace_cdf
SELECT assert(
laplace_cdf(NULL, 1, 1) IS NULL AND
laplace_cdf(1, NULL, 1) IS NULL AND
laplace_cdf(1, 1, NULL) IS NULL,
'Laplace CDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(laplace_cdf('NaN', 1, 1) ) AND
isnan(laplace_cdf(1, 'NaN', 1) ) AND
isnan(laplace_cdf(1, 1, 'NaN') ),
'Laplace CDF: Wrong handling of NaNs.'
);
SELECT assert(
laplace_cdf('-Inf', 1, 1) = 0 AND
laplace_cdf('Inf', 1, 1) = 1 AND
relative_error(laplace_cdf(2, 1, 1), 0.8160603) < 1e-5 AND
relative_error(laplace_cdf(-2, 1, 1), 0.02489353) < 1e-5,
'Laplace CDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT laplace_cdf(0.5, 1, 0)$$) AND
check_if_raises_error($$SELECT laplace_cdf(0.5, 1, -1)$$),
'Laplace CDF: scale less than or equal to 0 does not raise error.'
);
-- laplace_pdf
SELECT assert(
laplace_pdf(NULL, 1, 1) IS NULL AND
laplace_pdf(1, NULL, 1) IS NULL AND
laplace_pdf(1, 1, NULL) IS NULL,
'Laplace PDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(laplace_pdf('NaN', 1, 1) ) AND
isnan(laplace_pdf(1, 'NaN', 1) ) AND
isnan(laplace_pdf(1, 1, 'NaN') ),
'Laplace PDF: Wrong handling of NaNs.'
);
SELECT assert(
laplace_pdf('-Inf', 1, 1) = 0 AND
laplace_pdf('Inf', 1, 1) = 0 AND
relative_error(laplace_pdf(2, 1, 1), 0.1839397) < 1e-5 AND
relative_error(laplace_pdf(-2, 1, 1), 0.02489353) < 1e-5,
'Laplace PDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT laplace_pdf(0.5, 1, 0)$$) AND
check_if_raises_error($$SELECT laplace_pdf(0.5, 1, -1)$$),
'Laplace PDF: scale less than or equal to 0 does not raise error.'
);
-- laplace_quantile
SELECT assert(
laplace_quantile(NULL, 1, 1) IS NULL AND
laplace_quantile(1, NULL, 1) IS NULL AND
laplace_quantile(1, 1, NULL) IS NULL,
'Laplace Quantile: Wrong handling of NULLs.'
);
SELECT assert(
isnan(laplace_quantile('NaN', 1, 1) ) AND
isnan(laplace_quantile(1, 'NaN', 1) ) AND
isnan(laplace_quantile(1, 1, 'NaN') ),
'Laplace Quantile: Wrong handling of NaNs.'
);
SELECT assert(
laplace_quantile(0, 1, 1) = '-Inf' AND
laplace_quantile(1, 1, 1) = 'Inf' AND
relative_error(laplace_quantile(0.8160603, 1, 1), 2) < 1e-5 AND
relative_error(laplace_quantile(0.02489353, 1, 1), -2) < 1e-5,
'Laplace Quantile: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT laplace_quantile(0.5, 1, 0)$$) AND
check_if_raises_error($$SELECT laplace_quantile(0.5, 1, -1)$$),
'Laplace Quantile: scale less than or equal to 0 does not raise error.'
);
-- logistic_cdf
SELECT assert(
logistic_cdf(NULL, 1, 1) IS NULL AND
logistic_cdf(1, NULL, 1) IS NULL AND
logistic_cdf(1, 1, NULL) IS NULL,
'Logistic CDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(logistic_cdf('NaN', 1, 1) ) AND
isnan(logistic_cdf(1, 'NaN', 1) ) AND
isnan(logistic_cdf(1, 1, 'NaN') ),
'Logistic CDF: Wrong handling of NaNs.'
);
SELECT assert(
logistic_cdf('-Inf', 1, 2) = 0 AND
logistic_cdf('Inf', 1, 2) = 1 AND
relative_error(logistic_cdf(3, 1, 2), 0.7310586) < 1e-5 AND
relative_error(logistic_cdf(2, 1, 2), 0.6224593) < 1e-5 AND
relative_error(logistic_cdf(0, 1, 2), 0.3775407) < 1e-5 AND
relative_error(logistic_cdf(-1, 1, 2), 0.2689414) < 1e-5,
'Logistic CDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT logistic_cdf(0.5, 1, 0)$$) AND
check_if_raises_error($$SELECT logistic_cdf(0.5, 1, -1)$$),
'Logistic CDF: scale less than or equal to 0 does not raise error.'
);
-- logistic_pdf
SELECT assert(
logistic_pdf(NULL, 1, 1) IS NULL AND
logistic_pdf(1, NULL, 1) IS NULL AND
logistic_pdf(1, 1, NULL) IS NULL,
'Logistic PDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(logistic_pdf('NaN', 1, 1) ) AND
isnan(logistic_pdf(1, 'NaN', 1) ) AND
isnan(logistic_pdf(1, 1, 'NaN') ),
'Logistic PDF: Wrong handling of NaNs.'
);
SELECT assert(
logistic_pdf('-Inf', 1, 1) = 0 AND
logistic_pdf('Inf', 1, 1) = 0 AND
relative_error(logistic_pdf(3, 1, 2), 0.09830597) < 1e-5 AND
relative_error(logistic_pdf(2, 1, 2), 0.1175019) < 1e-5 AND
relative_error(logistic_pdf(0, 1, 2), 0.1175019) < 1e-5 AND
relative_error(logistic_pdf(-1, 1, 2), 0.09830597) < 1e-5,
'Logistic PDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT logistic_pdf(0.5, 1, 0)$$) AND
check_if_raises_error($$SELECT logistic_pdf(0.5, 1, -1)$$),
'Logistic PDF: scale less than or equal to 0 does not raise error.'
);
-- logistic_quantile
SELECT assert(
logistic_quantile(NULL, 1, 1) IS NULL AND
logistic_quantile(1, NULL, 1) IS NULL AND
logistic_quantile(1, 1, NULL) IS NULL,
'Logistic Quantile: Wrong handling of NULLs.'
);
SELECT assert(
isnan(logistic_quantile('NaN', 1, 1) ) AND
isnan(logistic_quantile(1, 'NaN', 1) ) AND
isnan(logistic_quantile(1, 1, 'NaN') ),
'Logistic Quantile: Wrong handling of NaNs.'
);
SELECT assert(
logistic_quantile(0, 1, 1) = '-Inf' AND
logistic_quantile(1, 1, 1) = 'Inf' AND
relative_error(logistic_quantile(0.7310586, 1, 2), 3) < 1e-5 AND
relative_error(logistic_quantile(0.6224593, 1, 2), 2) < 1e-5 AND
abs(logistic_quantile(0.3775407, 1, 2)) < 1e-5 AND
relative_error(logistic_quantile(0.2689414, 1, 2), -1) < 1e-5,
'Logistic Quantile: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT logistic_quantile(0.5, 1, 0)$$) AND
check_if_raises_error($$SELECT logistic_quantile(0.5, 1, -1)$$),
'Logistic Quantile: scale less than or equal to 0 does not raise error.'
);
-- lognormal_cdf
SELECT assert(
lognormal_cdf(NULL, 1, 1) IS NULL AND
lognormal_cdf(1, NULL, 1) IS NULL AND
lognormal_cdf(1, 1, NULL) IS NULL,
'Log-normal CDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(lognormal_cdf('NaN', 1, 1) ) AND
isnan(lognormal_cdf(1, 'NaN', 1) ) AND
isnan(lognormal_cdf(1, 1, 'NaN') ),
'Log-normal CDF: Wrong handling of NaNs.'
);
SELECT assert(
lognormal_cdf('-Inf', 1, 2) = 0 AND
lognormal_cdf('Inf', 1, 2) = 1 AND
relative_error(lognormal_cdf(3, 1, 2), 0.5196623) < 1e-5 AND
relative_error(lognormal_cdf(2, 1, 2), 0.439031) < 1e-5 AND
lognormal_cdf(0, 1, 2) = 0 AND
lognormal_cdf(-1, 1, 2) = 0,
'Log-normal CDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT lognormal_cdf(0.5, 'Inf', 1)$$) AND
check_if_raises_error($$SELECT lognormal_cdf(0.5, '-Inf', 1)$$),
'Log-normal CDF: non-finite location does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT lognormal_cdf(0.5, 1, 0)$$) AND
check_if_raises_error($$SELECT lognormal_cdf(0.5, 1, -1)$$),
'Log-normal CDF: scale less than or equal to 0 does not raise error.'
);
-- lognormal_pdf
SELECT assert(
lognormal_pdf(NULL, 1, 1) IS NULL AND
lognormal_pdf(1, NULL, 1) IS NULL AND
lognormal_pdf(1, 1, NULL) IS NULL,
'Log-normal PDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(lognormal_pdf('NaN', 1, 1) ) AND
isnan(lognormal_pdf(1, 'NaN', 1) ) AND
isnan(lognormal_pdf(1, 1, 'NaN') ),
'Log-normal PDF: Wrong handling of NaNs.'
);
SELECT assert(
lognormal_pdf('-Inf', 1, 1) = 0 AND
lognormal_pdf('Inf', 1, 1) = 0 AND
relative_error(lognormal_pdf(3, 1, 2), 0.06640961) < 1e-5 AND
relative_error(lognormal_pdf(2, 1, 2), 0.09856858) < 1e-5 AND
lognormal_pdf(0, 1, 2) = 0 AND
lognormal_pdf(-1, 1, 2) = 0,
'Log-normal PDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT lognormal_pdf(0.5, 'Inf', 1)$$) AND
check_if_raises_error($$SELECT lognormal_pdf(0.5, '-Inf', 1)$$),
'Log-normal PDF: non-finite location does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT lognormal_pdf(0.5, 1, 0)$$) AND
check_if_raises_error($$SELECT lognormal_pdf(0.5, 1, -1)$$),
'Log-normal PDF: scale less than or equal to 0 does not raise error.'
);
-- lognormal_quantile
SELECT assert(
lognormal_quantile(NULL, 1, 1) IS NULL AND
lognormal_quantile(1, NULL, 1) IS NULL AND
lognormal_quantile(1, 1, NULL) IS NULL,
'Log-normal Quantile: Wrong handling of NULLs.'
);
SELECT assert(
isnan(lognormal_quantile('NaN', 1, 1) ) AND
isnan(lognormal_quantile(1, 'NaN', 1) ) AND
isnan(lognormal_quantile(1, 1, 'NaN') ),
'Log-normal Quantile: Wrong handling of NaNs.'
);
SELECT assert(
lognormal_quantile(0, 1, 1) = 0 AND
lognormal_quantile(1, 1, 1) = 'Inf' AND
relative_error(lognormal_quantile(0.5196623, 1, 2), 3) < 1e-5 AND
relative_error(lognormal_quantile(0.439031, 1, 2), 2) < 1e-5,
'Log-normal Quantile: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT lognormal_quantile(0.5, 'Inf', 1)$$) AND
check_if_raises_error($$SELECT lognormal_quantile(0.5, '-Inf', 1)$$),
'Log-normal Quantile: non-finite location does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT lognormal_quantile(0.5, 1, 0)$$) AND
check_if_raises_error($$SELECT lognormal_quantile(0.5, 1, -1)$$),
'Log-normal Quantile: scale less than or equal to 0 does not raise error.'
);
-- negative_binomial_cdf
SELECT assert(
negative_binomial_cdf(NULL, 1, 1) IS NULL AND
negative_binomial_cdf(1, NULL, 1) IS NULL AND
negative_binomial_cdf(1, 1, NULL) IS NULL,
'Negative binomial CDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(negative_binomial_cdf(1, 1, 'NaN') ),
'Negative binomial CDF: Wrong handling of NaNs.'
);
SELECT assert(
negative_binomial_cdf(-1,11, 0.4) = 0 AND
relative_error(negative_binomial_cdf(3, 11, 0.4), 0.003906407) < 1e-5 AND
negative_binomial_cdf(3, 11, 0.4) = negative_binomial_cdf(3.2, 11, 0.4) AND
relative_error(negative_binomial_cdf(11, 11, 0.4), 0.22805) < 1e-5 AND
relative_error(negative_binomial_cdf(12, 11, 0.4), 0.2870893) < 1e-5 AND
negative_binomial_cdf('-Inf',11, 0.4) = 0 AND
negative_binomial_cdf('Inf', 11, 0.4) = 1,
'Negative binomial CDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT negative_binomial_cdf(0, 0, 1)$$) AND
check_if_raises_error($$SELECT negative_binomial_cdf(0, -1, 1)$$) ,
'Negative binomial CDF: non positive trials does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT negative_binomial_cdf(0, 1, 0)$$) AND
check_if_raises_error($$SELECT negative_binomial_cdf(0, 1, 2)$$) AND
check_if_raises_error($$SELECT negative_binomial_cdf(0, 1, -1)$$),
'Negative binomial CDF: succ_prob out of range (0,1] does not raise error.'
);
-- negative_binomial_pmf
SELECT assert(
negative_binomial_pmf(NULL, 1, 1) IS NULL AND
negative_binomial_pmf(1, NULL, 1) IS NULL AND
negative_binomial_pmf(1, 1, NULL) IS NULL,
'Negative binomial PMF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(negative_binomial_pmf(1, 1, 'NaN') ),
'Negative binomial PMF: Wrong handling of NaNs.'
);
SELECT assert(
negative_binomial_pmf(-1,11, 0.4) = 0 AND
relative_error(negative_binomial_pmf(3, 11, 0.4), 0.002591073) < 1e-5 AND
relative_error(negative_binomial_pmf(11, 11, 0.4), 0.05367213) < 1e-5 AND
relative_error(negative_binomial_pmf(12, 11, 0.4), 0.05903934) < 1e-5 ,
'Negative binomial PMF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT negative_binomial_pmf(0, 0, 1)$$) AND
check_if_raises_error($$SELECT negative_binomial_pmf(0, -1, 1)$$) ,
'Negative binomial PMF: non positive trials does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT negative_binomial_pmf(0, 1, 0)$$) AND
check_if_raises_error($$SELECT negative_binomial_pmf(0, 1, 2)$$) AND
check_if_raises_error($$SELECT negative_binomial_pmf(0, 1, -1)$$),
'Negative binomial PMF: succ_prob out of range (0,1] does not raise error.'
);
-- negative_binomial_quantile
SELECT assert(
negative_binomial_quantile(NULL, 1, 1) IS NULL AND
negative_binomial_quantile(1, NULL, 1) IS NULL AND
negative_binomial_quantile(1, 1, NULL) IS NULL,
'Negative binomial Quantile: Wrong handling of NULLs.'
);
SELECT assert(
isnan(negative_binomial_quantile(1, 1, 'NaN') ),
'Negative binomial Quantile: Wrong handling of NaNs.'
);
SELECT assert(
negative_binomial_quantile(0,11, 0.4) = 0 AND
relative_error(negative_binomial_quantile(0.003906407, 11, 0.4), 3) < 1e-5 AND
relative_error(negative_binomial_quantile(0.22805, 11, 0.4), 11) < 1e-5 AND
relative_error(negative_binomial_quantile(0.287089336441514, 11, 0.4), 12) < 1e-5 AND
negative_binomial_quantile(1, 11, 0.4) = 'Inf' AND
negative_binomial_quantile(0.5, 20, 1) = 0,
'Negative binomial Quantile: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT negative_binomial_quantile(0, 0, 1)$$) AND
check_if_raises_error($$SELECT negative_binomial_quantile(0, -1, 1)$$) ,
'Negative binomial Quantile: non positive trials does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT negative_binomial_quantile(0, 1, 0)$$) AND
check_if_raises_error($$SELECT negative_binomial_quantile(0, 1, 2)$$) AND
check_if_raises_error($$SELECT negative_binomial_quantile(0, 1, -1)$$),
'Negative binomial Quantile: succ_prob out of range (0,1] does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT negative_binomial_quantile(-1, 1, 0.4)$$) AND
check_if_raises_error($$SELECT negative_binomial_quantile(2, 1, 0.4)$$),
'Negative binomial quantile: probability out of range [0,1] does not raise error.'
);
-- non_central_beta_cdf
SELECT assert(
non_central_beta_cdf(NULL, 1, 1, 1) IS NULL AND
non_central_beta_cdf(1, NULL, 1, 1) IS NULL AND
non_central_beta_cdf(1, 1, NULL, 1) IS NULL ANd
non_central_beta_cdf(1, 1, 1, NULL) IS NULL,
'Non-central beta CDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(non_central_beta_cdf('NaN', 1, 1, 1) ) AND
isnan(non_central_beta_cdf(1, 'NaN', 1, 1) ) AND
isnan(non_central_beta_cdf(1, 1, 'NaN', 1) ) ANd
isnan(non_central_beta_cdf(1, 1, 1, 'NaN') ),
'Non-central beta CDF: Wrong handling of NaNs.'
);
SELECT assert(
non_central_beta_cdf(-1, 1, 2, 3) = 0 AND
non_central_beta_cdf(0, 1, 2, 3) = 0 AND
relative_error(non_central_beta_cdf(0.5, 1, 2, 3), 0.4428436) < 1e-5 AND
non_central_beta_cdf(1, 1, 2, 3) = 1 AND
non_central_beta_cdf('Inf', 1, 2, 3) = 1 AND
non_central_beta_cdf(0, 0.5, 2, 3) = 0 AND
non_central_beta_cdf(1, 1, 0.5, 3) = 1 AND
non_central_beta_cdf(0, 0.5, 0.5, 3) = 0 AND
non_central_beta_cdf(1, 0.5, 0.5, 3) = 1,
'Non-central beta CDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT non_central_beta_cdf(0.5, 0, 1, 1)$$) AND
check_if_raises_error($$SELECT non_central_beta_cdf(0.5, 1, 0, 1)$$) AND
check_if_raises_error($$SELECT non_central_beta_cdf(0.5, -1, 1, 1)$$) AND
check_if_raises_error($$SELECT non_central_beta_cdf(0.5, 1, -1, 1)$$),
'Non-central beta CDF: shape parameters less or equal to 0 does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT non_central_beta_cdf(0.5, 1, 2, -1)$$) AND
NOT check_if_raises_error($$SELECT non_central_beta_cdf(0.5, 1, 2, 0)$$),
'Non-central beta CDF: non-centrality less than 0 does not raise error.'
);
-- non_central_beta_pdf
SELECT assert(
non_central_beta_pdf(NULL, 1, 1, 1) IS NULL AND
non_central_beta_pdf(1, NULL, 1, 1) IS NULL AND
non_central_beta_pdf(1, 1, NULL, 1) IS NULL ANd
non_central_beta_pdf(1, 1, 1, NULL) IS NULL,
'Non-central beta PDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(non_central_beta_pdf('NaN', 1, 1, 1) ) AND
isnan(non_central_beta_pdf(1, 'NaN', 1, 1) ) AND
isnan(non_central_beta_pdf(1, 1, 'NaN', 1) ) ANd
isnan(non_central_beta_pdf(1, 1, 1, 'NaN') ),
'Non-central beta PDF: Wrong handling of NaNs.'
);
SELECT assert(
non_central_beta_pdf(-1, 1, 2, 3) = 0 AND
relative_error(non_central_beta_pdf(0, 1, 2, 3), 2. * exp(-3./2.)) < 1e-5 AND
relative_error(non_central_beta_pdf(0.5, 1, 2, 3), 1.313769) < 1e-5 AND
non_central_beta_pdf(1, 1, 2, 3) = 0 AND
non_central_beta_pdf('Inf', 1, 2, 3) = 0 AND
non_central_beta_pdf(0, 0.5, 2, 3) = 'Inf' AND
non_central_beta_pdf(1, 1, 0.5, 3) = 'Inf' AND
non_central_beta_pdf(0, 0.5, 0.5, 3) = 'Inf' AND
non_central_beta_pdf(1, 0.5, 0.5, 3) = 'Inf',
'Non-central beta PDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT non_central_beta_pdf(0.5, 0, 1, 1)$$) AND
check_if_raises_error($$SELECT non_central_beta_pdf(0.5, 1, 0, 1)$$) AND
check_if_raises_error($$SELECT non_central_beta_pdf(0.5, -1, 1, 1)$$) AND
check_if_raises_error($$SELECT non_central_beta_pdf(0.5, 1, -1, 1)$$),
'Non-central beta PDF: shape parameters less or equal to 0 does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT non_central_beta_pdf(0.5, 1, 2, -1)$$) AND
NOT check_if_raises_error($$SELECT non_central_beta_pdf(0.5, 1, 2, 0)$$),
'Non-central beta PDF: non-centrality less than 0 does not raise error.'
);
-- non_central_beta_quantile
SELECT assert(
non_central_beta_quantile(NULL, 1, 1, 1) IS NULL AND
non_central_beta_quantile(1, NULL, 1, 1) IS NULL AND
non_central_beta_quantile(1, 1, NULL, 1) IS NULL ANd
non_central_beta_quantile(1, 1, 1, NULL) IS NULL,
'Non-central beta Quantile: Wrong handling of NULLs.'
);
SELECT assert(
isnan(non_central_beta_quantile('NaN', 1, 1, 1) ) AND
isnan(non_central_beta_quantile(1, 'NaN', 1, 1) ) AND
isnan(non_central_beta_quantile(1, 1, 'NaN', 1) ) ANd
isnan(non_central_beta_quantile(1, 1, 1, 'NaN') ),
'Non-central beta Quantile: Wrong handling of NaNs.'
);
SELECT assert(
non_central_beta_quantile(0, 1, 2, 3) = 0 AND
relative_error(non_central_beta_quantile(0.4428436, 1, 2, 3), 0.5) < 1e-5 AND
non_central_beta_quantile(1, 1, 2, 3) = 1 AND
non_central_beta_quantile(0, 0.5, 0.5, 3) = 0 AND
non_central_beta_quantile(1, 0.5, 0.5, 3) = 1,
'Non-central beta Quantile: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT non_central_beta_quantile(0.5, 0, 1, 1)$$) AND
check_if_raises_error($$SELECT non_central_beta_quantile(0.5, 1, 0, 1)$$) AND
check_if_raises_error($$SELECT non_central_beta_quantile(0.5, -1, 1, 1)$$) AND
check_if_raises_error($$SELECT non_central_beta_quantile(0.5, 1, -1, 1)$$),
'Non-central beta Quantile: shape parameters less or equal to 0 does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT non_central_beta_quantile(0.5, 1, 2, -1)$$) AND
NOT check_if_raises_error($$SELECT non_central_beta_quantile(0.5, 1, 2, 0)$$),
'Non-central beta Quantile: non-centrality less than 0 does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT non_central_beta_quantile(-1, 1, 1, 1)$$) AND
check_if_raises_error($$SELECT non_central_beta_quantile(2, 1, 1, 1)$$) ,
'Non-central beta Quantile: CDF out of range [0,1] does not raise error.'
);
-- non_central_chi_squared_cdf
SELECT assert(
non_central_chi_squared_cdf(NULL, 1, 1) IS NULL AND
non_central_chi_squared_cdf(1, NULL, 1) IS NULL AND
non_central_chi_squared_cdf(1, 1, NULL) IS NULL,
'Non-central chi-squared CDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(non_central_chi_squared_cdf('NaN', 1, 1) ) AND
isnan(non_central_chi_squared_cdf(1, 'NaN', 1) ) AND
isnan(non_central_chi_squared_cdf(1, 1, 'NaN') ),
'Non-central chi-squared CDF: Wrong handling of NaNs.'
);
SELECT assert(
non_central_chi_squared_cdf(0, 1, 3) = 0 AND
non_central_chi_squared_cdf(-1, 2, 3) = 0 AND
non_central_chi_squared_cdf(0, 2, 3) = 0 AND
non_central_chi_squared_cdf('Inf', 2, 3) = 1 AND
relative_error(non_central_chi_squared_cdf(1, 2, 3), 0.1218255) < 1e-5,
'Non-central chi-squared CDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT non_central_chi_squared_cdf(1.5, 0, 1)$$) AND
check_if_raises_error($$SELECT non_central_chi_squared_cdf(1.5, -1, 1)$$),
'Non-central chi-squared CDF: degree of freedom less than or equal to 0 does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT non_central_chi_squared_cdf(1.5, 1, -1)$$) AND
NOT check_if_raises_error($$SELECT non_central_chi_squared_cdf(1.5, 1, 0)$$),
'Non-central chi-squared CDF: non-centrality less than to 0 does not raise error.'
);
-- non_central_chi_squared_pdf
SELECT assert(
non_central_chi_squared_pdf(NULL, 1, 1) IS NULL AND
non_central_chi_squared_pdf(1, NULL, 1) IS NULL AND
non_central_chi_squared_pdf(1, 1, NULL) IS NULL,
'Non-central chi-squared PDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(non_central_chi_squared_pdf('NaN', 1, 1) ) AND
isnan(non_central_chi_squared_pdf(1, 'NaN', 1) ) AND
isnan(non_central_chi_squared_pdf(1, 1, 'NaN') ),
'Non-central chi-squared PDF: Wrong handling of NaNs.'
);
SELECT assert(
non_central_chi_squared_pdf(0, 1, 3) = 'Inf' AND
non_central_chi_squared_pdf(-1, 2, 3) = 0 AND
relative_error(non_central_chi_squared_pdf(0, 2, 3), 0.1115651) < 1e-5 AND
non_central_chi_squared_pdf('Inf', 2, 3) = 0 AND
relative_error(non_central_chi_squared_pdf(1, 2, 3), 0.1287654) < 1e-5,
'Non-central chi-squared PDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT non_central_chi_squared_pdf(1.5, 0, 1)$$) AND
check_if_raises_error($$SELECT non_central_chi_squared_pdf(1.5, -1, 1)$$),
'Non-central chi-squared PDF: degree of freedom less than or equal to 0 does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT non_central_chi_squared_pdf(1.5, 1, -1)$$) AND
NOT check_if_raises_error($$SELECT non_central_chi_squared_pdf(1.5, 1, 0)$$),
'Non-central chi-squared PDF: non-centrality less than 0 does not raise error.'
);
-- non_central_chi_squared_quantile
SELECT assert(
non_central_chi_squared_quantile(NULL, 1, 1) IS NULL AND
non_central_chi_squared_quantile(1, NULL, 1) IS NULL AND
non_central_chi_squared_quantile(1, 1, NULL) IS NULL,
'Non-central chi-squared Quantile: Wrong handling of NULLs.'
);
SELECT assert(
isnan(non_central_chi_squared_quantile('NaN', 1, 1) ) AND
isnan(non_central_chi_squared_quantile(1, 'NaN', 1) ) AND
isnan(non_central_chi_squared_quantile(1, 1, 'NaN') ),
'Non-central chi-squared Quantile: Wrong handling of NaNs.'
);
SELECT assert(
non_central_chi_squared_quantile(0, 1, 3) = 0 AND
non_central_chi_squared_quantile(0, 2, 3) = 0 AND
non_central_chi_squared_quantile(1, 2, 3) > 1.79769313486231e+308 AND
relative_error(non_central_chi_squared_quantile(0.1218255, 2, 3), 1) < 1e-5,
'Non-central chi-squared Quantile: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT non_central_chi_squared_quantile(1.5, 0, 1)$$) AND
check_if_raises_error($$SELECT non_central_chi_squared_quantile(1.5, -1, 1)$$),
'Non-central chi-squared Quantile: degree of freedom less than or equal to 0 does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT non_central_chi_squared_quantile(0.5, 1, -1)$$) AND
NOT check_if_raises_error($$SELECT non_central_chi_squared_quantile(0.5, 1, 0)$$),
'Non-central chi-squared Quantile: non-centrality less than 0 does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT non_central_chi_squared_quantile(-1, 2)$$) AND
check_if_raises_error($$SELECT non_central_chi_squared_quantile(1.5, 0)$$),
'Non-central chi-squared Quantile: CDF out of range [0,1] does not raise error.'
);
-- non_central_f_cdf
SELECT assert(
non_central_f_cdf(NULL, 1, 1, 1) IS NULL AND
non_central_f_cdf(1, NULL, 1, 1) IS NULL AND
non_central_f_cdf(1, 1, NULL, 1) IS NULL AND
non_central_f_cdf(1, 1, 1, NULL) IS NULL,
'Non-central fisher f CDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(non_central_f_cdf('nan', 1, 1, 1 )) AND
isnan(non_central_f_cdf(1, 'NaN', 1, 1 )) AND
isnan(non_central_f_cdf(1, 1, 'NaN', 1 )) AND
isnan(non_central_f_cdf(1, 1, 1, 'NaN' )),
'Non-central fisher f CDF: Wrong handling of NaNs.'
);
SELECT assert(
non_central_f_cdf(-1, 1, 2, 3) = 0 AND
non_central_f_cdf(0, 1, 2, 3) = 0 AND
relative_error(non_central_f_cdf(1, 1, 2, 3), 0.2123953) < 1e-5 AND
non_central_f_cdf('Inf', 1, 2, 3) = 1,
'Non-central fisher f CDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT non_central_f_cdf(1.5, 0, 1, 1)$$) AND
check_if_raises_error($$SELECT non_central_f_cdf(1.5, 1, 0, 1)$$) AND
check_if_raises_error($$SELECT non_central_f_cdf(1.5, -1, 1, 1)$$) AND
check_if_raises_error($$SELECT non_central_f_cdf(1.5, 1, -1, 1)$$),
'Non-central fisher f CDF: degrees of freedom less or equal to 0 does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT non_central_f_cdf(1.5, 1, 1, -1)$$),
'Non-central fisher f CDF: non-centrality less than 0 does not raise error.'
);
-- non_central_f_pdf
SELECT assert(
non_central_f_pdf(NULL, 1, 1, 1) IS NULL AND
non_central_f_pdf(1, NULL, 1, 1) IS NULL AND
non_central_f_pdf(1, 1, NULL, 1) IS NULL AND
non_central_f_pdf(1, 1, 1, NULL) IS NULL,
'Non-central fisher f PDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(non_central_f_pdf('NaN', 1, 1, 1 )) AND
isnan(non_central_f_pdf(1, 'NaN', 1, 1 )) AND
isnan(non_central_f_pdf(1, 1, 'NaN', 1 )) AND
isnan(non_central_f_pdf(1, 1, 1, 'NaN' )),
'Non-central fisher f PDF: Wrong handling of NaNs.'
);
SELECT assert(
non_central_f_pdf(-1, 1, 2, 3) = 0 AND
non_central_f_pdf(0, 1, 2, 3) = 'Inf' AND
relative_error(non_central_f_pdf(0, 2, 2, 3), exp(-3./2.)) < 1e-5 AND
relative_error(non_central_f_pdf(1, 1, 2, 3), 0.1415969) < 1e-5 AND
non_central_f_pdf('Inf', 1, 2, 3) = 0,
'Non-central fisher f PDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT non_central_f_pdf(1.5, 0, 1, 1)$$) AND
check_if_raises_error($$SELECT non_central_f_pdf(1.5, 1, 0, 1)$$) AND
check_if_raises_error($$SELECT non_central_f_pdf(1.5, -1, 1, 1)$$) AND
check_if_raises_error($$SELECT non_central_f_pdf(1.5, 1, -1, 1)$$),
'Non-central fisher f PDF: degrees of freedom less or equal to 0 does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT non_central_f_pdf(1.5, 1, 1, -1)$$),
'Non-central fisher f PDF: non-centrality less than 0 does not raise error.'
);
-- non_central_f_quantile
SELECT assert(
non_central_f_quantile(NULL, 1, 1, 1) IS NULL AND
non_central_f_quantile(1, NULL, 1, 1) IS NULL AND
non_central_f_quantile(1, 1, NULL, 1) IS NULL AND
non_central_f_quantile(1, 1, 1, NULL) IS NULL,
'Non-central fisher f Quantile: Wrong handling of NULLs.'
);
SELECT assert(
isnan(non_central_f_quantile('NaN', 1, 1, 1 )) AND
isnan(non_central_f_quantile(1, 'NaN', 1, 1 )) AND
isnan(non_central_f_quantile(1, 1, 'NaN', 1 )) AND
isnan(non_central_f_quantile(1, 1, 1, 'NaN' )),
'Non-central fisher f Quantile: Wrong handling of NaNs.'
);
SELECT assert(
non_central_f_quantile(0, 1, 2, 3) = 0 AND
relative_error(non_central_f_quantile(0.2123953, 1, 2, 3), 1) < 1e-5 AND
non_central_f_quantile(1, 1, 2, 3) = 'Inf',
'Non-central fisher f Quantile: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT non_central_f_quantile(1.5, 0, 1, 1)$$) AND
check_if_raises_error($$SELECT non_central_f_quantile(1.5, 1, 0, 1)$$) AND
check_if_raises_error($$SELECT non_central_f_quantile(1.5, -1, 1, 1)$$) AND
check_if_raises_error($$SELECT non_central_f_quantile(1.5, 1, -1, 1)$$),
'Non-central fisher f Quantile: degrees of freedom less or equal to 0 does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT non_central_f_quantile(1.5, 1, 1, -1)$$),
'Non-central fisher f Quantile: non-centrality less than 0 does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT non_central_f_quantile(-1, 1, 1, 1)$$) AND
check_if_raises_error($$SELECT non_central_f_quantile(2, 1, 1, 1)$$) ,
'Non-central fisher f Quantile: CDF out of range [0,1] does not raise error.'
);
-- non_central_t_cdf
SELECT assert(
non_central_t_cdf(NULL, 1, 1) IS NULL AND
non_central_t_cdf(1, NULL, 1) IS NULL ANd
non_central_t_cdf(1, 1, NULL) IS NULL,
'Noncentral Students-t CDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan( non_central_t_cdf('NaN', 1, 1) ) AND
isnan( non_central_t_cdf(1, 'NaN', 1) ) AND
isnan( non_central_t_cdf(1, 1, 'NaN') ),
'Noncentral Students-t CDF: Wrong handling of NaNs.'
);
SELECT assert(
non_central_t_cdf('-Inf', 1, 1) = 0 AND
non_central_t_cdf('Inf', 1, 1) = 1 AND
relative_error(non_central_t_cdf(3, 1, 1), 0.7301026) < 1e-5 AND
relative_error(non_central_t_cdf(-3, 1, 1), 0.02172704) < 1e-5,
'Noncentral Students-t CDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT non_central_t_cdf(1, 0, 1)$$) AND
check_if_raises_error($$SELECT non_central_t_cdf(1, -1, 0)$$),
'Noncentral Students-t CDF: Non-positive degree of freedom (nu) does not raise error.'
);
-- non_central_t_pdf
SELECT assert(
non_central_t_pdf(NULL, 1, 1) IS NULL AND
non_central_t_pdf(1, NULL, 1) IS NULL ANd
non_central_t_pdf(1, 1, NULL) IS NULL,
'Noncentral Students-t PDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan( non_central_t_pdf('NaN', 1, 1) ) AND
isnan( non_central_t_pdf(1, 'NaN', 1) ) AND
isnan( non_central_t_pdf(1, 1, 'NaN') ),
'Noncentral Students-t PDF: Wrong handling of NaNs.'
);
SELECT assert(
non_central_t_pdf('-Inf', 1, 1) = 0 AND
non_central_t_pdf('Inf', 1, 1) = 0 AND
relative_error(non_central_t_pdf(3, 1, 1), 0.07896827) < 1e-5 AND
relative_error(non_central_t_pdf(-3, 1, 1), 0.006965928) < 1e-5,
'Noncentral Students-t PDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT non_central_t_pdf(1, 0, 1)$$) AND
check_if_raises_error($$SELECT non_central_t_pdf(1, -1, 0)$$),
'Noncentral Students-t PDF: Non-positive degree of freedom (nu) does not raise error.'
);
-- non_central_t_quantile
SELECT assert(
non_central_t_quantile(NULL, 1, 1) IS NULL AND
non_central_t_quantile(1, NULL, 1) IS NULL ANd
non_central_t_quantile(1, 1, NULL) IS NULL,
'Noncentral Students-t Quantile: Wrong handling of NULLs.'
);
SELECT assert(
isnan( non_central_t_quantile('NaN', 1, 1) ) AND
isnan( non_central_t_quantile(1, 'NaN', 1) ) AND
isnan( non_central_t_quantile(1, 1, 'NaN') ),
'Noncentral Students-t Quantile: Wrong handling of NaNs.'
);
SELECT assert(
non_central_t_quantile(0, 1, 1) = '-Inf' AND
non_central_t_quantile(1, 1, 1) = 'Inf' AND
relative_error(non_central_t_quantile(0.7301026, 1, 1), 3) < 1e-5 AND
relative_error(non_central_t_quantile(0.02172704, 1, 1), -3) < 1e-5,
'Noncentral Students-t Quantile: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT non_central_t_quantile(1, 0, 1)$$) AND
check_if_raises_error($$SELECT non_central_t_quantile(1, -1, 0)$$),
'Noncentral Students-t Quantile: Non-positive degree of freedom (nu) does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT non_central_t_quantile(-1, 1)$$) AND
check_if_raises_error($$SELECT non_central_t_quantile(2, 1)$$) ,
'Noncentral Students-t Quantile: CDF out of range [0,1] does not raise error.'
);
-- normal_cdf
SELECT assert(
normal_cdf(NULL, 0, 1) IS NULL AND
normal_cdf(0, NULL, 1) IS NULL AND
normal_cdf(0, 0, NULL) IS NULL,
'Normal CDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(normal_cdf('NaN', 0, 1)) AND
isnan(normal_cdf(0, 'NaN', 1)) AND
isnan(normal_cdf(0, 0, 'NaN')),
'Normal CDF: Wrong handling of NaNs.'
);
SELECT assert(
relative_error(normal_cdf(0.5, 0, 1), 0.6914625) < 1e-5 AND
relative_error(normal_cdf(-0.5, 0, 1), 0.3085375) < 1e-5 AND
relative_error(normal_cdf(0, 0, 1), 0.5) < 1e-5 AND
normal_cdf('Infinity', 0, 1) = 1 AND
normal_cdf('-Infinity', 0, 1) = 0,
'Normal CDF: Wrong values with mu = 0, signma = 1.'
);
SELECT assert(
relative_error(normal_cdf(0.5, -1, 2), 0.7733726) < 1e-5 AND
relative_error(normal_cdf(-0.5, -1, 2), 0.5987063) < 1e-5 AND
relative_error(normal_cdf(0, -1, 2), 0.6914625) < 1e-5 AND
relative_error(normal_cdf('Infinity', -1, 2), 1) < 1e-5 AND
normal_cdf('-Infinity', -1, 2) = 0,
'Normal CDF: Wrong values with mu = -1, signma = 2.'
);
SELECT assert(
check_if_raises_error($$SELECT normal_cdf(0.5, -2, -1)$$),
'Normal CDF: Non-positive sigma does not raise error.'
);
-- normal_pdf
CREATE OR REPLACE FUNCTION _test_normal_pdf(t float8, mu float8, sigma float8) RETURNS float8 AS $$
select exp(-1*($1 - $2)^2/(2*($3^2)))/sqrt(2*pi()*$3^2);
$$LANGUAGE 'sql' STRICT IMMUTABLE;
SELECT assert(
normal_pdf(NULL, 0, 1) IS NULL AND
normal_pdf(0, NULL, 1) IS NULL AND
normal_pdf(0, 0, NULL) IS NULL,
'Normal PDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(normal_pdf('NaN', 0, 1)) AND
isnan(normal_pdf(0, 'NaN', 1)) AND
isnan(normal_pdf(0, 0, 'NaN')),
'Normal PDF: Wrong handling of NaNs.'
);
SELECT assert(
relative_error(normal_pdf(0.5, 0, 1), _test_normal_pdf(0.5, 0, 1)) < 1e-5 AND
relative_error(normal_pdf(-0.5, 0, 1), _test_normal_pdf(-0.5, 0, 1)) < 1e-5 AND
relative_error(normal_pdf(0, 0, 1), _test_normal_pdf(0, 0, 1)) < 1e-5 AND
normal_pdf('Infinity', 0, 1) = 0 AND
normal_pdf('-Infinity', 0, 1) = 0,
'Normal PDF: Wrong values with mu = 0, signma = 1.'
);
SELECT assert(
relative_error(normal_pdf(0.5, -1, 2), _test_normal_pdf(0.5, -1, 2)) < 1e-5 AND
relative_error(normal_pdf(-0.5, -1, 2), _test_normal_pdf(-0.5, -1, 2)) < 1e-5 AND
relative_error(normal_pdf(0, -1, 2), _test_normal_pdf(0, -1, 2)) < 1e-5 AND
normal_pdf('Infinity', -1, 2) = 0 AND
normal_pdf('-Infinity', -1, 2) = 0,
'Normal PDF: Wrong values with mu = -1, signma = 2.'
);
SELECT assert(
check_if_raises_error($$SELECT normal_pdf(0.5, -2, -1)$$),
'Normal PDF: Non-positive sigma does not raise error.'
);
DROP FUNCTION _test_normal_pdf(t float8, mu float8, sigma float8);
-- normal_quantile
SELECT assert(
normal_quantile(NULL, 0, 1) IS NULL AND
normal_quantile(0, NULL, 1) IS NULL AND
normal_quantile(0, 0, NULL) IS NULL,
'Normal Quantile: Wrong handling of NULLs.'
);
SELECT assert(
isnan(normal_quantile('NaN', 0, 1)) AND
isnan(normal_quantile(0, 'NaN', 1)) AND
isnan(normal_quantile(0, 0, 'NaN')),
'Normal Quantile: Wrong handling of NaNs.'
);
SELECT assert(
normal_quantile(1, 0, 1) = 'Inf'::float8,
'Normal Quantile: Wrong value for CDF = 1'
);
SELECT assert(
normal_quantile(0, 0, 1) = '-Inf'::float8,
'Normal Quantile: Wrong value for CDF = 0'
);
SELECT assert(
abs(normal_quantile(0.5, 0, 1)) < 1e-5 AND
relative_error(normal_quantile(0.6, 0, 1), 0.2533471) < 1e-5 AND
normal_quantile(0, 0, 1) = '-Inf',
'Normal Quantile: Wrong values with mu = 0, signma = 1.'
);
SELECT assert(
relative_error(normal_quantile(0.5, -1, 2), -1) < 1e-5 AND
relative_error(normal_quantile(0.6, -1, 2), -0.4933058) < 1e-5 AND
normal_quantile(0, -1, 2) = '-inf',
'Normal Quantile: Wrong values with mu = -1, signma = 2.'
);
SELECT assert(
check_if_raises_error($$SELECT normal_quantile(0.5, -2, -1)$$),
'Normal Quantile: Non-positive sigma does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT normal_quantile(-0.5, -2, 1)$$),
'Normal Quantile: Non-positive CDF does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT normal_quantile(1.5, -2, 1)$$),
'Normal Quantile: CDF bigger than 1 does not raise error.'
);
-- pareto_cdf
SELECT assert(
pareto_cdf(NULL, 1, 1) IS NULL AND
pareto_cdf(1, NULL, 1) IS NULL AND
pareto_cdf(1, 1, NULL) IS NULL,
'Pareto CDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(pareto_cdf('NaN', 1, 1) ) AND
isnan(pareto_cdf(1, 'NaN', 1) ) AND
isnan(pareto_cdf(1, 1, 'NaN') ),
'Pareto CDF: Wrong handling of NaNs.'
);
SELECT assert(
pareto_cdf(-1, 1, 1) = 0 AND
pareto_cdf(0, 1, 1) = 0 AND
pareto_cdf(1, 1, 1) = 0 AND
pareto_cdf(2, 1, 1) = 0.5 AND
pareto_cdf(2, 2, 3) = 0 AND
pareto_cdf('Inf', 1, 1) = 1,
'Pareto CDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT pareto_cdf(0.5, 0, 1)$$) AND
check_if_raises_error($$SELECT pareto_cdf(0.5, -1, 1)$$),
'Pareto CDF: location less than or equal to 0 does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT pareto_cdf(0.5, 1, 0)$$) AND
check_if_raises_error($$SELECT pareto_cdf(0.5, 1, -1)$$),
'Pareto CDF: shape less than or equal to 0 does not raise error.'
);
-- pareto_pdf
SELECT assert(
pareto_pdf(NULL, 1, 1) IS NULL AND
pareto_pdf(1, NULL, 1) IS NULL AND
pareto_pdf(1, 1, NULL) IS NULL,
'Pareto PDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(pareto_pdf('NaN', 1, 1) ) AND
isnan(pareto_pdf(1, 'NaN', 1) ) AND
isnan(pareto_pdf(1, 1, 'NaN') ),
'Pareto PDF: Wrong handling of NaNs.'
);
SELECT assert(
pareto_pdf(-1, 1, 1) = 0 AND
pareto_pdf(0, 1, 1) = 0 AND
pareto_pdf(1, 1, 1) = 1 AND
pareto_pdf(2, 1, 1) = 0.25 AND
pareto_pdf(2, 2, 3) = 3. * 2^3 / 2^(3 + 1) /* = 1.5 (exactly representable) */ AND
pareto_pdf('Inf', 1, 1) = 0,
'Pareto PDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT pareto_pdf(0.5, 0, 1)$$) AND
check_if_raises_error($$SELECT pareto_pdf(0.5, -1, 1)$$),
'Pareto PDF: location less than or equal to 0 does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT pareto_pdf(0.5, 1, 0)$$) AND
check_if_raises_error($$SELECT pareto_pdf(0.5, 1, -1)$$),
'Pareto PDF: shape less than or equal to 0 does not raise error.'
);
-- pareto_quantile
SELECT assert(
pareto_quantile(NULL, 1, 1) IS NULL AND
pareto_quantile(1, NULL, 1) IS NULL AND
pareto_quantile(1, 1, NULL) IS NULL,
'Pareto Quantile: Wrong handling of NULLs.'
);
SELECT assert(
isnan(pareto_quantile('NaN', 1, 1) ) AND
isnan(pareto_quantile(1, 'NaN', 1) ) AND
isnan(pareto_quantile(1, 1, 'NaN') ),
'Pareto Quantile: Wrong handling of NaNs.'
);
SELECT assert(
pareto_quantile(1, 1, 1) = 'Inf' AND
pareto_quantile(0.5, 1, 1) = 2 AND
pareto_quantile(0, 1, 1) = 1,
'Pareto Quantile: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT pareto_quantile(0.5, 0, 1)$$) AND
check_if_raises_error($$SELECT pareto_quantile(0.5, -1, 1)$$),
'Pareto Quantile: location less than or equal to 0 does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT pareto_quantile(0.5, 1, 0)$$) AND
check_if_raises_error($$SELECT pareto_quantile(0.5, 1, -1)$$),
'Pareto Quantile: shape less than or equal to 0 does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT pareto_quantile(-1, 1)$$) AND
check_if_raises_error($$SELECT pareto_quantile(2, 1)$$) ,
'Pareto Quantile: CDF out of range [0,1] does not raise error.'
);
-- poisson_cdf
SELECT assert(
poisson_cdf(NULL, 1) IS NULL AND
poisson_cdf(1, NULL) IS NULL,
'Poisson CDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(poisson_cdf('NaN', 1) ) AND
isnan(poisson_cdf(1, 'NaN') ) ,
'Poisson CDF: Wrong handling of NaNs.'
);
SELECT assert(
relative_error(poisson_cdf(0, 0.3), 0.7408182) < 1e-5 AND
poisson_cdf(0.7, 0.3) = poisson_cdf(0, 0.3) AND
relative_error(poisson_cdf(1, 0.3), 0.9630637) < 1e-5 AND
relative_error(poisson_cdf(2, 0.3), 0.9964005) < 1e-5 AND
poisson_cdf('Inf', 0.3) = 1 AND
poisson_cdf('-Inf', 0.3) = 0 AND
poisson_cdf(-0.1, 0.3) = 0,
'Poisson CDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT poisson_cdf(5, -1)$$) AND
check_if_raises_error($$SELECT poisson_cdf(5, 0)$$) ,
'Poisson CDF: mean less than or equal to 0 does not raise error.'
);
-- poisson_pmf
SELECT assert(
poisson_pmf(NULL, 1) IS NULL AND
poisson_pmf(1, NULL) IS NULL,
'Poisson PMF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(poisson_pmf(1, 'NaN') ) ,
'Poisson PMF: Wrong handling of NaNs.'
);
SELECT assert(
relative_error(poisson_pmf(0, 0.3), 0.7408182) < 1e-5 AND
relative_error(poisson_pmf(1, 0.3), 0.2222455) < 1e-5 AND
relative_error(poisson_pmf(2, 0.3), 0.03333682) < 1e-5 AND
poisson_pmf(-1, 0.3) = 0,
'Poisson PMF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT poisson_pmf(5, -1)$$) AND
check_if_raises_error($$SELECT poisson_pmf(5, 0)$$) ,
'Poisson PMF: less than or equal to 0 does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT poisson_pmf(0.5, 0.3)$$),
'Poisson PMF: random variable not in {.., -1, 0, 1, 2, ...} does not raise error.'
);
-- poisson_quantile
SELECT assert(
poisson_quantile(NULL, 1) IS NULL AND
poisson_quantile(1, NULL) IS NULL,
'Poisson Quantile: Wrong handling of NULLs.'
);
SELECT assert(
isnan(poisson_quantile('NaN', 1) ) AND
isnan(poisson_quantile(1, 'NaN') ) ,
'Poisson Quantile: Wrong handling of NaNs.'
);
SELECT assert(
abs(poisson_quantile(0.7408182, 0.3)) < 1e-5 AND
relative_error(poisson_quantile(0.963063686886233, 0.3), 1) < 1e-5 AND
relative_error(poisson_quantile(0.9964005, 0.3), 2) < 1e-5 AND
poisson_quantile(0, 0.3) = 0 AND
poisson_quantile(1, 0.3) = 'Inf',
'Poisson Quantile: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT poisson_quantile(0.5, -1)$$) AND
check_if_raises_error($$SELECT poisson_quantile(0.5, 0)$$) ,
'Poisson Quantile: less than or equal to 0 does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT poisson_quantile(-1, 1)$$) AND
check_if_raises_error($$SELECT poisson_quantile(2, 1)$$) ,
'Poisson Quantile: CDF out of range [0,1] does not raise error.'
);
-- rayleigh_cdf
SELECT assert(
rayleigh_cdf(NULL, 1) IS NULL AND
rayleigh_cdf(1, NULL) IS NULL,
'Rayleigh CDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(rayleigh_cdf('NaN', 1)) AND
isnan(rayleigh_cdf(1, 'NaN')) ,
'Rayleigh CDF: Wrong handling of NaNs.'
);
SELECT assert(
relative_error(rayleigh_cdf(2,3), 0.1992626) < 1e-5 AND
rayleigh_cdf(0,3) = 0 AND
rayleigh_cdf(-1,3) = 0 AND
rayleigh_cdf('-Inf',2) = 0 AND
rayleigh_cdf('Inf',2) = 1,
'Rayleigh CDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT rayleigh_cdf(0.5, 0)$$) AND
check_if_raises_error($$SELECT rayleigh_cdf(0.5, -1)$$) AND
check_if_raises_error($$SELECT rayleigh_cdf(0.5, '-Inf')$$) AND
check_if_raises_error($$SELECT rayleigh_cdf(0.5, 'Inf')$$),
'Rayleigh CDF: shape outside (0, infinity) does not raise error.'
);
-- rayleigh_pdf
SELECT assert(
rayleigh_pdf(NULL, 1) IS NULL AND
rayleigh_pdf(1, NULL) IS NULL,
'Rayleigh PDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(rayleigh_pdf('NaN', 1)) AND
isnan(rayleigh_pdf(1, 'NaN')) ,
'Rayleigh PDF: Wrong handling of NaNs.'
);
SELECT assert(
relative_error(rayleigh_pdf(2,3), 0.1779416) < 1e-5 AND
rayleigh_pdf(0,3) = 0 AND
rayleigh_pdf(-1,3) = 0 AND
rayleigh_pdf('-Inf',2) = 0 AND
rayleigh_pdf('Inf',2) = 0,
'Rayleigh PDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT rayleigh_pdf(0.5, 0)$$) AND
check_if_raises_error($$SELECT rayleigh_pdf(0.5, -1)$$) AND
check_if_raises_error($$SELECT rayleigh_pdf(0.5, '-Inf')$$) AND
check_if_raises_error($$SELECT rayleigh_pdf(0.5, 'Inf')$$),
'Rayleigh PDF: shape outside (0, infinity) does not raise error.'
);
-- rayleigh_quantile
SELECT assert(
rayleigh_quantile(NULL, 1) IS NULL AND
rayleigh_quantile(1, NULL) IS NULL,
'Rayleigh Quantile: Wrong handling of NULLs.'
);
SELECT assert(
isnan(rayleigh_quantile('NaN', 1)) AND
isnan(rayleigh_quantile(1, 'NaN')) ,
'Rayleigh Quantile: Wrong handling of NaNs.'
);
SELECT assert(
relative_error(rayleigh_quantile(0.1992626,3), 2) < 1e-5 AND
rayleigh_quantile(0,3) = 0 AND
rayleigh_quantile(1,3) = 'Inf',
'Rayleigh Quantile: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT rayleigh_quantile(0.5, 0)$$) AND
check_if_raises_error($$SELECT rayleigh_quantile(0.5, -1)$$) AND
check_if_raises_error($$SELECT rayleigh_quantile(0.5, '-Inf')$$) AND
check_if_raises_error($$SELECT rayleigh_quantile(0.5, 'Inf')$$),
'Rayleigh Quantile: shape outside (0, infinity) does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT rayleigh_quantile(-1, 1)$$) AND
check_if_raises_error($$SELECT rayleigh_quantile(2, 1)$$) ,
'Rayleigh Quantile: CDF out of range [0,1] does not raise error.'
);
-- students_t_cdf
SELECT assert(
students_t_cdf(NULL, 1) IS NULL AND
students_t_cdf(1, NULL) IS NULL,
$$Student's t CDF: Wrong handling of NULLs.$$
);
SELECT assert(
isnan( students_t_cdf('NaN', 1) ) AND
isnan( students_t_cdf(1, 'NaN') ),
$$Student's t CDF: Wrong handling of NaNs.$$
);
SELECT assert(
relative_error(students_t_cdf(0, 1000001), 0.5) < 0.0001 AND
relative_error(students_t_cdf(1, 1000001) + students_t_cdf(-1, 1000001), 1.0) < 1e-5 AND
relative_error(students_t_cdf(0, 201), 0.5) < 0.0001 AND
relative_error(students_t_cdf(1, 201) + students_t_cdf(-1, 201), 1.0) < 0.001 AND
relative_error(students_t_cdf(0, 5), 0.5) < 0.0001 AND
relative_error(students_t_cdf(1, 5) + students_t_cdf(-1, 5), 1.0) < 0.001 AND
relative_error(students_t_cdf(0, 4.5), 0.5) < 0.0001 AND
relative_error(students_t_cdf(1, 4.5) + students_t_cdf(-1, 4.5), 1.0) < 0.001,
$$Student's t CDF: Distribution is not symmetric.$$
);
SELECT assert(
relative_error(students_t_cdf(1, 1), 1.0/2 + 1.0/pi() * atan(1)) < 0.0001 AND
relative_error(students_t_cdf(-1, 1), 1.0/2 + 1.0/pi() * atan(-1)) < 0.0001 AND
relative_error(students_t_cdf(2, 1), 1.0/2 + 1.0/pi() * atan(2)) < 0.0001 AND
relative_error(students_t_cdf(-2, 1), 1.0/2 + 1.0/pi() * atan(-2)) < 0.0001 AND
relative_error(students_t_cdf(4, 1), 1.0/2 + 1.0/pi() * atan(4)) < 0.0001 AND
relative_error(students_t_cdf(-4, 1), 1.0/2 + 1.0/pi() * atan(-4)) < 0.0001 AND
relative_error(students_t_cdf(1, 2), 1.0/2 * (1. + 1/sqrt(2 + 1^2))) < 0.0001 AND
relative_error(students_t_cdf(-1, 2), 1.0/2 * (1. - 1/sqrt(2 + 1^2))) < 0.0001 AND
relative_error(students_t_cdf(2, 2), 1.0/2 * (1. + 2/sqrt(2 + 2^2))) < 0.0001 AND
relative_error(students_t_cdf(-2, 2), 1.0/2 * (1. - 2/sqrt(2 + 2^2))) < 0.0001 AND
relative_error(students_t_cdf(4, 2), 1.0/2 * (1. + 4/sqrt(2 + 4^2))) < 0.0001 AND
relative_error(students_t_cdf(-4, 2), 1.0/2 * (1. - 4/sqrt(2 + 4^2))) < 0.0001,
$$Student's t CDF: Wrong values for special case nu in {1,2}.$$
);
SELECT assert(
check_if_raises_error($$SELECT students_t_cdf(1, 0)$$) AND
NOT check_if_raises_error($$SELECT students_t_cdf(1, 1)$$),
$$Student's t CDF: Non-positive degree of freedom (nu) does not raise error.$$
);
-- students_t_pdf
SELECT assert(
students_t_pdf(NULL, 1) IS NULL AND
students_t_pdf(1, NULL) IS NULL,
'Students-t PDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan( students_t_pdf('NaN', 1) ) AND
isnan( students_t_pdf(1, 'NaN') ),
'Students-t PDF: Wrong handling of NaNs.'
);
SELECT assert(
relative_error(students_t_pdf(1, 1), 0.1591549) < 1e-5 AND
relative_error(students_t_pdf(-1, 1), 0.1591549) < 1e-5 AND
relative_error(students_t_pdf(2, 1), 0.06366198) < 1e-5 AND
relative_error(students_t_pdf(-2, 1), 0.06366198) < 1e-5 AND
relative_error(students_t_pdf(4, 1), 0.01872411) < 1e-5 AND
relative_error(students_t_pdf(-4, 1), 0.01872411) < 1e-5 AND
relative_error(students_t_pdf(1, 2), 0.1924501) < 1e-5 AND
relative_error(students_t_pdf(-1, 2), 0.1924501) < 1e-5 AND
relative_error(students_t_pdf(2, 2), 0.06804138) < 1e-5 AND
relative_error(students_t_pdf(-2, 2), 0.06804138) < 1e-5 AND
relative_error(students_t_pdf(4, 2), 0.01309457) < 1e-5 AND
relative_error(students_t_pdf(-4, 2), 0.01309457) < 1e-5,
'Students-t PDF: Wrong values for special case nu in {1,2}.'
);
SELECT assert(
check_if_raises_error($$SELECT students_t_pdf(1, 0)$$) AND
NOT check_if_raises_error($$SELECT students_t_pdf(1, 1)$$),
'Students-t PDF: Non-positive degree of freedom (nu) does not raise error.'
);
-- students_t_quantile
SELECT assert(
students_t_quantile(NULL, 1) IS NULL AND
students_t_quantile(1, NULL) IS NULL,
'Students-t Quantile: Wrong handling of NULLs.'
);
SELECT assert(
isnan( students_t_quantile('NaN', 1) ) AND
isnan( students_t_quantile(1, 'NaN') ),
'Students-t Quantile: Wrong handling of NaNs.'
);
SELECT assert(
students_t_quantile(1, 1) = 'Inf' AND
relative_error(students_t_quantile(0.9, 1), 3.077684) < 1e-5 AND
students_t_quantile(0, 1) = '-Inf' And
students_t_quantile(1, 2) = 'Inf' AND
relative_error(students_t_quantile(0.9, 2), 1.885618) < 1e-5 AND
students_t_quantile(0, 2) = '-Inf',
'Students-t Quantile: Wrong values for special case nu in {1,2}.'
);
SELECT assert(
check_if_raises_error($$SELECT students_t_quantile(1, 0)$$) AND
NOT check_if_raises_error($$SELECT students_t_quantile(1, 1)$$),
'Students-t Quantile: Non-positive degree of freedom (nu) does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT students_t_quantile(-1, 1)$$) AND
check_if_raises_error($$SELECT students_t_quantile(2, 1)$$),
'Students-t Quantile: Out range [0,1] of CDF does not raise error.'
);
-- triangular_cdf
SELECT assert(
triangular_cdf(NULL, 1, 1.5, 2) IS NULL AND
triangular_cdf(1, NULL, 1.5, 2) IS NULL AND
triangular_cdf(1, 1, NULL, 2) IS NULL AND
triangular_cdf(1, 1, 1.5, NULL) IS NULL,
'Triangular CDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(triangular_cdf('NaN', 1, 1.5, 2) ) AND
isnan(triangular_cdf(1, 'NaN', 1.5, 2) ) AND
isnan(triangular_cdf(1, 1, 'NaN', 2) ) AND
isnan(triangular_cdf(1, 1, 1.5, 'NaN') ),
'Triangular CDF: Wrong handling of NaNs.'
);
SELECT assert(
relative_error(triangular_cdf(0.5, 0, 1, 2), 0.125) < 1e-5 AND
triangular_cdf(0, 0, 1, 2) = 0 AND
triangular_cdf(-1, 0, 1, 2) = 0 AND
triangular_cdf(2, 0, 1, 2) = 1 AND
triangular_cdf(3, 0, 1, 2) = 1 AND
triangular_cdf('-Inf', 0, 1, 2) = 0 AND
triangular_cdf('Inf', 0, 1, 2) = 1,
'Triangular CDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT triangular_cdf(0.5, 1, 1, 1)$$) AND
check_if_raises_error($$SELECT triangular_cdf(0.5, 2, 1, 1)$$),
'Triangular CDF: lower greater than or equal to upper does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT triangular_cdf(0.5, 0, 3, 2)$$) AND
check_if_raises_error($$SELECT triangular_cdf(0.5, 0, -1, 2)$$),
'Triangular CDF: mode out of range [lowwer, upper] does not raise error.'
);
-- triangular_pdf
SELECT assert(
triangular_pdf(NULL, 1, 1.5, 2) IS NULL AND
triangular_pdf(1, NULL, 1.5, 2) IS NULL AND
triangular_pdf(1, 1, NULL, 2) IS NULL AND
triangular_pdf(1, 1, 1.5, NULL) IS NULL,
'Triangular PDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(triangular_pdf('NaN', 1, 1.5, 2) ) AND
isnan(triangular_pdf(1, 'NaN', 1.5, 2) ) AND
isnan(triangular_pdf(1, 1, 'NaN', 2) ) AND
isnan(triangular_pdf(1, 1, 1.5, 'NaN') ),
'Triangular PDF: Wrong handling of NaNs.'
);
SELECT assert(
relative_error(triangular_pdf(0.5, 0, 1, 2), 0.5) < 1e-5 AND
triangular_pdf(0, 0, 1, 2) = 0 AND
triangular_pdf(-1, 0, 1, 2) = 0 AND
triangular_pdf(2, 0, 1, 2) = 0 AND
triangular_pdf(3, 0, 1, 2) = 0 AND
triangular_pdf('-Inf', 0, 1, 2) = 0 AND
triangular_pdf('Inf', 0, 1, 2) = 0,
'Triangular PDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT triangular_pdf(0.5, 1, 1, 1)$$) AND
check_if_raises_error($$SELECT triangular_pdf(0.5, 2, 1, 1)$$),
'Triangular PDF: lower greater than or equal to lower does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT triangular_pdf(0.5, 0, 3, 2)$$) AND
check_if_raises_error($$SELECT triangular_pdf(0.5, 0, -1, 2)$$),
'Triangular PDF: mode out of range [lowwer, upper] does not raise error.'
);
-- triangular_quantile
SELECT assert(
triangular_quantile(NULL, 1, 1.5, 2) IS NULL AND
triangular_quantile(1, NULL, 1.5, 2) IS NULL AND
triangular_quantile(1, 1, NULL, 2) IS NULL AND
triangular_quantile(1, 1, 1.5, NULL) IS NULL,
'Triangular Quantile: Wrong handling of NULLs.'
);
SELECT assert(
isnan(triangular_quantile('NaN', 1, 1.5, 2) ) AND
isnan(triangular_quantile(1, 'NaN', 1.5, 2) ) AND
isnan(triangular_quantile(1, 1, 'NaN', 2) ) AND
isnan(triangular_quantile(1, 1, 1.5, 'NaN') ),
'Triangular Quantile: Wrong handling of NaNs.'
);
SELECT assert(
relative_error(triangular_quantile(0.125, 0, 1, 2), 0.5) < 1e-5 AND
triangular_quantile(1, 0, 1, 2) = 2 AND
triangular_quantile(0, 0, 1, 2) = 0 ,
'Triangular Quantile: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT triangular_quantile(0.5, 1, 1, 1)$$) AND
check_if_raises_error($$SELECT triangular_quantile(0.5, 2, 1, 1)$$),
'Triangular Quantile: lower greater than or equal to lower does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT triangular_quantile(0.5, 0, 3, 2)$$) AND
check_if_raises_error($$SELECT triangular_quantile(0.5, 0, -1, 2)$$),
'Triangular Quantile: mode out of range [lowwer, upper] does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT triangular_quantile(-1, 1, 1, 2)$$) AND
check_if_raises_error($$SELECT triangular_quantile(2, 1, 1, 2)$$) ,
'Triangular Quantile: CDF out of range [0,1] does not raise error.'
);
-- uniform_cdf
SELECT assert(
uniform_cdf(NULL, 0, 1) IS NULL AND
uniform_cdf(1, NULL, 1) IS NULL AND
uniform_cdf(1, 1, NULL) IS NULL,
'Uniform CDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(uniform_cdf('NaN', 0, 1) ) AND
isnan(uniform_cdf(1, 'NaN', 1) ) AND
isnan(uniform_cdf(1, 1, 'NaN') ),
'Uniform CDF: Wrong handling of NaNs.'
);
SELECT assert(
uniform_cdf(-1, 0, 1) = 0 AND
uniform_cdf(1, 0, 1) = 1 AND
uniform_cdf(2, 0, 1) = 1 AND
uniform_cdf(0.5, 0, 1) = 0.5 AND
uniform_cdf('-Inf', 0, 1) = 0 AND
uniform_cdf('Inf', 0, 1) = 1,
'Uniform CDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT uniform_cdf(0.5, 1, 1)$$) AND
check_if_raises_error($$SELECT uniform_cdf(0.5, 1, 0)$$),
'Uniform CDF: empty range does not raise error.'
);
-- uniform_pdf
SELECT assert(
uniform_pdf(NULL, 0, 1) IS NULL AND
uniform_pdf(1, NULL, 1) IS NULL AND
uniform_pdf(1, 1, NULL) IS NULL,
'Uniform PDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(uniform_pdf('NaN', 0, 1) ) AND
isnan(uniform_pdf(1, 'NaN', 1) ) AND
isnan(uniform_pdf(1, 1, 'NaN') ),
'Uniform PDF: Wrong handling of NaNs.'
);
SELECT assert(
uniform_pdf(-1, 0, 1) = 0 AND
uniform_pdf(1, 0, 1) = 1 AND
uniform_pdf(2, 0, 1) = 0 AND
uniform_pdf(0.5, 0, 1) = 1 AND
uniform_pdf('-Inf', 0, 1) = 0 AND
uniform_pdf('Inf', 0, 1) = 0,
'Uniform PDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT uniform_pdf(0.5, 1, 1)$$) AND
check_if_raises_error($$SELECT uniform_pdf(0.5, 1, 0)$$),
'Uniform PDF: empty range does not raise error.'
);
-- uniform_quantile
SELECT assert(
uniform_quantile(NULL, 0, 1) IS NULL AND
uniform_quantile(1, NULL, 1) IS NULL AND
uniform_quantile(1, 1, NULL) IS NULL,
'Uniform Quantile: Wrong handling of NULLs.'
);
SELECT assert(
isnan(uniform_quantile('NaN', 0, 1) ) AND
isnan(uniform_quantile(1, 'NaN', 1) ) AND
isnan(uniform_quantile(1, 1, 'NaN') ),
'Uniform Quantile: Wrong handling of NaNs.'
);
SELECT assert(
uniform_quantile(1, 0, 1) = 1 AND
uniform_quantile(0.5, 0, 1) = 0.5,
'Uniform Quantile: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT uniform_quantle(0.5, 1, 1)$$) AND
check_if_raises_error($$SELECT uniform_quantile(0.5, 1, 0)$$),
'Uniform Quantile: empty range does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT uniform_quantile(-1, 1, 1)$$) AND
check_if_raises_error($$SELECT uniform_quantile(2, 1, 1)$$) ,
'Uniform Quantile: CDF out of range [0,1] does not raise error.'
);
-- weibull_cdf
SELECT assert(
weibull_cdf(NULL, 1, 1) IS NULL AND
weibull_cdf(1, NULL, 1) IS NULL AND
weibull_cdf(1, 1, NULL) IS NULL,
'Weibull CDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(weibull_cdf('NaN', 1, 1) ) AND
isnan(weibull_cdf(1, 'NaN', 1) ) AND
isnan(weibull_cdf(1, 1, 'NaN') ),
'Weibull CDF: Wrong handling of NaNs.'
);
SELECT assert(
relative_error(weibull_cdf(0.5, 1, 1), 0.3934693) < 1e-5 AND
weibull_cdf(0, 1, 1) = 0 AND
weibull_cdf(-1, 1, 1) = 0,
'Weibull CDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT weibull_cdf(0.5, 0, 1)$$) AND
check_if_raises_error($$SELECT weibull_cdf(0.5, 1, 0)$$) AND
check_if_raises_error($$SELECT weibull_cdf(0.5, -1, 1)$$) AND
check_if_raises_error($$SELECT weibull_cdf(0.5, 1, -1)$$) ,
'Weibull CDF: scale or shape less than or equal to 0 does not raise error.'
);
-- weibull_pdf
SELECT assert(
weibull_pdf(NULL, 1, 1) IS NULL AND
weibull_pdf(1, NULL, 1) IS NULL AND
weibull_pdf(1, 1, NULL) IS NULL,
'Weibull PDF: Wrong handling of NULLs.'
);
SELECT assert(
isnan(weibull_pdf('NaN', 1, 1) ) AND
isnan(weibull_pdf(1, 'NaN', 1) ) AND
isnan(weibull_pdf(1, 1, 'NaN') ),
'Weibull PDF: Wrong handling of NaNs.'
);
SELECT assert(
relative_error(weibull_pdf(0.5, 1, 1), 0.6065307) < 1e-5 AND
weibull_pdf(0, 1, 1) = 1 AND
weibull_pdf(0, 2, 1) = 0 AND
weibull_pdf(-1, 1, 1) = 0 AND
weibull_pdf(0, 0.5, 1) = 'Inf',
'Weibull PDF: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT weibull_pdf(0.5, 0, 1)$$) AND
check_if_raises_error($$SELECT weibull_pdf(0.5, 1, 0)$$) AND
check_if_raises_error($$SELECT weibull_pdf(0.5, -1, 1)$$) AND
check_if_raises_error($$SELECT weibull_pdf(0.5, 1, -1)$$) ,
'Weibull PDF: scale or shape less than or equal to 0 does not raise error.'
);
-- weibull_quantile
SELECT assert(
weibull_quantile(NULL, 1, 1) IS NULL AND
weibull_quantile(1, NULL, 1) IS NULL AND
weibull_quantile(1, 1, NULL) IS NULL,
'Weibull Quantile: Wrong handling of NULLs.'
);
SELECT assert(
isnan(weibull_quantile('NaN', 1, 1) ) AND
isnan(weibull_quantile(1, 'NaN', 1) ) AND
isnan(weibull_quantile(1, 1, 'NaN') ),
'Weibull Quantile: Wrong handling of NaNs.'
);
SELECT assert(
relative_error(weibull_quantile(0.5, 1, 1), 0.6931472) < 1e-5 AND
weibull_quantile(0, 1, 1) = 0 AND
weibull_quantile(1, 1, 1) = 'Inf' ,
'Weibull Quantile: Wrong handling regular values'
);
SELECT assert(
check_if_raises_error($$SELECT weibull_quantile(0.5, 0, 1)$$) AND
check_if_raises_error($$SELECT weibull_quantile(0.5, 1, 0)$$) AND
check_if_raises_error($$SELECT weibull_quantile(0.5, -1, 1)$$) AND
check_if_raises_error($$SELECT weibull_quantile(0.5, 1, -1)$$) ,
'Weibull Quantile: scale or shape less than or equal to 0 does not raise error.'
);
SELECT assert(
check_if_raises_error($$SELECT weibull_quantile(-1, 1, 1)$$) AND
check_if_raises_error($$SELECT weibull_quantile(2, 1, 1)$$) ,
'Weibull Quantile: CDF out of range [0,1] does not raise error.'
);