3 #include <hkl/hkl-sample.h>
4 #include <hkl/hkl-geometry-factory.h>
8 #ifdef HKL_TEST_SUITE_NAME
9 # undef HKL_TEST_SUITE_NAME
11 #define HKL_TEST_SUITE_NAME sample
13 #define SET_ANGLES(a, b, c, d) \
15 HklParameter *Omega, *Chi, *Phi, *Tth; \
17 Omega = (HklParameter *)(&geom->axes[0]); \
18 Chi = (HklParameter *)(&geom->axes[1]); \
19 Phi = (HklParameter *)(&geom->axes[2]); \
20 Tth = (HklParameter *)(&geom->axes[3]); \
22 hkl_parameter_set_value(Omega, a * HKL_DEGTORAD); \
23 hkl_parameter_set_value(Chi, b * HKL_DEGTORAD); \
24 hkl_parameter_set_value(Phi, c * HKL_DEGTORAD); \
25 hkl_parameter_set_value(Tth, d * HKL_DEGTORAD); \
28 HKL_TEST_SUITE_FUNC(new)
32 sample
= hkl_sample_new("test", HKL_SAMPLE_MONOCRYSTAL
);
34 hkl_sample_free(sample
);
39 HKL_TEST_SUITE_FUNC(add_reflection
)
41 HklDetector det
= {1};
44 HklSampleReflection
*ref
;
46 geom
= hkl_geometry_factory_new(HKL_GEOMETRY_EULERIAN4C_VERTICAL
);
47 sample
= hkl_sample_new("test", HKL_SAMPLE_MONOCRYSTAL
);
49 ref
= hkl_sample_add_reflection(sample
, geom
, &det
, 1, 0, 0);
51 hkl_sample_free(sample
);
52 hkl_geometry_free(geom
);
57 HKL_TEST_SUITE_FUNC(get_reflection
)
59 HklDetector det
= {1};
62 HklSampleReflection
*ref
;
63 HklSampleReflection
*ref2
;
65 geom
= hkl_geometry_factory_new(HKL_GEOMETRY_EULERIAN4C_VERTICAL
);
66 sample
= hkl_sample_new("test", HKL_SAMPLE_MONOCRYSTAL
);
68 ref
= hkl_sample_add_reflection(sample
, geom
, &det
, 1, 0, 0);
69 ref2
= hkl_sample_get_ith_reflection(sample
, 0);
70 HKL_ASSERT_POINTER_EQUAL(ref
, ref2
);
72 ref
= hkl_sample_add_reflection(sample
, geom
, &det
, -1, 0, 0);
73 ref
= hkl_sample_add_reflection(sample
, geom
, &det
, 0, 1, 0);
75 hkl_sample_free(sample
);
76 hkl_geometry_free(geom
);
81 HKL_TEST_SUITE_FUNC(del_reflection
)
83 HklDetector det
= {1};
86 HklSampleReflection
*ref
;
88 geom
= hkl_geometry_factory_new(HKL_GEOMETRY_EULERIAN4C_VERTICAL
);
89 sample
= hkl_sample_new("test", HKL_SAMPLE_MONOCRYSTAL
);
91 ref
= hkl_sample_add_reflection(sample
, geom
, &det
, 1, 0, 0);
92 hkl_sample_del_reflection(sample
, 0);
93 HKL_ASSERT_EQUAL(0, HKL_LIST_LEN(sample
->reflections
));
95 hkl_sample_free(sample
);
96 hkl_geometry_free(geom
);
101 HKL_TEST_SUITE_FUNC(compute_UB_busing_levy
)
103 HklDetector det
= {1};
106 HklSampleReflection
*ref
;
107 HklMatrix m_I
= {{{1,0,0}, {0,1,0}, {0, 0, 1}}};
108 HklMatrix m_ref
= {{{1., 0., 0.}, {0., 0., 1.}, {0.,-1., 0.}}};
110 geom
= hkl_geometry_factory_new(HKL_GEOMETRY_EULERIAN4C_VERTICAL
);
112 sample
= hkl_sample_new("test", HKL_SAMPLE_MONOCRYSTAL
);
114 SET_ANGLES(30, 0, 0, 60);
115 ref
= hkl_sample_add_reflection(sample
, geom
, &det
, 0, 0, 1);
117 SET_ANGLES(30, 0, -90, 60);
118 ref
= hkl_sample_add_reflection(sample
, geom
, &det
, -1, 0, 0);
120 hkl_sample_compute_UB_busing_levy(sample
, 0, 1);
121 HKL_ASSERT_EQUAL(HKL_TRUE
, hkl_matrix_cmp(&m_I
, &sample
->U
));
123 SET_ANGLES(30, 0, 90, 60);
124 ref
= hkl_sample_add_reflection(sample
, geom
, &det
, 1, 0, 0);
126 SET_ANGLES(30, 0, 180, 60);
127 ref
= hkl_sample_add_reflection(sample
, geom
, &det
, 0, 1, 0);
129 hkl_sample_compute_UB_busing_levy(sample
, 2, 3);
130 HKL_ASSERT_EQUAL(HKL_TRUE
, hkl_matrix_cmp(&m_ref
, &sample
->U
));
132 hkl_sample_free(sample
);
133 hkl_geometry_free(geom
);
135 return HKL_TEST_PASS
;
138 HKL_TEST_SUITE_FUNC(affine
)
140 double a
, b
, c
, alpha
, beta
, gamma
;
141 HklDetector det
= {1};
144 HklSampleReflection
*ref
;
145 HklMatrix m_ref
= {{{1., 0., 0.}, {0., 1., 0.}, {0., 0., 1.}}};
147 geom
= hkl_geometry_factory_new(HKL_GEOMETRY_EULERIAN4C_VERTICAL
);
149 sample
= hkl_sample_new("test", HKL_SAMPLE_MONOCRYSTAL
);
150 sample
->lattice
->a
->value
= 1;
151 sample
->lattice
->b
->value
= 5;
152 sample
->lattice
->c
->value
= 4;
153 sample
->lattice
->alpha
->value
= 92 * HKL_DEGTORAD
;
154 sample
->lattice
->beta
->value
= 81 * HKL_DEGTORAD
;
155 sample
->lattice
->gamma
->value
= 90 * HKL_DEGTORAD
;
157 SET_ANGLES(30, 0, 90, 60);
158 ref
= hkl_sample_add_reflection(sample
, geom
, &det
, 1, 0, 0);
160 SET_ANGLES(30, 90, 0, 60);
161 ref
= hkl_sample_add_reflection(sample
, geom
, &det
, 0, 1, 0);
163 SET_ANGLES(30, 0, 0, 60);
164 ref
= hkl_sample_add_reflection(sample
, geom
, &det
, 0, 0, 1);
166 SET_ANGLES(60, 60, 60, 60);
167 ref
= hkl_sample_add_reflection(sample
, geom
, &det
, .625, .75, -.216506350946);
169 SET_ANGLES(45, 45, 45, 60);
170 ref
= hkl_sample_add_reflection(sample
, geom
, &det
, .665975615037, .683012701892, .299950211252);
172 hkl_sample_affine(sample
);
174 a
= sample
->lattice
->a
->value
;
175 b
= sample
->lattice
->b
->value
;
176 c
= sample
->lattice
->c
->value
;
177 alpha
= sample
->lattice
->alpha
->value
;
178 beta
= sample
->lattice
->beta
->value
;
179 gamma
= sample
->lattice
->gamma
->value
;
180 HKL_ASSERT_EQUAL(HKL_TRUE
, hkl_matrix_cmp(&m_ref
, &sample
->U
));
181 HKL_ASSERT_DOUBLES_EQUAL(1.54, a
, HKL_EPSILON
);
182 HKL_ASSERT_DOUBLES_EQUAL(1.54, b
, HKL_EPSILON
);
183 HKL_ASSERT_DOUBLES_EQUAL(1.54, c
, HKL_EPSILON
);
184 HKL_ASSERT_DOUBLES_EQUAL(90 * HKL_DEGTORAD
, alpha
, HKL_EPSILON
);
185 HKL_ASSERT_DOUBLES_EQUAL(90 * HKL_DEGTORAD
, beta
, HKL_EPSILON
);
186 HKL_ASSERT_DOUBLES_EQUAL(90 * HKL_DEGTORAD
, gamma
, HKL_EPSILON
);
188 hkl_sample_free(sample
);
189 hkl_geometry_free(geom
);
191 return HKL_TEST_PASS
;
194 HKL_TEST_SUITE_FUNC(get_reflections_xxx_angle
)
196 HklDetector det
= {1};
199 HklSampleReflection
*ref
;
201 geom
= hkl_geometry_factory_new(HKL_GEOMETRY_EULERIAN4C_VERTICAL
);
203 sample
= hkl_sample_new("test", HKL_SAMPLE_MONOCRYSTAL
);
204 hkl_sample_set_lattice(sample
,
206 90*HKL_DEGTORAD
, 90*HKL_DEGTORAD
,90*HKL_DEGTORAD
);
208 SET_ANGLES(30, 0, 90, 60);
209 ref
= hkl_sample_add_reflection(sample
, geom
, &det
, 1, 0, 0);
211 SET_ANGLES(30, 90, 0, 60);
212 ref
= hkl_sample_add_reflection(sample
, geom
, &det
, 0, 1, 0);
214 SET_ANGLES(30, 0, 0, 60);
215 ref
= hkl_sample_add_reflection(sample
, geom
, &det
, 0, 0, 1);
217 SET_ANGLES(60, 60, 60, 60);
218 ref
= hkl_sample_add_reflection(sample
, geom
, &det
, .625, .75, -.216506350946);
220 SET_ANGLES(45, 45, 45, 60);
221 ref
= hkl_sample_add_reflection(sample
, geom
, &det
, .665975615037, .683012701892, .299950211252);
223 HKL_ASSERT_DOUBLES_EQUAL(90 * HKL_DEGTORAD
,
224 hkl_sample_get_reflection_theoretical_angle(sample
, 0, 1),
227 HKL_ASSERT_DOUBLES_EQUAL(90 * HKL_DEGTORAD
,
228 hkl_sample_get_reflection_mesured_angle(sample
, 0, 1),
231 HKL_ASSERT_DOUBLES_EQUAL(90 * HKL_DEGTORAD
,
232 hkl_sample_get_reflection_theoretical_angle(sample
, 1, 2),
235 HKL_ASSERT_DOUBLES_EQUAL(90 * HKL_DEGTORAD
,
236 hkl_sample_get_reflection_mesured_angle(sample
, 1, 2),
239 hkl_sample_free(sample
);
240 hkl_geometry_free(geom
);
242 return HKL_TEST_PASS
;
245 HKL_TEST_SUITE_FUNC(list_new
)
247 HklSampleList
*samples
;
249 samples
= hkl_sample_list_new();
251 hkl_sample_list_free(samples
);
253 return HKL_TEST_PASS
;
256 HKL_TEST_SUITE_FUNC(list_append_sample
)
258 HklSampleList
*samples
;
262 samples
= hkl_sample_list_new();
263 sample1
= hkl_sample_new("test1", HKL_SAMPLE_MONOCRYSTAL
);
264 sample2
= hkl_sample_new("test2", HKL_SAMPLE_MONOCRYSTAL
);
266 HKL_ASSERT_POINTER_EQUAL(sample1
, hkl_sample_list_append(samples
, sample1
));
267 HKL_ASSERT_EQUAL(0, hkl_sample_list_get_idx_from_name(samples
, "test1"));
269 HKL_ASSERT_POINTER_EQUAL(sample2
, hkl_sample_list_append(samples
, sample2
));
270 HKL_ASSERT_EQUAL(0, hkl_sample_list_get_idx_from_name(samples
, "test1"));
271 HKL_ASSERT_EQUAL(1, hkl_sample_list_get_idx_from_name(samples
, "test2"));
273 // can not have two samples with the same name.
274 HKL_ASSERT_POINTER_EQUAL(NULL
, hkl_sample_list_append(samples
, sample1
));
276 hkl_sample_list_free(samples
); // also relase sample1 and sample2
278 return HKL_TEST_PASS
;
281 HKL_TEST_SUITE_FUNC(list_select_current
)
283 HklSampleList
*samples
;
286 samples
= hkl_sample_list_new();
287 sample
= hkl_sample_new("test", HKL_SAMPLE_MONOCRYSTAL
);
289 hkl_sample_list_append(samples
, sample
);
291 HKL_ASSERT_EQUAL(HKL_SUCCESS
, hkl_sample_list_select_current(samples
, "test"));
292 HKL_ASSERT_EQUAL(HKL_FAIL
, hkl_sample_list_select_current(samples
, "tests"));
295 hkl_sample_list_free(samples
); // also release sample
297 return HKL_TEST_PASS
;
303 HKL_TEST( add_reflection
);
304 HKL_TEST( get_reflection
);
305 HKL_TEST( del_reflection
);
306 HKL_TEST( compute_UB_busing_levy
);
308 HKL_TEST( get_reflections_xxx_angle
);
310 HKL_TEST( list_new
);
311 HKL_TEST( list_append_sample
);
312 HKL_TEST( list_select_current
);