1 /* histogram/test2d_trap.c
3 * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Brian Gough
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or (at
8 * your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include <gsl/gsl_histogram2d.h>
24 #include <gsl/gsl_test.h>
25 #include <gsl/gsl_errno.h>
26 #include <gsl/gsl_ieee_utils.h>
31 static void my_error_handler (const char *reason, const char *file,
33 static int status = 0;
39 double result, lower, upper;
42 gsl_set_error_handler (&my_error_handler);
44 gsl_ieee_env_setup ();
47 h = gsl_histogram2d_calloc (0, 10);
48 gsl_test (!status, "gsl_histogram_calloc traps zero-width histogram");
50 "gsl_histogram2d_calloc returns NULL for zero-width histogram");
54 h = gsl_histogram2d_calloc (10, 0);
55 gsl_test (!status, "gsl_histogram_calloc traps zero-length histogram");
57 "gsl_histogram2d_calloc returns NULL for zero-length histogram");
61 h = gsl_histogram2d_calloc_uniform (0, 10, 0.0, 1.0, 0.0, 1.0);
63 "gsl_histogram2d_calloc_uniform traps zero-width histogram");
65 "gsl_histogram2d_calloc_uniform returns NULL for zero-width histogram");
68 h = gsl_histogram2d_calloc_uniform (10, 0, 0.0, 1.0, 0.0, 1.0);
70 "gsl_histogram2d_calloc_uniform traps zero-length histogram");
72 "gsl_histogram2d_calloc_uniform returns NULL for zero-length histogram");
75 h = gsl_histogram2d_calloc_uniform (10, 10, 0.0, 1.0, 1.0, 1.0);
77 "gsl_histogram2d_calloc_uniform traps equal endpoints");
79 "gsl_histogram2d_calloc_uniform returns NULL for equal endpoints");
82 h = gsl_histogram2d_calloc_uniform (10, 10, 1.0, 1.0, 0.0, 1.0);
84 "gsl_histogram2d_calloc_uniform traps equal endpoints");
86 "gsl_histogram2d_calloc_uniform returns NULL for equal endpoints");
89 h = gsl_histogram2d_calloc_uniform (10, 10, 0.0, 1.0, 2.0, 1.0);
91 "gsl_histogram2d_calloc_uniform traps invalid range");
93 "gsl_histogram2d_calloc_uniform returns NULL for invalid range");
96 h = gsl_histogram2d_calloc_uniform (10, 10, 2.0, 1.0, 0.0, 1.0);
98 "gsl_histogram2d_calloc_uniform traps invalid range");
100 "gsl_histogram2d_calloc_uniform returns NULL for invalid range");
102 h = gsl_histogram2d_calloc_uniform (N, M, 0.0, 1.0, 0.0, 1.0);
104 status = gsl_histogram2d_accumulate (h, 1.0, 0.0, 10.0);
105 gsl_test (status != GSL_EDOM, "gsl_histogram2d_accumulate traps x at xmax");
107 status = gsl_histogram2d_accumulate (h, 2.0, 0.0, 100.0);
108 gsl_test (status != GSL_EDOM, "gsl_histogram2d_accumulate traps x above xmax");
110 status = gsl_histogram2d_accumulate (h, -1.0, 0.0, 1000.0);
111 gsl_test (status != GSL_EDOM, "gsl_histogram2d_accumulate traps x below xmin");
113 status = gsl_histogram2d_accumulate (h, 0.0, 1.0, 10.0);
114 gsl_test (status != GSL_EDOM, "gsl_histogram2d_accumulate traps y at ymax");
116 status = gsl_histogram2d_accumulate (h, 0.0, 2.0, 100.0);
117 gsl_test (status != GSL_EDOM, "gsl_histogram2d_accumulate traps y above ymax");
119 status = gsl_histogram2d_accumulate (h, 0.0, -1.0, 1000.0);
120 gsl_test (status != GSL_EDOM, "gsl_histogram2d_accumulate traps y below ymin");
123 status = gsl_histogram2d_increment (h, 1.0, 0.0);
124 gsl_test (status != GSL_EDOM, "gsl_histogram2d_increment traps x at xmax");
126 status = gsl_histogram2d_increment (h, 2.0, 0.0);
127 gsl_test (status != GSL_EDOM, "gsl_histogram2d_increment traps x above xmax");
129 status = gsl_histogram2d_increment (h, -1.0, 0.0);
130 gsl_test (status != GSL_EDOM, "gsl_histogram2d_increment traps x below xmin");
133 status = gsl_histogram2d_increment (h, 0.0, 1.0);
134 gsl_test (status != GSL_EDOM, "gsl_histogram2d_increment traps y at ymax");
136 status = gsl_histogram2d_increment (h, 0.0, 2.0);
137 gsl_test (status != GSL_EDOM, "gsl_histogram2d_increment traps y above ymax");
139 status = gsl_histogram2d_increment (h, 0.0, -1.0);
140 gsl_test (status != GSL_EDOM, "gsl_histogram2d_increment traps y below ymin");
143 result = gsl_histogram2d_get (h, N, 0);
144 gsl_test (result != 0, "gsl_histogram2d_get traps x index at nx");
146 result = gsl_histogram2d_get (h, N + 1, 0);
147 gsl_test (result != 0, "gsl_histogram2d_get traps x index above nx");
149 result = gsl_histogram2d_get (h, 0, M);
150 gsl_test (result != 0, "gsl_histogram2d_get traps y index at ny");
152 result = gsl_histogram2d_get (h, 0, M + 1);
153 gsl_test (result != 0, "gsl_histogram2d_get traps y index above ny");
156 status = gsl_histogram2d_get_xrange (h, N, &lower, &upper);
157 gsl_test (status != GSL_EDOM, "gsl_histogram2d_get_xrange traps index at nx");
159 status = gsl_histogram2d_get_xrange (h, N + 1, &lower, &upper);
160 gsl_test (status != GSL_EDOM, "gsl_histogram2d_get_xrange traps index above nx");
162 status = gsl_histogram2d_get_yrange (h, M, &lower, &upper);
163 gsl_test (status != GSL_EDOM, "gsl_histogram2d_get_yrange traps index at ny");
165 status = gsl_histogram2d_get_yrange (h, M + 1, &lower, &upper);
166 gsl_test (status != GSL_EDOM, "gsl_histogram2d_get_yrange traps index above ny");
169 gsl_histogram2d_find (h, -0.01, 0.0, &i, &j);
170 gsl_test (status != GSL_EDOM, "gsl_histogram2d_find traps x below xmin");
173 gsl_histogram2d_find (h, 1.0, 0.0, &i, &j);
174 gsl_test (status != GSL_EDOM, "gsl_histogram2d_find traps x at xmax");
177 gsl_histogram2d_find (h, 1.1, 0.0, &i, &j);
178 gsl_test (status != GSL_EDOM, "gsl_histogram2d_find traps x above xmax");
182 gsl_histogram2d_find (h, 0.0, -0.01, &i, &j);
183 gsl_test (status != GSL_EDOM, "gsl_histogram2d_find traps y below ymin");
186 gsl_histogram2d_find (h, 0.0, 1.0, &i, &j);
187 gsl_test (status != GSL_EDOM, "gsl_histogram2d_find traps y at ymax");
190 gsl_histogram2d_find (h, 0.0, 1.1, &i, &j);
191 gsl_test (status != GSL_EDOM, "gsl_histogram2d_find traps y above ymax");
193 gsl_histogram2d_free (h);
198 my_error_handler (const char *reason, const char *file, int line, int err)
201 printf ("(caught [%s:%d: %s (%d)])\n", file, line, reason, err);