post release commit
[hkl.git] / tests / hkl-axis-t.c
blob00629d3336616bfbcdf51a83f3610d77aa74729c
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>
22 #include "hkl.h"
23 #include <tap/basic.h>
24 #include <tap/float.h>
25 #include <tap/hkl-tap.h>
27 #include <hkl-axis-private.h>
29 static void new(void)
31 HklParameter *axis;
32 static HklVector v = {{1, 0, 0}};
33 double min, max;
34 axis = hkl_parameter_new_axis("omega", &v, &hkl_unit_angle_deg);
36 is_string("omega", hkl_parameter_name_get(axis), __func__);
37 hkl_parameter_min_max_get(axis, &min, &max, HKL_UNIT_DEFAULT);
38 is_double(-M_PI, min, HKL_EPSILON, __func__);
39 is_double(M_PI, max, HKL_EPSILON, __func__);
40 is_double(0., hkl_parameter_value_get(axis, HKL_UNIT_DEFAULT), HKL_EPSILON, __func__);
41 ok(TRUE == hkl_parameter_fit_get(axis), __func__);
43 hkl_parameter_free(axis);
46 static void get_quaternions(void)
48 static HklVector v_ref = {{1, 0, 0}};
49 static HklQuaternion q1_ref = {{1, 0, 0, 0}};
50 static HklQuaternion q2_ref = {{M_SQRT1_2, -M_SQRT1_2, 0, 0}};
51 HklParameter *axis;
53 axis = hkl_parameter_new_axis("omega", &v_ref, &hkl_unit_angle_deg);
55 is_quaternion(&q1_ref, hkl_parameter_quaternion_get(axis), __func__);
57 ok(TRUE == hkl_parameter_value_set(axis, -M_PI_2, HKL_UNIT_DEFAULT, NULL), __func__);
58 is_quaternion(&q2_ref, hkl_parameter_quaternion_get(axis), __func__);
60 hkl_parameter_free(axis);
63 static void copy(void)
65 static HklVector v = {{1, 0, 0}};
66 static HklQuaternion q_ref = {{M_SQRT1_2, -M_SQRT1_2, 0, 0}};
67 HklParameter *axis;
68 HklParameter *copy;
69 double min, max;
72 axis = hkl_parameter_new_axis("omega", &v, &hkl_unit_angle_deg);
73 ok(TRUE == hkl_parameter_value_set(axis, -M_PI_2, HKL_UNIT_DEFAULT, NULL), __func__);
75 copy = hkl_parameter_new_copy(axis);
77 is_string("omega", hkl_parameter_name_get(copy), __func__);
78 hkl_parameter_min_max_get(copy, &min, &max, HKL_UNIT_DEFAULT);
79 is_double(-M_PI, min, HKL_EPSILON, __func__);
80 is_double(M_PI, max, HKL_EPSILON, __func__);
81 is_double(-M_PI_2, hkl_parameter_value_get(copy, HKL_UNIT_DEFAULT), HKL_EPSILON, __func__);
82 ok(TRUE == hkl_parameter_fit_get(copy), __func__);
84 is_quaternion(&q_ref, hkl_parameter_quaternion_get(copy), __func__);
86 hkl_parameter_free(axis);
87 hkl_parameter_free(copy);
90 static void is_valid(void)
92 static HklVector v = {{1, 0, 0}};
93 HklParameter *axis1;
95 axis1 = hkl_parameter_new_axis("omega", &v, &hkl_unit_angle_deg);
97 ok(TRUE == hkl_parameter_value_set(axis1, 45, HKL_UNIT_USER, NULL), __func__);
98 ok(TRUE == hkl_parameter_is_valid(axis1), __func__);
100 /* change the range of axis1 */
101 ok(TRUE == hkl_parameter_min_max_set(axis1, -270, 0, HKL_UNIT_USER, NULL), __func__);
102 ok(FALSE == hkl_parameter_is_valid(axis1), __func__);
104 ok(TRUE == hkl_parameter_value_set(axis1, -45, HKL_UNIT_USER, NULL), __func__);
105 ok(TRUE == hkl_parameter_is_valid(axis1), __func__);
107 ok(TRUE == hkl_parameter_min_max_set(axis1, 350, 450, HKL_UNIT_USER, NULL), __func__);
108 ok(TRUE == hkl_parameter_value_set(axis1, 45, HKL_UNIT_USER, NULL), __func__);
109 ok(TRUE == hkl_parameter_is_valid(axis1), __func__);
110 ok(TRUE == hkl_parameter_value_set(axis1, -45, HKL_UNIT_USER, NULL), __func__);
111 ok(FALSE == hkl_parameter_is_valid(axis1), __func__);
113 ok(TRUE == hkl_parameter_min_max_set(axis1, -10, 90, HKL_UNIT_USER, NULL), __func__);
114 ok(TRUE == hkl_parameter_value_set(axis1, 405, HKL_UNIT_USER, NULL), __func__);
115 ok(TRUE == hkl_parameter_is_valid(axis1), __func__);
116 ok(TRUE == hkl_parameter_value_set(axis1, -405, HKL_UNIT_USER, NULL), __func__);
117 ok(FALSE == hkl_parameter_is_valid(axis1), __func__);
119 hkl_parameter_free(axis1);
122 static void set_value_smallest_in_range(void)
124 HklParameter *axis;
125 static HklVector v = {{1, 0, 0}};
127 axis = hkl_parameter_new_axis("omega", &v, &hkl_unit_angle_deg);
129 ok(TRUE == hkl_parameter_min_max_set(axis, -190, 190, HKL_UNIT_USER, NULL), __func__);
131 ok(TRUE == hkl_parameter_value_set(axis, 185, HKL_UNIT_USER, NULL), __func__);
132 hkl_parameter_value_set_smallest_in_range(axis);
133 is_double(-175., hkl_parameter_value_get(axis, HKL_UNIT_USER), HKL_EPSILON, __func__);
135 ok(TRUE == hkl_parameter_value_set(axis, 545, HKL_UNIT_USER, NULL), __func__);
136 hkl_parameter_value_set_smallest_in_range(axis);
137 is_double(-175., hkl_parameter_value_get(axis, HKL_UNIT_USER), HKL_EPSILON, __func__);
139 ok(TRUE == hkl_parameter_value_set(axis, -185, HKL_UNIT_USER, NULL), __func__);
140 hkl_parameter_value_set_smallest_in_range(axis);
141 is_double(-185., hkl_parameter_value_get(axis, HKL_UNIT_USER), HKL_EPSILON, __func__);
143 ok(TRUE == hkl_parameter_value_set(axis, 175, HKL_UNIT_USER, NULL), __func__);
144 hkl_parameter_value_set_smallest_in_range(axis);
145 is_double(-185., hkl_parameter_value_get(axis, HKL_UNIT_USER), HKL_EPSILON, __func__);
147 ok(TRUE == hkl_parameter_value_set(axis, 190, HKL_UNIT_USER, NULL), __func__);
148 hkl_parameter_value_set_smallest_in_range(axis);
149 is_double(-170., hkl_parameter_value_get(axis, HKL_UNIT_USER), HKL_EPSILON, __func__);
151 ok(TRUE == hkl_parameter_value_set(axis, -190, HKL_UNIT_USER, NULL), __func__);
152 hkl_parameter_value_set_smallest_in_range(axis);
153 is_double(-190., hkl_parameter_value_get(axis, HKL_UNIT_USER), HKL_EPSILON, __func__);
155 hkl_parameter_free(axis);
158 static void get_value_closest(void)
160 HklParameter *axis1, *axis2;
161 static HklVector v = {{1, 0, 0}};
163 axis1 = hkl_parameter_new_axis("omega", &v, &hkl_unit_angle_deg);
164 axis2 = hkl_parameter_new_axis("omega", &v, &hkl_unit_angle_deg);
166 ok(TRUE == hkl_parameter_value_set(axis1, 0, HKL_UNIT_USER, NULL), __func__);
167 ok(TRUE == hkl_parameter_value_set(axis2, 0, HKL_UNIT_USER, NULL), __func__);
168 is_double(0., hkl_parameter_value_get_closest(axis1,
169 axis2),
170 HKL_EPSILON, __func__);
172 /* change the range of axis1 */
173 ok(TRUE == hkl_parameter_min_max_set(axis1, -270, 180, HKL_UNIT_USER, NULL), __func__);
174 ok(TRUE == hkl_parameter_value_set(axis1, 100, HKL_UNIT_USER, NULL), __func__);
176 ok(TRUE == hkl_parameter_value_set(axis2, -75, HKL_UNIT_USER, NULL), __func__);
177 is_double(100 * HKL_DEGTORAD, hkl_parameter_value_get_closest(axis1,
178 axis2),
179 HKL_EPSILON, __func__);
181 ok(TRUE == hkl_parameter_value_set(axis2, -85, HKL_UNIT_USER, NULL), __func__);
182 is_double(-260 * HKL_DEGTORAD, hkl_parameter_value_get_closest(axis1,
183 axis2),
184 HKL_EPSILON, __func__);
186 hkl_parameter_free(axis1);
187 hkl_parameter_free(axis2);
190 int main(void)
192 plan(53);
194 new();
195 get_quaternions();
196 copy();
197 is_valid();
198 set_value_smallest_in_range();
199 get_value_closest();
201 return 0;