Skip to content

Commit

Permalink
Add missing i5_array::initialize function.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnoel committed Dec 11, 2020
1 parent 5ac0899 commit aafbc24
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/linad99/i5arr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,12 @@ const int& i5_array::operator()(int i, int j, int k, int l, int m) const
return elem(i)(j, k, l, m);
}
#endif
/// Initialize i5_array elements with zeros.
void i5_array::initialize()
{
const int max = indexmax();
for (int i5 = indexmin(); i5 <= max; ++i5)
{
elem(i5).initialize();
}
}
62 changes: 62 additions & 0 deletions tests/gtests/test_i5_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,65 @@ TEST_F(test_i5_array, deallocatecopies)
ASSERT_EQ(0, firstcopy.get_ncopies());
ASSERT_EQ(0, secondcopy.get_ncopies());
}
TEST_F(test_i5_array, empty_initialize)
{
i5_array a;
ASSERT_NO_THROW({
a.initialize();
});
}
TEST_F(test_i5_array, initialize)
{
i5_array a;
a.allocate(1, 5, 1, 4, 1, 3, 1, 2, 1, 10);
int index = 1;
for (int i5 = 1; i5 <= 5; ++i5)
{
for (int i4 = 1; i4 <= 4; ++i4)
{
for (int i3 = 1; i3 <= 3; ++i3)
{
for (int i2 = 1; i2 <= 2; ++i2)
{
for (int i1 = 1; i1 <= 10; ++i1)
{
a(i5, i4, i3, i2, i1) = index++;
}
}
}
}
}
for (int i5 = 1; i5 <= 5; ++i5)
{
for (int i4 = 1; i4 <= 4; ++i4)
{
for (int i3 = 1; i3 <= 3; ++i3)
{
for (int i2 = 1; i2 <= 2; ++i2)
{
for (int i1 = 1; i1 <= 10; ++i1)
{
ASSERT_TRUE(a(i5, i4, i3, i2, i1) != 0);
}
}
}
}
}
a.initialize();
for (int i5 = 1; i5 <= 5; ++i5)
{
for (int i4 = 1; i4 <= 4; ++i4)
{
for (int i3 = 1; i3 <= 3; ++i3)
{
for (int i2 = 1; i2 <= 2; ++i2)
{
for (int i1 = 1; i1 <= 10; ++i1)
{
ASSERT_EQ(a(i5, i4, i3, i2, i1), 0);
}
}
}
}
}
}

0 comments on commit aafbc24

Please sign in to comment.