[cig-commits] r13152 - cs/cigma/trunk/tests/libcigma

luis at geodynamics.org luis at geodynamics.org
Wed Oct 29 15:10:59 PDT 2008


Author: luis
Date: 2008-10-29 15:10:59 -0700 (Wed, 29 Oct 2008)
New Revision: 13152

Added:
   cs/cigma/trunk/tests/libcigma/DofHandlerTest.cpp
   cs/cigma/trunk/tests/libcigma/DofHandlerTest.h
Log:
Basic test for cigma::DofHandler

Added: cs/cigma/trunk/tests/libcigma/DofHandlerTest.cpp
===================================================================
--- cs/cigma/trunk/tests/libcigma/DofHandlerTest.cpp	                        (rev 0)
+++ cs/cigma/trunk/tests/libcigma/DofHandlerTest.cpp	2008-10-29 22:10:59 UTC (rev 13152)
@@ -0,0 +1,89 @@
+#include "DofHandlerTest.h"
+using namespace libcigma;
+
+#include "DofHandler.h"
+using namespace cigma;
+
+const double delta = 1e-8;
+
+static void test_getData(int nno, int rank, double *dofs,
+                         int cellnno, int *nodeIds, double *answer)
+{
+    DofHandler dofHandler(nno, rank);
+    dofHandler.setData(dofs);
+
+    double localdofs[cellnno*rank];
+    dofHandler.getData(cellnno, nodeIds, localdofs);
+
+    CPPUNIT_ASSERT_EQUAL(dofHandler.n_nodes(), nno);
+    CPPUNIT_ASSERT_EQUAL(dofHandler.n_rank(), rank);
+
+    for (int i = 0; i < cellnno; i++)
+    {
+        for (int j = 0; j < rank; j++)
+        {
+            const int k = rank*i + j;
+            CPPUNIT_ASSERT_DOUBLES_EQUAL(localdofs[k], answer[k], delta);
+        }
+    }
+}
+
+void DofHandlerTest::test_get_data()
+{
+    const int nno = 5;
+
+    double dofs1[nno * 1] = {
+        1, 4, 9, 16, 25
+    };
+    double dofs2[nno * 2] = {
+        1, 1,
+        2, 4,
+        3, 9,
+        4, 16,
+        5, 25
+    };
+    double dofs3[nno * 3] = {
+        1, 1, 1,
+        2, 4, 8,
+        3, 9, 27,
+        4, 16, 64,
+        5, 25, 125
+    };
+    double dofs6[nno * 6] = {
+        1, 1, 1, 1, 1, 1,
+        2, 4, 8, 16, 32, 64,
+        3, 9, 27, 81, 243, 729,
+        4, 16, 64, 256, 1024, 4096,
+        5, 25, 125, 625, 3125, 15625
+    };
+
+    const int cellnno = 3;
+    
+    int nodeIds[3] = { 1, 3, 4 };
+
+    double ans1[3*1] = {
+        4, 16, 25
+    };
+    double ans2[3*2] = {
+        2, 4,
+        4, 16,
+        5, 25
+    };
+    double ans3[3*3] = {
+        2, 4, 8,
+        4, 16, 64,
+        5, 25, 125
+    };
+    double ans6[3*6] = {
+        2, 4, 8, 16, 32, 64,
+        4, 16, 64, 256, 1024, 4096,
+        5, 25, 125, 625, 3125, 15625
+    };
+
+    test_getData(nno, 1, dofs1, cellnno, nodeIds, ans1);
+    test_getData(nno, 2, dofs2, cellnno, nodeIds, ans2);
+    test_getData(nno, 3, dofs3, cellnno, nodeIds, ans3);
+    test_getData(nno, 6, dofs6, cellnno, nodeIds, ans6);
+}
+
+

Added: cs/cigma/trunk/tests/libcigma/DofHandlerTest.h
===================================================================
--- cs/cigma/trunk/tests/libcigma/DofHandlerTest.h	                        (rev 0)
+++ cs/cigma/trunk/tests/libcigma/DofHandlerTest.h	2008-10-29 22:10:59 UTC (rev 13152)
@@ -0,0 +1,23 @@
+#ifndef __DOF_HANDLER_TEST_H__
+#define __DOF_HANDLER_TEST_H__
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+
+namespace libcigma
+{
+    class DofHandlerTest : public CPPUNIT_NS::TestFixture
+    {
+        CPPUNIT_TEST_SUITE(DofHandlerTest);
+        CPPUNIT_TEST(test_get_data);
+        CPPUNIT_TEST_SUITE_END();
+
+    public:
+        DofHandlerTest() {}
+        ~DofHandlerTest() {}
+        void test_get_data();
+    };
+};
+
+#endif



More information about the CIG-COMMITS mailing list