From 279b1e84f1a3b17c22005728181470d5d14d7556 Mon Sep 17 00:00:00 2001 From: "Guoyang2022i@outlook.com" Date: Wed, 3 Apr 2024 12:39:32 +0800 Subject: [PATCH 1/2] initialize some variables --- source/module_base/test/realarray_test.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/module_base/test/realarray_test.cpp b/source/module_base/test/realarray_test.cpp index 3a988aabdc..cf469c1d7d 100644 --- a/source/module_base/test/realarray_test.cpp +++ b/source/module_base/test/realarray_test.cpp @@ -11,7 +11,7 @@ * - get the total number of real array created * - Construct * - construct real arrays (3 or 4 dimensions) - * - Creat + * - Creat * - create a real array (3 or 4 dimensions) * - GetSize * - get the total size of a real array @@ -22,7 +22,7 @@ * - GetBound * - get the size of each dimension of a real array * - ArrayEqReal - * - set all value of an array to a double float + * - set all value of an array to a double float * - ArrayEqArray * - equal a realarray to another one * - Parentheses @@ -43,8 +43,8 @@ class realArrayTest : public testing::Test ModuleBase::realArray a3, a4, b3, b4; double aa = 11.0; double bb = 1.0; - int count0; - int count1; + int count0 = 0; + int count1 = 0; const double zero = 0.0; }; From 56c20ce444eac6ac4f4497a24506fed95b7a4c1c Mon Sep 17 00:00:00 2001 From: "Guoyang2022i@outlook.com" Date: Sat, 13 Apr 2024 20:06:14 +0800 Subject: [PATCH 2/2] using [stl vector] replace [new]and[delete], in math_ylmreal_test.cpp --- source/module_base/test/math_ylmreal_test.cpp | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/source/module_base/test/math_ylmreal_test.cpp b/source/module_base/test/math_ylmreal_test.cpp index 13d0bd2b69..45e3bf7a73 100644 --- a/source/module_base/test/math_ylmreal_test.cpp +++ b/source/module_base/test/math_ylmreal_test.cpp @@ -5,6 +5,7 @@ #include"gtest/gtest.h" #include #include "module_psi/psi.h" +#include #define doublethreshold 1e-12 @@ -193,19 +194,24 @@ class YlmRealTest : public testing::Test void SetUp() { ylm.create(nylm,ng); - dylm = new ModuleBase::matrix[3]; + std::vector dylm; + dylm.resize(3); for(int i = 0 ; i < 3 ; ++i) dylm[i].create(nylm,ng); - g = new ModuleBase::Vector3[ng]; + std::vector> g; + g.resize(ng); g[0].set(1.0,0.0,0.0); g[1].set(0.0,1.0,0.0); g[2].set(0.0,0.0,1.0); g[3].set(-1.0,-1.0,-1.0); - rly = new double[nylm]; + std::vector rly; + rly.resize(nylm); rlyvector.resize(nylm); - rlgy = new double[nylm][3]; + std::vector> rlgy; + rlgy.resize(nylm, std::vector(3)); rlgyvector.resize(nylm,std::vector(3)); - ref = new double[64*4]{ + + std::vector ref = { y00(g[0].x, g[0].y, g[0].z), y00(g[1].x, g[1].y, g[1].z), y00(g[2].x, g[2].y, g[2].z), y00(g[3].x, g[3].y, g[3].z), y10(g[0].x, g[0].y, g[0].z), y10(g[1].x, g[1].y, g[1].z), y10(g[2].x, g[2].y, g[2].z), y10(g[3].x, g[3].y, g[3].z), y11(g[0].x, g[0].y, g[0].z), y11(g[1].x, g[1].y, g[1].z), y11(g[2].x, g[2].y, g[2].z), y11(g[3].x, g[3].y, g[3].z), @@ -273,14 +279,7 @@ class YlmRealTest : public testing::Test } ; } - void TearDown() - { - delete [] dylm; - delete [] g; - delete [] ref; - delete [] rly; - delete [] rlgy; - } + }; TEST_F(YlmRealTest,Constructor)