forked from abacusmodeling/abacus-develop
-
Notifications
You must be signed in to change notification settings - Fork 145
UT and annotations for inverse_matrix and heapsort #758
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| #include "../inverse_matrix.h" | ||
| #include "gtest/gtest.h" | ||
| #include <iostream> | ||
|
|
||
| /************************************************ | ||
| * unit test of class Inverse_Matrix_Complex | ||
| ***********************************************/ | ||
|
|
||
| /** | ||
| * - Tested Functions: | ||
| * - Inverse | ||
| * - use Inverse_Matrix_Complex to inverse a Hermite matrix | ||
| * - functions: init and using_zheev | ||
| * | ||
| */ | ||
|
|
||
| //a mock function of WARNING_QUIT, to avoid the uncorrected call by matrix.cpp at line 37. | ||
| namespace ModuleBase | ||
| { | ||
| void WARNING_QUIT(const std::string &file,const std::string &description) {return ;} | ||
| } | ||
|
|
||
| TEST(InverseMatrixComplexTest,Inverse) | ||
| { | ||
| int dim = 10; | ||
| ModuleBase::ComplexMatrix B(dim,dim); | ||
| ModuleBase::ComplexMatrix C(dim,dim); | ||
| ModuleBase::ComplexMatrix D(dim,dim); | ||
| double a; | ||
| double b; | ||
| double c; | ||
| // construct a Hermite matrix | ||
| for(int j=0;j<dim;j++) | ||
| { | ||
| for(int i=0;i<=j;i++) | ||
| { | ||
| if (i==j) | ||
| { | ||
| c = std::rand(); | ||
| B(i,j) = std::complex<double> (c,0.0); | ||
| } | ||
| else | ||
| { | ||
| a = std::rand(); | ||
| b = std::rand(); | ||
| B(i,j) = std::complex<double> (a,b); | ||
| B(j,i) = conj(B(i,j)); | ||
| } | ||
| } | ||
| } | ||
| ModuleBase::Inverse_Matrix_Complex IMC; | ||
| IMC.init(dim); | ||
| IMC.using_zheev(B,C); | ||
| D = B * C; | ||
| for(int i=0;i<dim;i++) | ||
| { | ||
| EXPECT_NEAR(D(i,i).real(),1.0,1e-14); | ||
| EXPECT_NEAR(D(i,i).imag(),0.0,1e-14); | ||
| //std::cout << D(i,i).real() << " " << D(i,i).imag() << std::endl; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| #include "../mymath.h" | ||
| #include "gtest/gtest.h" | ||
| #include <iostream> | ||
| #include <algorithm> | ||
|
|
||
| /************************************************ | ||
| * unit test of heap sort functions | ||
| ***********************************************/ | ||
|
|
||
| /** | ||
| * - Tested Functions: | ||
| * - Heapsort | ||
| * - heapsort function in mymath3.cpp | ||
| * - Hpsort | ||
| * - hpsort function in mymath3.cpp | ||
| * | ||
| */ | ||
|
|
||
| class MymathTest : public testing::Test | ||
| { | ||
| protected: | ||
| int number; | ||
| }; | ||
|
|
||
| TEST_F(MymathTest,Heapsort) | ||
| { | ||
| number = 5; | ||
| double rr[number]; | ||
| int index[number]; | ||
| rr[0] = 10; | ||
| rr[1] = 9; | ||
| rr[2] = 8; | ||
| rr[3] = 7; | ||
| rr[4] = 6; | ||
| index[0] = 0; | ||
| //for (int i=0;i<number;i++) | ||
| // std::cout << i << " " << rr[i] << std::endl; | ||
| ModuleBase::heapsort(number,rr,index); | ||
| for (int i=0;i<number-1;i++) | ||
| { | ||
| //std::cout << i << " " << rr[i] << std::endl; | ||
| EXPECT_LT(rr[i],rr[i+1]); | ||
| } | ||
| } | ||
|
|
||
| TEST_F(MymathTest,Hpsort) | ||
| { | ||
| number = 5; | ||
| double rr[number]; | ||
| int index[number]; | ||
| rr[0] = 10; | ||
| rr[1] = 9; | ||
| rr[2] = 8; | ||
| rr[3] = 7; | ||
| rr[4] = 6; | ||
| index[0] = 0; | ||
| //for (int i=0;i<number;i++) | ||
| // std::cout << i << " " << rr[i] << std::endl; | ||
| ModuleBase::hpsort(number,rr,index); | ||
| //std::sort(rr,rr+number); | ||
| for (int i=0;i<number-1;i++) | ||
| { | ||
| //std::cout << i << " " << rr[i] << std::endl; | ||
| EXPECT_LT(rr[i],rr[i+1]); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.