Added script front-end for primer-design code
[htsworkflow.git] / htswanalysis / MACS / lib / gsl / gsl-1.11 / histogram / test2d_trap.c
1 /* histogram/test2d_trap.c
2  * 
3  * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Brian Gough
4  * 
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.
9  * 
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.
14  * 
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.
18  */
19
20 #include <config.h>
21 #include <stdlib.h>
22 #include <stdio.h>
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>
27
28 #define N 107
29 #define M 239
30
31 static void my_error_handler (const char *reason, const char *file,
32                               int line, int err);
33 static int status = 0;
34
35 void
36 test2d_trap (void)
37 {
38   gsl_histogram2d *h;
39   double result, lower, upper;
40   size_t i, j;
41
42   gsl_set_error_handler (&my_error_handler);
43
44   gsl_ieee_env_setup ();
45
46   status = 0;
47   h = gsl_histogram2d_calloc (0, 10);
48   gsl_test (!status, "gsl_histogram_calloc traps zero-width histogram");
49   gsl_test (h != 0,
50             "gsl_histogram2d_calloc returns NULL for zero-width histogram");
51
52
53   status = 0;
54   h = gsl_histogram2d_calloc (10, 0);
55   gsl_test (!status, "gsl_histogram_calloc traps zero-length histogram");
56   gsl_test (h != 0,
57             "gsl_histogram2d_calloc returns NULL for zero-length histogram");
58
59
60   status = 0;
61   h = gsl_histogram2d_calloc_uniform (0, 10, 0.0, 1.0, 0.0, 1.0);
62   gsl_test (!status,
63             "gsl_histogram2d_calloc_uniform traps zero-width histogram");
64   gsl_test (h != 0,
65     "gsl_histogram2d_calloc_uniform returns NULL for zero-width histogram");
66
67   status = 0;
68   h = gsl_histogram2d_calloc_uniform (10, 0, 0.0, 1.0, 0.0, 1.0);
69   gsl_test (!status,
70             "gsl_histogram2d_calloc_uniform traps zero-length histogram");
71   gsl_test (h != 0,
72    "gsl_histogram2d_calloc_uniform returns NULL for zero-length histogram");
73
74   status = 0;
75   h = gsl_histogram2d_calloc_uniform (10, 10, 0.0, 1.0, 1.0, 1.0);
76   gsl_test (!status,
77             "gsl_histogram2d_calloc_uniform traps equal endpoints");
78   gsl_test (h != 0,
79          "gsl_histogram2d_calloc_uniform returns NULL for equal endpoints");
80
81   status = 0;
82   h = gsl_histogram2d_calloc_uniform (10, 10, 1.0, 1.0, 0.0, 1.0);
83   gsl_test (!status,
84             "gsl_histogram2d_calloc_uniform traps equal endpoints");
85   gsl_test (h != 0,
86          "gsl_histogram2d_calloc_uniform returns NULL for equal endpoints");
87
88   status = 0;
89   h = gsl_histogram2d_calloc_uniform (10, 10, 0.0, 1.0, 2.0, 1.0);
90   gsl_test (!status,
91             "gsl_histogram2d_calloc_uniform traps invalid range");
92   gsl_test (h != 0,
93             "gsl_histogram2d_calloc_uniform returns NULL for invalid range");
94
95   status = 0;
96   h = gsl_histogram2d_calloc_uniform (10, 10, 2.0, 1.0, 0.0, 1.0);
97   gsl_test (!status,
98             "gsl_histogram2d_calloc_uniform traps invalid range");
99   gsl_test (h != 0,
100             "gsl_histogram2d_calloc_uniform returns NULL for invalid range");
101
102   h = gsl_histogram2d_calloc_uniform (N, M, 0.0, 1.0, 0.0, 1.0);
103
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");
106
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");
109
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");
112
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");
115
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");
118
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");
121
122
123   status = gsl_histogram2d_increment (h, 1.0, 0.0);
124   gsl_test (status != GSL_EDOM, "gsl_histogram2d_increment traps x at xmax");
125
126   status = gsl_histogram2d_increment (h, 2.0, 0.0);
127   gsl_test (status != GSL_EDOM, "gsl_histogram2d_increment traps x above xmax");
128
129   status = gsl_histogram2d_increment (h, -1.0, 0.0);
130   gsl_test (status != GSL_EDOM, "gsl_histogram2d_increment traps x below xmin");
131
132
133   status = gsl_histogram2d_increment (h, 0.0, 1.0);
134   gsl_test (status != GSL_EDOM, "gsl_histogram2d_increment traps y at ymax");
135
136   status = gsl_histogram2d_increment (h, 0.0, 2.0);
137   gsl_test (status != GSL_EDOM, "gsl_histogram2d_increment traps y above ymax");
138
139   status = gsl_histogram2d_increment (h, 0.0, -1.0);
140   gsl_test (status != GSL_EDOM, "gsl_histogram2d_increment traps y below ymin");
141
142
143   result = gsl_histogram2d_get (h, N, 0);
144   gsl_test (result != 0, "gsl_histogram2d_get traps x index at nx");
145
146   result = gsl_histogram2d_get (h, N + 1, 0);
147   gsl_test (result != 0, "gsl_histogram2d_get traps x index above nx");
148
149   result = gsl_histogram2d_get (h, 0, M);
150   gsl_test (result != 0, "gsl_histogram2d_get traps y index at ny");
151
152   result = gsl_histogram2d_get (h, 0, M + 1);
153   gsl_test (result != 0, "gsl_histogram2d_get traps y index above ny");
154
155
156   status = gsl_histogram2d_get_xrange (h, N, &lower, &upper);
157   gsl_test (status != GSL_EDOM, "gsl_histogram2d_get_xrange traps index at nx");
158
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");
161
162   status = gsl_histogram2d_get_yrange (h, M, &lower, &upper);
163   gsl_test (status != GSL_EDOM, "gsl_histogram2d_get_yrange traps index at ny");
164
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");
167
168   status = 0;
169   gsl_histogram2d_find (h, -0.01, 0.0, &i, &j);
170   gsl_test (status != GSL_EDOM, "gsl_histogram2d_find traps x below xmin");
171
172   status = 0;
173   gsl_histogram2d_find (h, 1.0, 0.0, &i, &j);
174   gsl_test (status != GSL_EDOM, "gsl_histogram2d_find traps x at xmax");
175
176   status = 0;
177   gsl_histogram2d_find (h, 1.1, 0.0, &i, &j);
178   gsl_test (status != GSL_EDOM, "gsl_histogram2d_find traps x above xmax");
179
180
181   status = 0;
182   gsl_histogram2d_find (h, 0.0, -0.01, &i, &j);
183   gsl_test (status != GSL_EDOM, "gsl_histogram2d_find traps y below ymin");
184
185   status = 0;
186   gsl_histogram2d_find (h, 0.0, 1.0, &i, &j);
187   gsl_test (status != GSL_EDOM, "gsl_histogram2d_find traps y at ymax");
188
189   status = 0;
190   gsl_histogram2d_find (h, 0.0, 1.1, &i, &j);
191   gsl_test (status != GSL_EDOM, "gsl_histogram2d_find traps y above ymax");
192
193   gsl_histogram2d_free (h);
194 }
195
196
197 static void
198 my_error_handler (const char *reason, const char *file, int line, int err)
199 {
200   if (0)
201     printf ("(caught [%s:%d: %s (%d)])\n", file, line, reason, err);
202   status = 1;
203 }