29#include "hdrl_random.h"
44cpl_error_code test_basic(
void)
46 hdrl_random_state * state = hdrl_random_state_new(1, NULL);
47 const size_t N = 10000;
49 for (
size_t i = 0; i < N; i++) {
50 int64_t r = hdrl_random_uniform_int64(state, 0, 100);
52 r = hdrl_random_uniform_int64(state, 1000, 2000);
56 r = hdrl_random_uniform_int64(state, -(1ll<<55ll), 1ll<<55ll);
57 cpl_test_lt(r, (1ll<<55ll) + 1);
58 cpl_test_lt(-(1ll<<55ll) + 1ll, r);
60 r = hdrl_random_uniform_int64(state, -(1ll<<55ll), 0);
62 cpl_test_lt(-(1ll<<55ll) + 1ll, r);
64 double rd = hdrl_random_uniform_double(state, -5., 2.);
65 cpl_test_lt(rd, nextafter(2., 1));
66 cpl_test_lt(nextafter(-5., -1), rd);
71 for (
size_t i = 0; i < N; i++) {
72 buf[i] = (int)hdrl_random_poisson(state, 300.);
73 bufd[i] = hdrl_random_normal(state, 3.5, 1.5);
75 cpl_image * iimg = cpl_image_wrap_int(N, 1, buf);
76 cpl_image * dimg = cpl_image_wrap_double(N, 1, bufd);
77 cpl_test_abs(cpl_image_get_mean(iimg), 300, 1);
78 cpl_test_abs(cpl_image_get_stdev(iimg), sqrt(300), 0.5);
79 cpl_test_abs(cpl_image_get_mean(dimg), 3.5, 0.1);
80 cpl_test_abs(cpl_image_get_stdev(dimg), 1.5, 0.1);
82 cpl_image_unwrap(iimg);
83 cpl_image_unwrap(dimg);
84 hdrl_random_state_delete(state);
86 uint64_t seed[2] = {1342, 232};
87 state = hdrl_random_state_new(1, seed);
88 hdrl_random_state_delete(state);
90 return cpl_error_get_code();
101 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
105 return cpl_test_end(0);