* the reflection tests passed
[hkl.git] / test / reflection_test.cpp
blobd230018235c2cc38cd3a2fd5ffd60faa579e0ab7
1 #include "reflection_test.h"
2 #include "reflection_monocrystal.h"
4 CPPUNIT_TEST_SUITE_REGISTRATION( ReflectionTest );
6 void
7 ReflectionTest::setUp(void)
9 static hkl_svector svector_X = {{1,0,0}};
11 _geometry = new hkl::eulerian4C::vertical::Geometry(1, 2, 3, 1);
12 _geometry->get_source().set_ki(&svector_X);
15 void
16 ReflectionTest::tearDown(void)
18 delete _geometry;
21 void
22 ReflectionTest::Constructor(void)
24 static hkl_svector hkl_ref = {{1,0,0}};
25 hkl_svector const * hkl;
27 hkl::Reflection * reflection = new hkl::reflection::MonoCrystal(*_geometry, &hkl_ref, true);
28 hkl = reflection->get_hkl();
29 CPPUNIT_ASSERT_EQUAL(HKL_TRUE, ::hkl_svector_cmp(&hkl_ref, hkl));
30 CPPUNIT_ASSERT_EQUAL(true, reflection->flag());
31 delete reflection;
34 void
35 ReflectionTest::Equal(void)
37 static hkl_svector hkl_ref = {{1,0,0}};
39 hkl::Reflection * reflection = new hkl::reflection::MonoCrystal(*_geometry, &hkl_ref, true);
40 CPPUNIT_ASSERT_EQUAL(*reflection, *reflection);
41 delete reflection;
44 void
45 ReflectionTest::GetSet(void)
47 static hkl_svector svector_X = {{1,0,0}};
48 static hkl_svector hkl_ref = {{1.5, 1.5, 1.5}};
49 hkl_svector const * hkl;
51 hkl::Reflection * reflection = new hkl::reflection::MonoCrystal(*_geometry, &svector_X, true);
52 reflection->set_hkl(&hkl_ref);
53 hkl = reflection->get_hkl();
54 CPPUNIT_ASSERT_EQUAL(HKL_TRUE, ::hkl_svector_cmp(&hkl_ref, hkl));
55 reflection->flag() = false;
56 CPPUNIT_ASSERT_EQUAL(false, reflection->flag());
57 delete reflection;
60 void
61 ReflectionTest::GetHKL(void)
63 static hkl_svector hkl_ref = {{1,0,0}};
64 hkl_svector const * hkl;
66 hkl::Reflection * reflection = new hkl::reflection::MonoCrystal(*_geometry, &hkl_ref, true);
67 hkl = reflection->get_hkl();
68 CPPUNIT_ASSERT_EQUAL(HKL_TRUE, ::hkl_svector_cmp(&hkl_ref, hkl));
69 delete reflection;
72 void
73 ReflectionTest::ComputeAngle(void)
75 static hkl_svector hkl1 = {{1,0,0}};
76 static hkl_svector hkl2 = {{1,1,.5}};
77 static hkl_svector hkl3 = {{1,1,0}};
78 static hkl_svector hkl4 = {{1,.5,-1}};
80 double angle;
81 const hkl::Reflection * reflection = new hkl::reflection::MonoCrystal(*_geometry, &hkl1, true);
82 const hkl::Reflection * reflection1 = new hkl::reflection::MonoCrystal(*_geometry, &hkl2, true);
84 angle = reflection->computeAngle(&hkl1).get_value();
85 CPPUNIT_ASSERT_DOUBLES_EQUAL(0., angle, HKL_EPSILON);
87 angle = reflection->computeAngle(&hkl3).get_value();
88 CPPUNIT_ASSERT_DOUBLES_EQUAL(acos(1./sqrt(2.)), angle, HKL_EPSILON);
90 angle = reflection1->computeAngle(&hkl4).get_value();
91 CPPUNIT_ASSERT_DOUBLES_EQUAL(acos(1./2.25), angle, HKL_EPSILON);
93 delete reflection;
94 delete reflection1;
97 void
98 ReflectionTest::isColinear(void)
100 static hkl_svector hkl1 = {{1,0,0}};
101 static hkl_svector hkl2 = {{2,0,0}};
102 static hkl_svector hkl3 = {{1,1,.5}};
104 hkl::Reflection * reflection = new hkl::reflection::MonoCrystal(*_geometry, &hkl1, true);
105 hkl::Reflection * reflection1 = new hkl::reflection::MonoCrystal(*_geometry, &hkl2, true);
106 hkl::Reflection * reflection2 = new hkl::reflection::MonoCrystal(*_geometry, &hkl3, true);
108 CPPUNIT_ASSERT_EQUAL(true, reflection->isColinear(*reflection));
109 CPPUNIT_ASSERT_EQUAL(true, reflection->isColinear(*reflection1));
110 CPPUNIT_ASSERT_EQUAL(false, reflection->isColinear(*reflection2));
112 delete reflection;
113 delete reflection1;
114 delete reflection2;