Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions source/source_cell/magnetism.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@
#include "source_base/vector3.h"
#include <vector>

class MagnetismTest;

/**
* @brief Class for magnetism calculations.
*/
class Magnetism
{
/// @brief the unit test drives the private judge_parallel() helper directly
friend class MagnetismTest;

public:
/// @brief Constructor
Magnetism();
Expand Down
10 changes: 10 additions & 0 deletions source/source_cell/read_pp.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
#include "source_base/matrix.h"
#include "source_base/realarray.h"

class AtomPseudoTest;
class NCPPTest;
class ReadPPTest;

/**
* @brief Pseudopot_upf class for reading pseudopotential files.
*
Expand All @@ -19,6 +23,12 @@
*/
class Pseudopot_upf
{
/// @brief the unit tests drive the private format readers and the
/// complete_default_* helpers directly; see source_cell/test/
friend class AtomPseudoTest;
friend class NCPPTest;
friend class ReadPPTest;

public:
/// PP_INFO
/// PP_HEADER
Expand Down
14 changes: 10 additions & 4 deletions source/source_cell/test/atom_pseudo_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,22 @@
* - bcast upf201 pp info to other processes
*/

#define private public
#include "source_cell/read_pp.h"
#include "source_cell/pseudo.h"
#include "source_cell/atom_pseudo.h"
#undef private
class AtomPseudoTest : public testing::Test
{
protected:
std::unique_ptr<Pseudopot_upf> upf{new Pseudopot_upf};
std::unique_ptr<Atom_pseudo> atom_pseudo{new Atom_pseudo};

// Pseudopot_upf declares this fixture a friend, but a TEST_F body lives in
// a class derived from it, and friendship is not inherited -- so the call
// into the private format reader has to happen here.
int read_pseudo_upf201(std::ifstream& ifs, Atom_pseudo& pp) const
{
return upf->read_pseudo_upf201(ifs, pp);
}
};

TEST_F(AtomPseudoTest, SetDSo)
Expand All @@ -43,7 +49,7 @@ TEST_F(AtomPseudoTest, SetDSo)
std::ifstream ifs;
ifs.open("./support/C.upf");
const double pseudo_rcut = 15.0;
upf->read_pseudo_upf201(ifs, *atom_pseudo);
read_pseudo_upf201(ifs, *atom_pseudo);
upf->complete_default(*atom_pseudo, pseudo_rcut);
ifs.close();
EXPECT_EQ(atom_pseudo->nh,14);
Expand Down Expand Up @@ -75,7 +81,7 @@ TEST_F(AtomPseudoTest, BcastAtomPseudo)
std::ifstream ifs;
ifs.open("./support/C.upf");
const double pseudo_rcut = 15.0;
upf->read_pseudo_upf201(ifs, *atom_pseudo);
read_pseudo_upf201(ifs, *atom_pseudo);
upf->complete_default(*atom_pseudo, pseudo_rcut);
ifs.close();
}
Expand Down
14 changes: 10 additions & 4 deletions source/source_cell/test/magnetism_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
* - and non-collinear case with nspin = 4
*/

#define private public
#include "source_cell/magnetism.h"
#undef private


class MagnetismTest : public ::testing::Test
Expand All @@ -34,6 +32,14 @@ class MagnetismTest : public ::testing::Test
{
delete magnetism;
}

// Magnetism declares this fixture a friend, but a TEST_F body lives in a
// class derived from it, and friendship is not inherited -- so the call
// into the private helper has to happen here.
bool judge_parallel(const double a[3], const ModuleBase::Vector3<double>& b) const
{
return magnetism->judge_parallel(a, b);
}
};

TEST_F(MagnetismTest, Magnetism)
Expand All @@ -47,9 +53,9 @@ TEST_F(MagnetismTest, JudgeParallel)
{
double a[3] = {1.0, 0.0, 0.0};
ModuleBase::Vector3<double> b(1.0, 0.0, 0.0);
EXPECT_TRUE(magnetism->judge_parallel(a, b));
EXPECT_TRUE(judge_parallel(a, b));
b = ModuleBase::Vector3<double>(0.0, 1.0, 0.0);
EXPECT_FALSE(magnetism->judge_parallel(a, b));
EXPECT_FALSE(judge_parallel(a, b));
}

TEST_F(MagnetismTest, ComputeMagnetizationS2)
Expand Down
34 changes: 24 additions & 10 deletions source/source_cell/test/pseudo_nc_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,39 @@
* - print_pseudo
*/

#define private public
#include "source_cell/read_pp.h"
#include "source_cell/atom_pseudo.h"
#undef private
class NCPPTest : public testing::Test
{
protected:
std::unique_ptr<Pseudopot_upf> upf{new Pseudopot_upf};
std::unique_ptr<Atom_pseudo> ncpp{new Atom_pseudo};

// Pseudopot_upf declares this fixture a friend, but a TEST_F body lives in
// a class derived from it, and friendship is not inherited -- so the calls
// into the private reader and the complete_default_* helpers happen here.
int read_pseudo_upf201(std::ifstream& ifs, Atom_pseudo& pp) const
{
return upf->read_pseudo_upf201(ifs, pp);
}
void complete_default_h(Atom_pseudo& pp) const
{
upf->complete_default_h(pp);
}
void complete_default_atom(Atom_pseudo& pp, const double pseudo_rcut) const
{
upf->complete_default_atom(pp, pseudo_rcut);
}
};

TEST_F(NCPPTest, SetPseudoH)
{
std::ifstream ifs;
//set
ifs.open("./support/C.upf");
upf->read_pseudo_upf201(ifs, *ncpp);
read_pseudo_upf201(ifs, *ncpp);
//set_pseudo_h
upf->complete_default_h(*ncpp);
complete_default_h(*ncpp);

if(!ncpp->has_so)
{
Expand All @@ -62,10 +76,10 @@ TEST_F(NCPPTest, SetPseudoAtom)
//set
ifs.open("./support/C.upf");
const double pseudo_rcut = 15.0;
upf->read_pseudo_upf201(ifs, *ncpp);
read_pseudo_upf201(ifs, *ncpp);
//set_pseudo_atom
upf->complete_default_h(*ncpp);
upf->complete_default_atom(*ncpp, pseudo_rcut);
complete_default_h(*ncpp);
complete_default_atom(*ncpp, pseudo_rcut);
EXPECT_EQ(ncpp->rcut,pseudo_rcut);

if(!ncpp->nlcc)
Expand All @@ -86,12 +100,12 @@ TEST_F(NCPPTest, SetPseudoNC)
ifs.open("./support/C.upf");
const double pseudo_rcut = 15.0;
// set pseudo nbeta = 0
upf->read_pseudo_upf201(ifs, *ncpp);
read_pseudo_upf201(ifs, *ncpp);
ncpp->nbeta = 0;
upf->complete_default(*ncpp, pseudo_rcut);
EXPECT_EQ(ncpp->nh,0);
// set pseudo nbeta > 0
upf->read_pseudo_upf201(ifs, *ncpp);
read_pseudo_upf201(ifs, *ncpp);
upf->complete_default(*ncpp, pseudo_rcut);
EXPECT_EQ(ncpp->nh,14);
EXPECT_EQ(ncpp->kkbeta,132);
Expand All @@ -105,7 +119,7 @@ TEST_F(NCPPTest, PrintNC)
//set
ifs.open("./support/C.upf");
const double pseudo_rcut = 15.0;
upf->read_pseudo_upf201(ifs, *ncpp);
read_pseudo_upf201(ifs, *ncpp);
upf->complete_default(*ncpp, pseudo_rcut);
ifs.close();
//print
Expand Down
Loading
Loading