Skip to content

Commit afb52a3

Browse files
Critsium-xyclaude
andauthored
source_basis/module_ao: orb_atomic_lm_test off the access hack, via getters plus one friend (#7953)
`orb_atomic_lm_test.cpp` reached into 17 private members of `Numerical_Orbital_Lm` and called four of its private methods. Sixteen of those members already have public accessors, so the macro comes off mostly by using them: 138 sites now read through `get_psi()`, `getNr()`, `getRcut()` and the rest. No PARAM is involved. Two things needed more than a substitution: - `psir` was the only array in the class without the vector accessor its siblings all have. `Numerical_Orbital_Lm` exposes a systematic trio per array -- `getX()` returning a pointer, `getX(i)` returning an element, `get_x()` returning the vector -- and psir had only the first two, so `.psir.size()` and `.psir.empty()` had no public route. Added the missing `get_psir()`, completing the pattern rather than inventing an accessor for the test. - `cal_kradial`, `cal_kradial_sbpool`, `cal_rradial_sbpool` and `plot` are private and are what four of the tests exist to exercise. These get `friend class NumericalOrbitalLmTest;`, next to the `friend class Numerical_Orbital;` the class already carries, plus four forwarding wrappers on the fixture -- a TEST_F body lives in a derived class and does not inherit friendship. The substitution is uniform because the accessors return the member itself: `get_psi()` yields `const std::vector<double>&`, so `.psi[i]`, `.psi.size()`, `.psi.empty()` and bare `.psi` all keep working through it, and the scalar getters return const references. Every site was rewritten mechanically and then checked: no private member of the class is named in any TEST_F body any more. No test expectation changed. Macro occurrences in this file go 1 -> 0; no `#undef private` is added and no other file is touched. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 9958006 commit afb52a3

2 files changed

Lines changed: 156 additions & 146 deletions

File tree

‎source/source_basis/module_ao/orb_atomic_lm.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ using std::vector;
2020
class Numerical_Orbital_Lm
2121
{
2222
friend class Numerical_Orbital;
23+
/// the unit test drives cal_kradial(), cal_kradial_sbpool(),
24+
/// cal_rradial_sbpool() and plot() directly
25+
friend class NumericalOrbitalLmTest;
2326

2427
public:
2528

@@ -139,6 +142,7 @@ class Numerical_Orbital_Lm
139142
const std::vector<double>& get_psi() const { return psi; }
140143
const double* getPsi_r() const { return ModuleBase::GlobalFunc::VECTOR_TO_PTR(psir); }
141144
const double& getPsi_r(const int ir) const { return psir[ir]; }
145+
const std::vector<double>& get_psir() const { return psir; }
142146

143147
const double* getPsif() const { return ModuleBase::GlobalFunc::VECTOR_TO_PTR(psif); }
144148
const double& getPsif(const int ik) const { return psif[ik]; }

0 commit comments

Comments
 (0)