From 29efe40a8d68e2d7e1f99b66f7a5d4fff05efab9 Mon Sep 17 00:00:00 2001 From: YuLiu98 Date: Sat, 21 Sep 2024 10:16:01 +0800 Subject: [PATCH] Tests: add unittests --- source/module_io/test/outputlog_test.cpp | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/source/module_io/test/outputlog_test.cpp b/source/module_io/test/outputlog_test.cpp index 1fd15a30ea..2e7a085f81 100644 --- a/source/module_io/test/outputlog_test.cpp +++ b/source/module_io/test/outputlog_test.cpp @@ -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;