1+ #include " gtest/gtest.h"
2+ #include " gmock/gmock.h"
3+ #include < string>
4+ #include < cmath>
5+ #include < complex>
6+ #include " module_cell/unitcell.h"
7+ #include " module_elecstate/module_dm/test/prepare_unitcell.h"
8+ #define private public
9+ #include " module_parameter/parameter.h"
10+ #include " module_hamilt_pw/hamilt_pwdft/structure_factor.h"
11+ #undef private
12+ /* ***********************************************
13+ * unit test of class Structure_factor and
14+ ***********************************************/
15+
16+ /* *
17+ * - Tested Functions:
18+ * - Fcoef::create to create a 5 dimensional array of complex numbers
19+ * - Soc::set_fcoef to set the fcoef array
20+ * - Soc::spinor to calculate the spinor
21+ * - Soc::rot_ylm to calculate the rotation matrix
22+ * - Soc::sph_ind to calculate the m index of the spherical harmonics
23+ */
24+
25+ // compare two complex by using EXPECT_DOUBLE_EQ()
26+ InfoNonlocal::InfoNonlocal ()
27+ {
28+ }
29+ InfoNonlocal::~InfoNonlocal ()
30+ {
31+ }
32+
33+ Magnetism::Magnetism ()
34+ {
35+ }
36+ Magnetism::~Magnetism ()
37+ {
38+ }
39+
40+ class StructureFactorTest : public testing ::Test
41+ {
42+ protected:
43+ Structure_Factor SF;
44+ std::string output;
45+ ModulePW::PW_Basis* rho_basis;
46+ UnitCell* ucell;
47+ UcellTestPrepare utp = UcellTestLib[" Si" ];
48+ Parallel_Grid* pgrid;
49+ std::vector<int > nw = {13 };
50+ int nlocal = 0 ;
51+ void SetUp ()
52+ {
53+ rho_basis=new ModulePW::PW_Basis;
54+ ucell = utp.SetUcellInfo (nw, nlocal);
55+ ucell->set_iat2iwt (1 );
56+ pgrid = new Parallel_Grid;
57+ rho_basis->npw =10 ;
58+ rho_basis->gcar =new ModuleBase::Vector3<double >[10 ];
59+ // for (int ig=0;ig<rho_basis->npw;ig++)
60+ // {
61+ // rho_basis->gcar[ig]=1.0;
62+ // }
63+ }
64+ };
65+
66+ TEST_F (StructureFactorTest, set)
67+ {
68+ const ModulePW::PW_Basis* rho_basis_in;
69+ const int nbspline_in =10 ;
70+ SF.set (rho_basis_in,nbspline_in);
71+ EXPECT_EQ (nbspline_in, 10 );
72+ }
73+
74+
75+ TEST_F (StructureFactorTest, setup_structure_factor_double)
76+ {
77+ rho_basis->npw = 10 ;
78+ SF.setup_structure_factor (ucell,*pgrid,rho_basis);
79+
80+ for (int i=0 ;i< ucell->nat * (2 * rho_basis->nx + 1 );i++)
81+ {
82+ EXPECT_EQ (SF.z_eigts1 [i].real (),1 );
83+ EXPECT_EQ (SF.z_eigts1 [i].imag (),0 );
84+ }
85+
86+ for (int i=0 ;i< ucell->nat * (2 * rho_basis->ny + 1 );i++)
87+ {
88+ EXPECT_EQ (SF.z_eigts2 [i].real (),1 );
89+ EXPECT_EQ (SF.z_eigts2 [i].imag (),0 );
90+ }
91+
92+ for (int i=0 ;i< ucell->nat * (2 * rho_basis->nz + 1 );i++)
93+ {
94+ EXPECT_EQ (SF.z_eigts3 [i].real (),1 );
95+ EXPECT_EQ (SF.z_eigts3 [i].imag (),0 );
96+ }
97+ }
98+
99+ TEST_F (StructureFactorTest, setup_structure_factor_float)
100+ {
101+ PARAM.sys .has_float_data = true ;
102+ rho_basis->npw = 10 ;
103+ SF.setup_structure_factor (ucell,*pgrid,rho_basis);
104+
105+ for (int i=0 ;i< ucell->nat * (2 * rho_basis->nx + 1 );i++)
106+ {
107+ EXPECT_EQ (SF.c_eigts1 [i].real (),1 );
108+ EXPECT_EQ (SF.c_eigts1 [i].imag (),0 );
109+ }
110+
111+ for (int i=0 ;i< ucell->nat * (2 * rho_basis->ny + 1 );i++)
112+ {
113+ EXPECT_EQ (SF.c_eigts2 [i].real (),1 );
114+ EXPECT_EQ (SF.c_eigts2 [i].imag (),0 );
115+ }
116+
117+ for (int i=0 ;i< ucell->nat * (2 * rho_basis->nz + 1 );i++)
118+ {
119+ EXPECT_EQ (SF.c_eigts3 [i].real (),1 );
120+ EXPECT_EQ (SF.c_eigts3 [i].imag (),0 );
121+ }
122+ }
123+
124+ int main ()
125+ {
126+ testing::InitGoogleTest ();
127+ return RUN_ALL_TESTS ();
128+ }
0 commit comments