Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions source/Makefile.Objects
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ OBJS_CELL=atom_pseudo.o\
read_pp_blps.o\
read_pp_vwr.o\
unitcell.o\
unitcell_index.o\
unitcell_stats.o\
unitcell_setup.o\
read_atoms.o\
read_atoms_helper.o\
print_cell.o\
Expand Down
3 changes: 3 additions & 0 deletions source/source_cell/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ add_library(
mdcell_reader.cpp
mdcell.cpp
unitcell.cpp
unitcell_index.cpp
unitcell_stats.cpp
unitcell_setup.cpp
read_atoms.cpp
read_atoms_helper.cpp
read_orb.cpp
Expand Down
12 changes: 12 additions & 0 deletions source/source_cell/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ install(FILES bcast_sep_cell_test.sh DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

list(APPEND cell_simple_srcs
../unitcell.cpp
../unitcell_index.cpp
../unitcell_stats.cpp
../unitcell_setup.cpp
../update_cell.cpp
../bcast_cell.cpp
../print_cell.cpp
Expand Down Expand Up @@ -138,6 +141,9 @@ AddTest(
../print_cell.cpp
../atom_spec.cpp
../unitcell.cpp
../unitcell_index.cpp
../unitcell_stats.cpp
../unitcell_setup.cpp
../update_cell.cpp
../bcast_cell.cpp
../atom_pseudo.cpp
Expand Down Expand Up @@ -176,6 +182,12 @@ AddTest(
SOURCES unitcell_test.cpp ../cal_ux.cpp
)

AddTest(
TARGET MODULE_CELL_unitcell_index_test
LIBS base device cell_info symmetry
SOURCES test_unitcell_index.cpp ../magnetism.cpp
)

AddTest(
TARGET MODULE_CELL_print_cell_test
LIBS base device cell_info symmetry
Expand Down
75 changes: 75 additions & 0 deletions source/source_cell/test/test_unitcell_index.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include "../unitcell.h"

#include <gtest/gtest.h>

class TestUnitCellIndex : public ::testing::Test
{
protected:
void SetUp() override
{
// Build a minimal UnitCell:
// 2 species, 2 atoms of the first species, 1 atom of the second
ucell.ntype = 2;
ucell.nat = 3;
ucell.atoms = new Atom[2];
ucell.atoms[0].na = 2;
ucell.atoms[0].nw = 4; // 4 orbitals
ucell.atoms[1].na = 1;
ucell.atoms[1].nw = 2; // 2 orbitals
ucell.set_atom_flag = true;
}

void TearDown() override
{
// Do NOT delete[] ucell.atoms: ~UnitCell() frees it (set_atom_flag = true).
// Do NOT delete[] iat2it/iat2ia either: they are owned by the internal
// Statistics member, whose destructor releases them (see AGENTS.md).
}

UnitCell ucell;
};

TEST_F(TestUnitCellIndex, SetIat2itia)
{
ucell.set_iat2itia();
// iat2it: [0, 0, 1]
EXPECT_EQ(ucell.iat2it[0], 0);
EXPECT_EQ(ucell.iat2it[1], 0);
EXPECT_EQ(ucell.iat2it[2], 1);
// iat2ia: [0, 1, 0]
EXPECT_EQ(ucell.iat2ia[0], 0);
EXPECT_EQ(ucell.iat2ia[1], 1);
EXPECT_EQ(ucell.iat2ia[2], 0);
}

TEST_F(TestUnitCellIndex, SetIat2itiaCalledTwice)
{
// Cover the delete[] + new[] reallocation path: the second call must
// produce the same mapping as the first.
ucell.set_iat2itia();
ucell.set_iat2itia();
EXPECT_EQ(ucell.iat2it[0], 0);
EXPECT_EQ(ucell.iat2it[1], 0);
EXPECT_EQ(ucell.iat2it[2], 1);
EXPECT_EQ(ucell.iat2ia[0], 0);
EXPECT_EQ(ucell.iat2ia[1], 1);
EXPECT_EQ(ucell.iat2ia[2], 0);
}

TEST_F(TestUnitCellIndex, SetIat2iwtNpol1)
{
ucell.set_iat2iwt(1);
// iat=0: iwt=0, iat=1: iwt=4, iat=2: iwt=8
EXPECT_EQ(ucell.get_iat2iwt()[0], 0);
EXPECT_EQ(ucell.get_iat2iwt()[1], 4);
EXPECT_EQ(ucell.get_iat2iwt()[2], 8);
}

TEST_F(TestUnitCellIndex, SetIat2iwtNpol2)
{
ucell.set_iat2iwt(2);
// iat=0: iwt=0, iat=1: iwt=8, iat=2: iwt=16
EXPECT_EQ(ucell.get_iat2iwt()[0], 0);
EXPECT_EQ(ucell.get_iat2iwt()[1], 8);
EXPECT_EQ(ucell.get_iat2iwt()[2], 16);
}
2 changes: 1 addition & 1 deletion source/source_cell/test_pw/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ install(FILES unitcell_test_pw_para.sh DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
AddTest(
TARGET MODULE_CELL_unitcell_test_pw
LIBS parameter base device
SOURCES unitcell_test_pw.cpp ../unitcell.cpp ../read_atoms.cpp ../read_atoms_helper.cpp ../cell_tools.cpp ../atom_spec.cpp ../update_cell.cpp ../bcast_cell.cpp
SOURCES unitcell_test_pw.cpp ../unitcell.cpp ../unitcell_index.cpp ../unitcell_stats.cpp ../unitcell_setup.cpp ../read_atoms.cpp ../read_atoms_helper.cpp ../cell_tools.cpp ../atom_spec.cpp ../update_cell.cpp ../bcast_cell.cpp
../atom_pseudo.cpp ../pseudo.cpp ../read_pp.cpp ../read_pp_complete.cpp ../read_pp_upf201.cpp ../read_pp_upf100.cpp
../read_stru.cpp ../read_atom_species.cpp
../read_pp_vwr.cpp ../read_pp_blps.cpp
Expand Down
Loading
Loading