Use ListOfLists in gmx_mtop_t and gmx_localtop_t
[alexxy/gromacs.git] / src / gromacs / topology / tests / exclusionblocks.cpp
index ab9f1ad1227d98909f09b37739599105213112c2..53a2a05fbcb04605c034338b9e1eabcb09f3db09 100644 (file)
@@ -47,6 +47,7 @@
 
 #include "gromacs/topology/block.h"
 #include "gromacs/utility/arrayref.h"
+#include "gromacs/utility/listoflists.h"
 #include "gromacs/utility/smalloc.h"
 
 #include "testutils/cmdlinetest.h"
@@ -101,6 +102,21 @@ void makeTestBlockAData(t_blocka* ba)
     addGroupToBlocka(ba, indices);
 }
 
+//! Return ListOfLists filled with some datastructures
+ListOfLists<int> makeTestListOfLists()
+{
+    ListOfLists<int> list;
+
+    std::vector<int> indices = { 12, 11, 9, 6, 2 };
+    list.pushBack(indices);
+    indices = { 10, 8, 5, 1 };
+    list.pushBack(indices);
+    indices = { 7, 4, 0 };
+    list.pushBack(indices);
+
+    return list;
+}
+
 class ExclusionBlockTest : public ::testing::Test
 {
 public:
@@ -108,6 +124,7 @@ public:
     {
         const int natom = 3;
         makeTestBlockAData(&ba_);
+        list_ = makeTestListOfLists();
         b_.resize(natom);
     }
     ~ExclusionBlockTest() override { done_blocka(&ba_); }
@@ -126,8 +143,23 @@ public:
         }
     }
 
+    void compareBlocksAndList()
+    {
+        GMX_RELEASE_ASSERT(ssize(b_) == list_.ssize(), "The list counts should match");
+        for (index i = 0; i < ssize(b_); i++)
+        {
+            gmx::ArrayRef<const int> jList = list_[i];
+            EXPECT_EQ(b_[i].nra(), jList.ssize()) << "Block size mismatch at " << i << ".";
+            for (int j = 0; j < b_[i].nra(); j++)
+            {
+                EXPECT_EQ(b_[i].atomNumber[j], jList[j]) << "Block mismatch at " << i << " , " << j << ".";
+            }
+        }
+    }
+
 protected:
     t_blocka                    ba_;
+    ListOfLists<int>            list_;
     std::vector<ExclusionBlock> b_;
 };
 
@@ -148,8 +180,8 @@ TEST_F(ExclusionBlockTest, ConvertExclusionBlockToBlocka)
 
 TEST_F(ExclusionBlockTest, MergeExclusions)
 {
-    mergeExclusions(&ba_, b_);
-    compareBlocks();
+    mergeExclusions(&list_, b_);
+    compareBlocksAndList();
 }
 
 } // namespace