1 /* This file is part of the hkl library.
3 * The hkl library is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * The hkl library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with the hkl library. If not, see <http://www.gnu.org/licenses/>.
16 * Copyright (C) 2003-2016 Synchrotron SOLEIL
17 * L'Orme des Merisiers Saint-Aubin
18 * BP 48 91192 GIF-sur-YVETTE CEDEX
20 * Authors: Picca Frédéric-Emmanuel <picca@synchrotron-soleil.fr>
25 #include <tap/basic.h>
26 #include <tap/float.h>
28 #include "hkl-interval-private.h"
32 HklInterval interval_ref
= {-1, 1};
35 interval
= interval_ref
;
36 ok(FALSE
== hkl_interval_cmp(&interval_ref
, &interval
), __func__
);
39 static void plus_interval(void)
41 HklInterval i_ref
= {-2, 8};
42 HklInterval i1
= {-1, 4};
43 HklInterval i2
= {-1, 4};
45 hkl_interval_plus_interval(&i1
, &i2
);
46 ok(FALSE
== hkl_interval_cmp(&i_ref
, &i1
), __func__
);
49 static void plus_double(void)
51 HklInterval i_ref
= {-1, 9};
52 HklInterval i1
= {-2, 8};
54 hkl_interval_plus_double(&i1
, 1);
55 ok(FALSE
== hkl_interval_cmp(&i_ref
, &i1
), __func__
);
58 static void times_interval(void)
60 HklInterval i_ref
= {-9, 36};
61 HklInterval i1
= {-1, 9};
62 HklInterval i2
= {-1, 4};
64 hkl_interval_times_interval(&i1
, &i2
);
65 ok(FALSE
== hkl_interval_cmp(&i_ref
, &i1
), __func__
);
68 static void times_double(void)
70 HklInterval i_ref
= {-108, 27};
71 HklInterval i1
= {-9, 36};
73 hkl_interval_times_double(&i1
, -3);
74 ok(FALSE
== hkl_interval_cmp(&i_ref
, &i1
), __func__
);
77 static void divides_double(void)
79 HklInterval i_ref
= {-9, 36};
80 HklInterval i1
= {-108, 27};
82 hkl_interval_divides_double(&i1
, -3);
83 ok(FALSE
== hkl_interval_cmp(&i_ref
, &i1
), __func__
);
86 static void contain_zero(void)
88 HklInterval i1
= {-9, 36};
89 HklInterval i2
= {-108, -27};
91 ok(TRUE
== hkl_interval_contain_zero(&i1
), __func__
);
92 ok(FALSE
== hkl_interval_contain_zero(&i2
), __func__
);
95 static void cosinus(void)
97 /* we will test all 16 cases. */
98 /* we devide the trigonometric circle in 4 from quaters */
102 /* 3 [3*pi/2, 2*pi[ */
108 #define COS(a, b, min_ref, max_ref) do { \
109 i.min = min = a * HKL_DEGTORAD; \
110 i.max = max = b * HKL_DEGTORAD; \
111 i_ref.min = min_ref; \
112 i_ref.max = max_ref; \
113 hkl_interval_cos(&i); \
114 ok(FALSE == hkl_interval_cmp(&i_ref, &i), __func__); \
119 COS(10, 14, cos(max
), cos(min
));
121 COS(-15, 14,cos(min
), 1);
123 COS(-95, 14, cos(min
), 1);
125 COS(-215, 14, -1, 1);
129 COS(10, 100, cos(max
), cos(min
));
131 COS(-20, 100, cos(max
), 1);
133 COS(-110, 100, cos(min
), 1);
134 COS(-95, 100, cos(max
), 1);
136 COS(-190, 100,-1, 1);
140 COS(10, 190, -1, cos(min
));
142 COS(95, 190, -1, cos(min
));
143 COS(175, 190, -1, cos(max
));
145 COS(185, 190, cos(min
), cos(max
));
146 COS(-95, 190, -1, 1);
148 COS(-45, 190, -1, 1);
152 COS(-350, -30, -1, cos(min
));
153 COS(-310, -30, -1, cos(max
));
155 COS(-40, -30, cos(min
), cos(max
));
156 COS(-370, -30, -1, 1);
158 COS(-100, -30, cos(min
), cos(max
));
160 COS(-190, -30, -1, cos(max
));
163 static void acosinus(void)
165 HklInterval i_ref
= {acos(.5), acos(-.5)};
166 HklInterval i
= {-.5, .5};
168 hkl_interval_acos(&i
);
169 ok(FALSE
== hkl_interval_cmp(&i_ref
, &i
), __func__
);
172 static void sinus(void)
174 /* we will test all 16 cases. */
175 /* we devide the trigonometric circle in 4 from quaters */
179 /* 3 [3*pi/2, 2*pi[ */
184 #define SIN(a,b, min_ref, max_ref) do { \
185 i.min = min = a * HKL_DEGTORAD; \
186 i.max = max = b * HKL_DEGTORAD; \
187 i_ref.min = min_ref; \
188 i_ref.max = max_ref; \
189 hkl_interval_sin(&i); \
190 ok(FALSE == hkl_interval_cmp(&i_ref, &i), __func__); \
195 SIN(10, 14,sin(min
), sin(max
));
196 SIN(-275, 14, -1, 1);
198 SIN(-15, 14, sin(min
), sin(max
));
200 SIN(-95, 14, -1, sin(max
));
202 SIN(-185, 14, -1, sin(max
));
203 SIN(-215, 14, -1, sin(min
));
207 SIN(10, 100, sin(min
), 1);
208 SIN(85, 100, sin(max
), 1);
210 SIN(-20, 100, sin(min
), 1);
212 SIN(-110, 100, -1, 1);
214 SIN(-190, 100, -1, 1);
215 SIN(95, 100, sin(max
), sin(min
));
219 SIN(10, 190, sin(max
), 1);
221 SIN(95, 190, sin(max
), sin(min
));
223 SIN(-95, 190, -1, 1);
224 SIN(185, 190, sin(max
), sin(min
));
226 SIN(-5, 190, sin(max
), 1);
227 SIN(-45, 190, sin(min
), 1);
231 SIN(-350, -30, -1, 1);
233 SIN(-40, -30, sin(min
), sin(max
));
234 SIN(-370, -30, -1, 1);
236 SIN(-100, -30, -1, sin(max
));
237 SIN(-170, -30, -1, sin(min
));
239 SIN(-190, -30, -1, sin(min
));
242 static void asinus(void)
244 HklInterval i_ref
= {asin(-.5), asin(.5)};
245 HklInterval i
= {-.5, .5};
247 hkl_interval_asin(&i
);
248 ok(FALSE
== hkl_interval_cmp(&i_ref
, &i
), __func__
);
251 static void tangeante(void)
257 #define TAN(a,b, min_ref, max_ref) do { \
258 i.min = min = a * HKL_DEGTORAD; \
259 i.max = max = b * HKL_DEGTORAD; \
260 i_ref.min = min_ref; \
261 i_ref.max = max_ref; \
262 hkl_interval_tan(&i); \
263 ok(FALSE == hkl_interval_cmp(&i_ref, &i), __func__); \
266 TAN(-100, -89, -INFINITY
, INFINITY
);
269 // The limit case is not yet ok
270 TAN(-100, 11, 12, -90);
271 r_ref.set(-hklconstantmathinfinity, tan(current), tan(consign), hklconstantmathinfinity);
276 static void atangeante(void)
278 HklInterval i_ref
= {atan(-10.), atan(10)};
279 HklInterval i
= {-10, 10};
281 hkl_interval_atan(&i
);
282 ok(FALSE
== hkl_interval_cmp(&i_ref
, &i
), __func__
);
285 static void length(void)
287 HklInterval interval
;
291 is_double(1., hkl_interval_length(&interval
), HKL_EPSILON
, __func__
);
295 is_double(1., hkl_interval_length(&interval
), HKL_EPSILON
, __func__
);