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>
23 #include <tap/basic.h>
24 #include <tap/float.h>
25 #include <tap/hkl-tap.h>
27 /* use these private methods */
28 HklParameter
*hkl_parameter_new_axis(const char *, const HklVector
*axis_v
);
29 int hkl_parameter_is_valid(const HklParameter
*parameter
);
30 void hkl_parameter_value_set_smallest_in_range(HklParameter
*parameter
);
31 double hkl_parameter_value_get_closest(HklParameter
*parameter
, HklParameter
*ref
);
36 static HklVector v
= {{1, 0, 0}};
39 axis
= hkl_parameter_new_axis("omega", &v
);
41 is_string("omega", hkl_parameter_name_get(axis
), __func__
);
42 hkl_parameter_min_max_get(axis
, &min
, &max
, HKL_UNIT_DEFAULT
);
43 is_double(-M_PI
, min
, HKL_EPSILON
, __func__
);
44 is_double(M_PI
, max
, HKL_EPSILON
, __func__
);
45 is_double(0., hkl_parameter_value_get(axis
, HKL_UNIT_DEFAULT
), HKL_EPSILON
, __func__
);
46 ok(TRUE
== hkl_parameter_fit_get(axis
), __func__
);
48 hkl_parameter_free(axis
);
51 static void get_quaternions(void)
53 static HklVector v_ref
= {{1, 0, 0}};
54 static HklQuaternion q1_ref
= {{1, 0, 0, 0}};
55 static HklQuaternion q2_ref
= {{M_SQRT1_2
, -M_SQRT1_2
, 0, 0}};
58 axis
= hkl_parameter_new_axis("omega", &v_ref
);
60 is_quaternion(&q1_ref
, hkl_parameter_quaternion_get(axis
), __func__
);
62 ok(TRUE
== hkl_parameter_value_set(axis
, -M_PI_2
, HKL_UNIT_DEFAULT
, NULL
), __func__
);
63 is_quaternion(&q2_ref
, hkl_parameter_quaternion_get(axis
), __func__
);
65 hkl_parameter_free(axis
);
68 static void copy(void)
70 static HklVector v
= {{1, 0, 0}};
71 static HklQuaternion q_ref
= {{M_SQRT1_2
, -M_SQRT1_2
, 0, 0}};
77 axis
= hkl_parameter_new_axis("omega", &v
);
78 ok(TRUE
== hkl_parameter_value_set(axis
, -M_PI_2
, HKL_UNIT_DEFAULT
, NULL
), __func__
);
80 copy
= hkl_parameter_new_copy(axis
);
82 is_string("omega", hkl_parameter_name_get(copy
), __func__
);
83 hkl_parameter_min_max_get(copy
, &min
, &max
, HKL_UNIT_DEFAULT
);
84 is_double(-M_PI
, min
, HKL_EPSILON
, __func__
);
85 is_double(M_PI
, max
, HKL_EPSILON
, __func__
);
86 is_double(-M_PI_2
, hkl_parameter_value_get(copy
, HKL_UNIT_DEFAULT
), HKL_EPSILON
, __func__
);
87 ok(TRUE
== hkl_parameter_fit_get(copy
), __func__
);
89 is_quaternion(&q_ref
, hkl_parameter_quaternion_get(copy
), __func__
);
91 hkl_parameter_free(axis
);
92 hkl_parameter_free(copy
);
95 static void is_valid(void)
97 static HklVector v
= {{1, 0, 0}};
100 axis1
= hkl_parameter_new_axis("omega", &v
);
102 ok(TRUE
== hkl_parameter_value_set(axis1
, 45, HKL_UNIT_USER
, NULL
), __func__
);
103 ok(TRUE
== hkl_parameter_is_valid(axis1
), __func__
);
105 /* change the range of axis1 */
106 ok(TRUE
== hkl_parameter_min_max_set(axis1
, -270, 0, HKL_UNIT_USER
, NULL
), __func__
);
107 ok(FALSE
== hkl_parameter_is_valid(axis1
), __func__
);
109 ok(TRUE
== hkl_parameter_value_set(axis1
, -45, HKL_UNIT_USER
, NULL
), __func__
);
110 ok(TRUE
== hkl_parameter_is_valid(axis1
), __func__
);
112 ok(TRUE
== hkl_parameter_min_max_set(axis1
, 350, 450, HKL_UNIT_USER
, NULL
), __func__
);
113 ok(TRUE
== hkl_parameter_value_set(axis1
, 45, HKL_UNIT_USER
, NULL
), __func__
);
114 ok(TRUE
== hkl_parameter_is_valid(axis1
), __func__
);
115 ok(TRUE
== hkl_parameter_value_set(axis1
, -45, HKL_UNIT_USER
, NULL
), __func__
);
116 ok(FALSE
== hkl_parameter_is_valid(axis1
), __func__
);
118 ok(TRUE
== hkl_parameter_min_max_set(axis1
, -10, 90, HKL_UNIT_USER
, NULL
), __func__
);
119 ok(TRUE
== hkl_parameter_value_set(axis1
, 405, HKL_UNIT_USER
, NULL
), __func__
);
120 ok(TRUE
== hkl_parameter_is_valid(axis1
), __func__
);
121 ok(TRUE
== hkl_parameter_value_set(axis1
, -405, HKL_UNIT_USER
, NULL
), __func__
);
122 ok(FALSE
== hkl_parameter_is_valid(axis1
), __func__
);
124 hkl_parameter_free(axis1
);
127 static void set_value_smallest_in_range(void)
130 static HklVector v
= {{1, 0, 0}};
132 axis
= hkl_parameter_new_axis("omega", &v
);
134 ok(TRUE
== hkl_parameter_min_max_set(axis
, -190, 190, HKL_UNIT_USER
, NULL
), __func__
);
136 ok(TRUE
== hkl_parameter_value_set(axis
, 185, HKL_UNIT_USER
, NULL
), __func__
);
137 hkl_parameter_value_set_smallest_in_range(axis
);
138 is_double(-175., hkl_parameter_value_get(axis
, HKL_UNIT_USER
), HKL_EPSILON
, __func__
);
140 ok(TRUE
== hkl_parameter_value_set(axis
, 545, HKL_UNIT_USER
, NULL
), __func__
);
141 hkl_parameter_value_set_smallest_in_range(axis
);
142 is_double(-175., hkl_parameter_value_get(axis
, HKL_UNIT_USER
), HKL_EPSILON
, __func__
);
144 ok(TRUE
== hkl_parameter_value_set(axis
, -185, HKL_UNIT_USER
, NULL
), __func__
);
145 hkl_parameter_value_set_smallest_in_range(axis
);
146 is_double(-185., hkl_parameter_value_get(axis
, HKL_UNIT_USER
), HKL_EPSILON
, __func__
);
148 ok(TRUE
== hkl_parameter_value_set(axis
, 175, HKL_UNIT_USER
, NULL
), __func__
);
149 hkl_parameter_value_set_smallest_in_range(axis
);
150 is_double(-185., hkl_parameter_value_get(axis
, HKL_UNIT_USER
), HKL_EPSILON
, __func__
);
152 ok(TRUE
== hkl_parameter_value_set(axis
, 190, HKL_UNIT_USER
, NULL
), __func__
);
153 hkl_parameter_value_set_smallest_in_range(axis
);
154 is_double(-170., hkl_parameter_value_get(axis
, HKL_UNIT_USER
), HKL_EPSILON
, __func__
);
156 ok(TRUE
== hkl_parameter_value_set(axis
, -190, HKL_UNIT_USER
, NULL
), __func__
);
157 hkl_parameter_value_set_smallest_in_range(axis
);
158 is_double(-190., hkl_parameter_value_get(axis
, HKL_UNIT_USER
), HKL_EPSILON
, __func__
);
160 hkl_parameter_free(axis
);
163 static void get_value_closest(void)
165 HklParameter
*axis1
, *axis2
;
166 static HklVector v
= {{1, 0, 0}};
168 axis1
= hkl_parameter_new_axis("omega", &v
);
169 axis2
= hkl_parameter_new_axis("omega", &v
);
171 ok(TRUE
== hkl_parameter_value_set(axis1
, 0, HKL_UNIT_USER
, NULL
), __func__
);
172 ok(TRUE
== hkl_parameter_value_set(axis2
, 0, HKL_UNIT_USER
, NULL
), __func__
);
173 is_double(0., hkl_parameter_value_get_closest(axis1
,
175 HKL_EPSILON
, __func__
);
177 /* change the range of axis1 */
178 ok(TRUE
== hkl_parameter_min_max_set(axis1
, -270, 180, HKL_UNIT_USER
, NULL
), __func__
);
179 ok(TRUE
== hkl_parameter_value_set(axis1
, 100, HKL_UNIT_USER
, NULL
), __func__
);
181 ok(TRUE
== hkl_parameter_value_set(axis2
, -75, HKL_UNIT_USER
, NULL
), __func__
);
182 is_double(100 * HKL_DEGTORAD
, hkl_parameter_value_get_closest(axis1
,
184 HKL_EPSILON
, __func__
);
186 ok(TRUE
== hkl_parameter_value_set(axis2
, -85, HKL_UNIT_USER
, NULL
), __func__
);
187 is_double(-260 * HKL_DEGTORAD
, hkl_parameter_value_get_closest(axis1
,
189 HKL_EPSILON
, __func__
);
191 hkl_parameter_free(axis1
);
192 hkl_parameter_free(axis2
);
203 set_value_smallest_in_range();