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

luis at geodynamics.org luis at geodynamics.org
Wed Oct 15 02:08:05 PDT 2008


Author: luis
Date: 2008-10-15 02:08:04 -0700 (Wed, 15 Oct 2008)
New Revision: 13060

Modified:
   cs/cigma/trunk/tests/libcigma/PointsTest.cpp
   cs/cigma/trunk/tests/libcigma/PointsTest.h
Log:
Test copy constructor and assignment operator for Points

Modified: cs/cigma/trunk/tests/libcigma/PointsTest.cpp
===================================================================
--- cs/cigma/trunk/tests/libcigma/PointsTest.cpp	2008-10-15 09:08:02 UTC (rev 13059)
+++ cs/cigma/trunk/tests/libcigma/PointsTest.cpp	2008-10-15 09:08:04 UTC (rev 13060)
@@ -25,6 +25,33 @@
     CPPUNIT_ASSERT_DOUBLES_EQUAL(pt3.get(2), 3.0, delta);
 }
 
+void PointsTest::test_copy()
+{
+    double a[3] = {1,2,3};
+    Point<3> pt1(a,3);
+
+    /* test copy constructor */
+    Point<3> pt2 = pt1;
+
+    /* test assignment operator */
+    Point<3> pt3;
+    pt3 = pt2;
+
+    /* test subscript operator */
+    Point<3> pt4;
+    pt4[0] = pt1.get(0);
+    pt4[1] = pt1.get(1);
+    pt4[2] = pt1.get(2);
+
+    for (int i = 0; i < 3; i++)
+    {
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(pt1[i], a[i], delta);
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(pt1[i], pt2[i], delta);
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(pt1[i], pt3[i], delta);
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(pt1[i], pt4[i], delta);
+    }
+}
+
 void PointsTest::test_components()
 {
     const int npts = 10;
@@ -59,9 +86,12 @@
 
     for (i = 0; i < npts; i++)
     {
+        pt = dpts.get(i);
         for (j = 0; j < 3; j++)
         {
-            CPPUNIT_ASSERT_DOUBLES_EQUAL(dpts.get(i,j), _p3[3*i + j], delta);
+            double val = _p3[3*i + j];
+            CPPUNIT_ASSERT_DOUBLES_EQUAL(dpts.get(i,j), val, delta);
+            CPPUNIT_ASSERT_DOUBLES_EQUAL(pt[j], val, delta);
         }
     }
 

Modified: cs/cigma/trunk/tests/libcigma/PointsTest.h
===================================================================
--- cs/cigma/trunk/tests/libcigma/PointsTest.h	2008-10-15 09:08:02 UTC (rev 13059)
+++ cs/cigma/trunk/tests/libcigma/PointsTest.h	2008-10-15 09:08:04 UTC (rev 13060)
@@ -12,6 +12,7 @@
     {
         CPPUNIT_TEST_SUITE(PointsTest);
         CPPUNIT_TEST(test_constructors);
+        CPPUNIT_TEST(test_copy);
         CPPUNIT_TEST(test_components);
         CPPUNIT_TEST_SUITE_END();
 
@@ -21,6 +22,7 @@
         virtual ~PointsTest();
 
         void test_constructors();
+        void test_copy();
         void test_components();
     };
 }



More information about the cig-commits mailing list