1 /* histogram/test_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_histogram.h>
24 #include <gsl/gsl_test.h>
25 #include <gsl/gsl_errno.h>
26 #include <gsl/gsl_ieee_utils.h>
30 static void my_error_handler (const char *reason, const char *file,
32 static int status = 0;
38 double result, lower, upper;
41 gsl_set_error_handler (&my_error_handler);
43 gsl_ieee_env_setup ();
46 h = gsl_histogram_calloc (0);
47 gsl_test (!status, "gsl_histogram_calloc traps zero-length histogram");
49 "gsl_histogram_calloc returns NULL for zero-length histogram");
52 h = gsl_histogram_calloc_uniform (0, 0.0, 1.0);
54 "gsl_histogram_calloc_uniform traps zero-length histogram");
56 "gsl_histogram_calloc_uniform returns NULL for zero-length histogram");
59 h = gsl_histogram_calloc_uniform (10, 1.0, 1.0);
61 "gsl_histogram_calloc_uniform traps equal endpoints");
63 "gsl_histogram_calloc_uniform returns NULL for equal endpoints");
66 h = gsl_histogram_calloc_uniform (10, 2.0, 1.0);
68 "gsl_histogram_calloc_uniform traps invalid range");
70 "gsl_histogram_calloc_uniform returns NULL for invalid range");
72 h = gsl_histogram_calloc_uniform (N, 0.0, 1.0);
74 status = gsl_histogram_accumulate (h, 1.0, 10.0);
75 gsl_test (status != GSL_EDOM, "gsl_histogram_accumulate traps x at xmax");
77 status = gsl_histogram_accumulate (h, 2.0, 100.0);
78 gsl_test (status != GSL_EDOM, "gsl_histogram_accumulate traps x above xmax");
80 status = gsl_histogram_accumulate (h, -1.0, 1000.0);
81 gsl_test (status != GSL_EDOM, "gsl_histogram_accumulate traps x below xmin");
83 status = gsl_histogram_increment (h, 1.0);
84 gsl_test (status != GSL_EDOM, "gsl_histogram_increment traps x at xmax");
86 status = gsl_histogram_increment (h, 2.0);
87 gsl_test (status != GSL_EDOM, "gsl_histogram_increment traps x above xmax");
89 status = gsl_histogram_increment (h, -1.0);
90 gsl_test (status != GSL_EDOM, "gsl_histogram_increment traps x below xmin");
93 result = gsl_histogram_get (h, N);
94 gsl_test (result != 0, "gsl_histogram_get traps index at n");
96 result = gsl_histogram_get (h, N + 1);
97 gsl_test (result != 0, "gsl_histogram_get traps index above n");
99 status = gsl_histogram_get_range (h, N, &lower, &upper);
100 gsl_test (status != GSL_EDOM,
101 "gsl_histogram_get_range traps index at n");
103 status = gsl_histogram_get_range (h, N + 1, &lower, &upper);
104 gsl_test (status != GSL_EDOM,
105 "gsl_histogram_get_range traps index above n");
109 gsl_histogram_find (h, -0.01, &i);
110 gsl_test (status != GSL_EDOM, "gsl_histogram_find traps x below xmin");
113 gsl_histogram_find (h, 1.0, &i);
114 gsl_test (status != GSL_EDOM, "gsl_histogram_find traps x at xmax");
117 gsl_histogram_find (h, 1.1, &i);
118 gsl_test (status != GSL_EDOM, "gsl_histogram_find traps x above xmax");
120 gsl_histogram_free (h);
125 my_error_handler (const char *reason, const char *file, int line, int err)
128 printf ("(caught [%s:%d: %s (%d)])\n", file, line, reason, err);