Skip to content

Commit 14a0af7

Browse files
committed
Add check for complex numbers.
1 parent 6a32203 commit 14a0af7

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

source/module_hamilt_lcao/module_deepks/test/LCAO_deepks_test.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,22 @@ void test_deepks<T>::compare_with_ref(const std::string f1, const std::string f2
501501
return;
502502
}
503503
}
504+
else if (word1[0] == '(' && word1[word1.size() - 1] == ')' &&
505+
word2[0] == '(' && word2[word2.size() - 1] == ')') // complex number
506+
{
507+
std::string word1_str = word1.substr(1, word1.size() - 2);
508+
std::string word2_str = word2.substr(1, word2.size() - 2);
509+
double word1_real = std::stof(word1_str.substr(0, word1_str.find(',')));
510+
double word1_imag = std::stof(word1_str.substr(word1_str.find(',') + 1));
511+
double word2_real = std::stof(word2_str.substr(0, word2_str.find(',')));
512+
double word2_imag = std::stof(word2_str.substr(word2_str.find(',') + 1));
513+
if (std::abs(word1_real - word2_real) > test_thr || std::abs(word1_imag - word2_imag) > test_thr)
514+
{
515+
this->failed_check += 1;
516+
std::cout << "\e[1;31m [ FAILED ] \e[0m" << f1.c_str() << " inconsistent!" << std::endl;
517+
return;
518+
}
519+
}
504520
else
505521
{
506522
if (word1 != word2)

0 commit comments

Comments
 (0)