Repository navigation
Expand file tree
/
Copy pathmathzone_test.cpp
More file actions
86 lines (80 loc) · 2.05 KB
/
Copy pathmathzone_test.cpp
File metadata and controls
86 lines (80 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "../mathzone.h"
#include "../matrix3.h"
#include "../vector3.h"
#include "gtest/gtest.h"
#include "gmock/gmock.h"
/************************************************
* unit test of class Mathzone
***********************************************/
/**
* - Tested Functions:
* - PointwiseProduct
* - return a vector, which is the pointwise
* - product of another two vectors of the same
* - length
* - Direct2Cartesian
* - change atomic coordinates from direct
* - to Cartesian
* - Cartesian2Direct
* - change atomic coordinates from Cartesian
* - to Direct
*/
class MathzoneTest : public testing::Test
{
protected:
double R11 = 3.68; double R12 = 0.00; double R13 = 0.00;
double R21 = 0.00; double R22 = 10.1; double R23 = 0.00;
double R31 = 0.00; double R32 = 0.00; double R33 = 26.7;
ModuleBase::Matrix3 lattice;
ModuleBase::Vector3<double> direct, cartesian;
};
TEST_F(MathzoneTest, PointwiseProduct)
{
std::vector<double> aa, bb, cc;
for(int i=0;i<10;i++)
{
aa.push_back(i*i);
bb.push_back(i*2);
}
cc = ModuleBase::Mathzone::Pointwise_Product(aa,bb);
for(int i=0;i<10;i++)
{
EXPECT_EQ(cc[i],i*i*i*2);
}
}
TEST_F(MathzoneTest, Direct2Cartesian)
{
direct.set(0.1,0.2,0.4);
cartesian.set(0.368,2.02,10.68);
ModuleBase::Vector3<double> cartnew;
ModuleBase::Mathzone::Direct_to_Cartesian(direct.x,
direct.y,
direct.z,
R11, R12, R13,
R21, R22, R23,
R31, R32, R33,
cartnew.x,
cartnew.y,
cartnew.z);
EXPECT_NEAR(cartnew.x,cartesian.x, 1e-15);
EXPECT_NEAR(cartnew.y,cartesian.y, 1e-15);
EXPECT_NEAR(cartnew.z,cartesian.z, 1e-15);
}
TEST_F(MathzoneTest, Cartesian2Direct)
{
direct.set(0.1,0.2,0.4);
cartesian.set(0.368,2.02,10.68);
ModuleBase::Vector3<double> directnew;
ModuleBase::Mathzone::Cartesian_to_Direct(cartesian.x,
cartesian.y,
cartesian.z,
R11, R12, R13,
R21, R22, R23,
R31, R32, R33,
directnew.x,
directnew.y,
directnew.z);
EXPECT_NEAR(directnew.x,direct.x, 1e-15);
EXPECT_NEAR(directnew.y,direct.y, 1e-15);
EXPECT_NEAR(directnew.z,direct.z, 1e-15);
}