Skip to content

Commit

Permalink
Tests: add unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
YuLiu98 committed Sep 21, 2024
1 parent e8a6832 commit 29efe40
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions source/module_io/test/outputlog_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,33 @@ TEST(OutputEfermiTest, TestConvergence) {
std::remove("test_output_efermi.txt");
}

// Test the output_efermi function
TEST(OutputAfterRelaxTest, TestConvergence)
{
bool conv_ion = true;
bool conv_elec = false;
std::ofstream ofs_running("test_output_after_relax.txt");
ModuleIO::output_after_relax(conv_ion, conv_elec, ofs_running);
ofs_running.close();

std::ifstream ifs_running("test_output_after_relax.txt");
std::stringstream ss;
ss << ifs_running.rdbuf();
std::string file_content = ss.str();
ifs_running.close();

std::string expected_content
= "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n Relaxation is converged, but the SCF is unconverged! The "
"results are unreliable.. \n\n It is suggested to increase the maximum SCF step and/or perform the "
"relaxation again. "
"\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%"
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";

EXPECT_EQ(file_content, expected_content);
std::remove("test_output_after_relax.txt");
}

TEST(OutputEfermiTest, TestNotConvergence) {
bool convergence = false;
double efermi = 1.0;
Expand Down

0 comments on commit 29efe40

Please sign in to comment.