Skip to content

Commit 1cab52c

Browse files
authored
UT of MemAvalibale,TEST_LEVEL and Tamplate of V*M (#2004)
1 parent 900e050 commit 1cab52c

File tree

4 files changed

+80
-3
lines changed

4 files changed

+80
-3
lines changed

source/module_base/global_function.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,8 @@ void DONE(std::ofstream &ofs, const std::string &description, const bool only_ra
112112
// NAME : TEST_LEVEL
113113
// control the test_level
114114
//==========================================================
115-
void TEST_LEVEL(const std::string &name)
115+
void TEST_LEVEL(const std::string &name, bool disable=true)
116116
{
117-
bool disable = true;
118117
if (disable) return;
119118

120119
if (name == "none")

source/module_base/global_function.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ inline void ZEROS(T *u,const TI n) // Peize Lin change int to TI at 2020.03.03
141141
// NAME : TEST_LEVEL
142142
// control the test_level
143143
//==========================================================
144-
void TEST_LEVEL(const std::string &name);
144+
void TEST_LEVEL(const std::string &name, bool disable);
145145

146146

147147
//==========================================================

source/module_base/test/global_function_test.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@
6060
* - get a copy of the ptr of a vector
6161
* - VECTOR_TO_PTR_v3double
6262
* - get a copy of the ptr of a vector whose elements' type belongs to Vector3<double>
63+
* - MemAvailable
64+
* - get the current memory valus
65+
* - TETS_LEVEL
66+
* - set the test level
6367
*/
6468

6569
inline void EXPECT_COMPLEX_FLOAT_EQ(const std::complex<float>& a, const std::complex<float>& b)
@@ -659,6 +663,56 @@ TEST_F(GlobalFunctionTest,Vector2Ptr)
659663
}
660664
}
661665

666+
TEST_F(GlobalFunctionTest,MemAvailable)
667+
{
668+
for(int i=0;i<5;i++)
669+
{
670+
std::ifstream ifs("/proc/meminfo");
671+
while (ifs.good())
672+
{
673+
std::string label, size, kB;
674+
ifs >> label >> size >> kB;
675+
if (label == "MemAvailable:")
676+
{
677+
EXPECT_LE(std::stol(size)-1000,ModuleBase::GlobalFunc::MemAvailable());
678+
EXPECT_GE(std::stol(size)+1000,ModuleBase::GlobalFunc::MemAvailable());
679+
}
680+
}
681+
}
682+
}
683+
684+
TEST_F(GlobalFunctionTest,TEST_LEVEL)
685+
{
686+
std::string name;
687+
bool test_bool=false;
688+
name="none";
689+
ModuleBase::GlobalFunc::TEST_LEVEL(name,test_bool);
690+
EXPECT_EQ(GlobalV::test_wf,0);
691+
EXPECT_EQ(GlobalV::test_potential,0);
692+
EXPECT_EQ(GlobalV::test_charge,0);
693+
name="init_potential";
694+
ModuleBase::GlobalFunc::TEST_LEVEL(name,test_bool);
695+
EXPECT_EQ(GlobalV::test_wf,1);
696+
EXPECT_EQ(GlobalV::test_potential,1);
697+
EXPECT_EQ(GlobalV::test_charge,1);
698+
name="init_read";
699+
ModuleBase::GlobalFunc::TEST_LEVEL(name,test_bool);
700+
EXPECT_EQ(GlobalV::test_input,1);
701+
EXPECT_EQ(GlobalV::test_winput,1);
702+
EXPECT_EQ(GlobalV::test_kpoint,1);
703+
EXPECT_EQ(GlobalV::test_atom,1);
704+
EXPECT_EQ(GlobalV::test_unitcell,1);
705+
#ifndef __EPM
706+
EXPECT_EQ(GlobalV::test_pseudo_cell,1);
707+
#else
708+
EXPECT_EQ(test_epm_unitcell,1);
709+
#endif
710+
name="pw_init";
711+
ModuleBase::GlobalFunc::TEST_LEVEL(name,test_bool);
712+
EXPECT_EQ(GlobalV::test_pw,1);
713+
}
714+
715+
662716
/*
663717
TEST_F(GlobalFunctionTest, Note)
664718
{

source/module_base/test/matrix3_test.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
* - ToMatrix
5959
* - change the form of a 3x3 matrix from that of class Matrix3
6060
* - to that of class matrix
61+
* -Template V Multiply M
62+
* -tamplate classes for (Vector3)*(3x3 matrix)
6163
*/
6264

6365
class Matrix3Test : public testing::Test
@@ -340,3 +342,25 @@ TEST_F(Matrix3Test, ToMatrix)
340342
EXPECT_EQ(ma.e21,mb(1,0)); EXPECT_EQ(ma.e22,mb(1,1)); EXPECT_EQ(ma.e23,mb(1,2));
341343
EXPECT_EQ(ma.e31,mb(2,0)); EXPECT_EQ(ma.e32,mb(2,1)); EXPECT_EQ(ma.e33,mb(2,2));
342344
}
345+
346+
TEST_F(Matrix3Test,TemplateVectorMultiplyMatrix)
347+
{
348+
ModuleBase::Vector3<int> ui(1,2,3);
349+
ModuleBase::Vector3<double> ud(1.0,2.0,3.0);
350+
ModuleBase::Vector3<float> uf(1.0,2.0,3.0);
351+
ModuleBase::Vector3<double> vi,vd,vf;
352+
ModuleBase::Matrix3 ma;
353+
ma = get_random_matrix3();
354+
vi=ui*ma;
355+
vd=ud*ma;
356+
vf=uf*ma;
357+
EXPECT_DOUBLE_EQ(vi.x,ui.x * ma.e11 + ui.y * ma.e21 + ui.z * ma.e31);
358+
EXPECT_DOUBLE_EQ(vi.y,ui.x * ma.e12 + ui.y * ma.e22 + ui.z * ma.e32);
359+
EXPECT_DOUBLE_EQ(vi.z,ui.x * ma.e13 + ui.y * ma.e23 + ui.z * ma.e33);
360+
EXPECT_DOUBLE_EQ(vd.x,ud.x * ma.e11 + ud.y * ma.e21 + ud.z * ma.e31);
361+
EXPECT_DOUBLE_EQ(vd.y,ud.x * ma.e12 + ud.y * ma.e22 + ud.z * ma.e32);
362+
EXPECT_DOUBLE_EQ(vd.z,ud.x * ma.e13 + ud.y * ma.e23 + ud.z * ma.e33);
363+
EXPECT_DOUBLE_EQ(vf.x,uf.x * ma.e11 + uf.y * ma.e21 + uf.z * ma.e31);
364+
EXPECT_DOUBLE_EQ(vf.y,uf.x * ma.e12 + uf.y * ma.e22 + uf.z * ma.e32);
365+
EXPECT_DOUBLE_EQ(vf.z,uf.x * ma.e13 + uf.y * ma.e23 + uf.z * ma.e33);
366+
}

0 commit comments

Comments
 (0)