Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54230 - trunk/libs/numeric/ublas/test
From: guwi17_at_[hidden]
Date: 2009-06-22 16:53:50


Author: guwi17
Date: 2009-06-22 16:53:49 EDT (Mon, 22 Jun 2009)
New Revision: 54230
URL: http://svn.boost.org/trac/boost/changeset/54230

Log:
comp_mat_erase.cpp - unit test to verify compressed matrix layout, insertion and erasure of elements, see #2195

CMakeLists.txt - added new test: comp_mat_erase

Jamfile.v2 - added new test: comp_mat_erase

Added:
   trunk/libs/numeric/ublas/test/comp_mat_erase.cpp (contents, props changed)
Text files modified:
   trunk/libs/numeric/ublas/test/CMakeLists.txt | 1 +
   trunk/libs/numeric/ublas/test/Jamfile.v2 | 2 ++
   2 files changed, 3 insertions(+), 0 deletions(-)

Modified: trunk/libs/numeric/ublas/test/CMakeLists.txt
==============================================================================
--- trunk/libs/numeric/ublas/test/CMakeLists.txt (original)
+++ trunk/libs/numeric/ublas/test/CMakeLists.txt 2009-06-22 16:53:49 EDT (Mon, 22 Jun 2009)
@@ -66,6 +66,7 @@
 boost_test_run(triangular_layout
   triangular_layout.cpp)
 
+boost_test_run(comp_mat_erase)
 
 SET(test_compile_flags "-DEXTERNAL")
 #-- Intel Compiler flags

Modified: trunk/libs/numeric/ublas/test/Jamfile.v2
==============================================================================
--- trunk/libs/numeric/ublas/test/Jamfile.v2 (original)
+++ trunk/libs/numeric/ublas/test/Jamfile.v2 2009-06-22 16:53:49 EDT (Mon, 22 Jun 2009)
@@ -114,4 +114,6 @@
       ]
       [ run triangular_layout.cpp
       ]
+ [ run comp_mat_erase.cpp
+ ]
     ;

Added: trunk/libs/numeric/ublas/test/comp_mat_erase.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/numeric/ublas/test/comp_mat_erase.cpp 2009-06-22 16:53:49 EDT (Mon, 22 Jun 2009)
@@ -0,0 +1,100 @@
+#include "boost/numeric/ublas/matrix_sparse.hpp"
+
+#define BOOST_TEST_MODULE SparseMatrixErasureTest
+#include <boost/test/included/unit_test.hpp>
+
+
+BOOST_AUTO_TEST_CASE( compressed_matrix_erase_after_end )
+{
+ boost::numeric::ublas::compressed_matrix<int, boost::numeric::ublas::row_major > A(2, 2);
+
+ BOOST_CHECK_EQUAL( A.filled1(), 1 );
+ BOOST_CHECK_EQUAL( A.index1_data()[0], 0 );
+
+ A(0,0) = 1;
+
+ BOOST_CHECK_EQUAL( A.nnz(), 1 );
+ BOOST_CHECK_EQUAL( A.filled1(), 2 );
+
+ // check new element
+ BOOST_CHECK_EQUAL( A.index1_data()[0], 0 );
+ BOOST_CHECK_EQUAL( A.index2_data()[0], 0 );
+ BOOST_CHECK_EQUAL( A.value_data()[0], 1 );
+ // check end of list marker
+ BOOST_CHECK_EQUAL( A.index1_data()[1], 1 );
+
+ A.erase_element(1,0);
+
+ BOOST_CHECK_EQUAL( A.nnz(), 1 );
+ BOOST_CHECK_EQUAL( A.filled1(), 2 );
+ BOOST_CHECK_EQUAL( A.filled2(), 1 );
+
+ // check new element
+ BOOST_CHECK_EQUAL( A.index1_data()[0], 0 );
+ BOOST_CHECK_EQUAL( A.index2_data()[0], 0 );
+ BOOST_CHECK_EQUAL( A.value_data()[0], 1 );
+ // check end of list marker
+ BOOST_CHECK_EQUAL( A.index1_data()[1], 1 );
+
+ A.erase_element(0,0);
+
+ BOOST_CHECK_EQUAL( A.nnz(), 0 );
+ BOOST_CHECK_EQUAL( A.filled1(), 2 );
+ BOOST_CHECK_EQUAL( A.filled2(), 0 );
+ BOOST_CHECK_EQUAL( A.index1_data()[0], 0 );
+
+}
+
+BOOST_AUTO_TEST_CASE( compressed_matrix_erase_in_the_middle )
+{
+ boost::numeric::ublas::compressed_matrix<int, boost::numeric::ublas::row_major > A(2, 2);
+
+ BOOST_CHECK_EQUAL( A.filled1(), 1 );
+ BOOST_CHECK_EQUAL( A.filled2(), 0 );
+ BOOST_CHECK_EQUAL( A.index1_data()[0], 0 );
+
+ A.insert_element(0,1,5);
+
+ BOOST_CHECK_EQUAL( A.filled1(), 2 );
+ BOOST_CHECK_EQUAL( A.filled2(), 1 );
+
+ // check new element
+ BOOST_CHECK_EQUAL( A.index1_data()[0], 0 );
+ BOOST_CHECK_EQUAL( A.index2_data()[0], 1 );
+ BOOST_CHECK_EQUAL( A.value_data()[0], 5 );
+ // check end of list marker
+ BOOST_CHECK_EQUAL( A.index1_data()[1], 1 );
+
+ A.insert_element(0,0,4);
+
+ BOOST_CHECK_EQUAL( A.filled1(), 2 );
+ BOOST_CHECK_EQUAL( A.filled2(), 2 );
+
+ // check new element
+ BOOST_CHECK_EQUAL( A.index2_data()[0], 0 );
+ BOOST_CHECK_EQUAL( A.value_data()[0], 4 );
+ // check previous element
+ BOOST_CHECK_EQUAL( A.index2_data()[1], 1 );
+ BOOST_CHECK_EQUAL( A.value_data()[1], 5 );
+ // check end of list marker
+ BOOST_CHECK_EQUAL( A.index1_data()[1], 2 );
+
+ A.erase_element(0,0);
+
+ BOOST_CHECK_EQUAL( A.filled1(), 2 );
+ BOOST_CHECK_EQUAL( A.filled2(), 1 );
+
+ BOOST_CHECK_EQUAL( A.index2_data()[0], 1 );
+ BOOST_CHECK_EQUAL( A.value_data()[0], 5 );
+
+ BOOST_CHECK_EQUAL( A.index1_data()[0], 0 );
+ BOOST_CHECK_EQUAL( A.index1_data()[1], 1 );
+
+ A.erase_element(0,1);
+
+ BOOST_CHECK_EQUAL( A.filled1(), 2 );
+ BOOST_CHECK_EQUAL( A.filled2(), 0 );
+ BOOST_CHECK_EQUAL( A.index1_data()[0], 0 );
+ BOOST_CHECK_EQUAL( A.index1_data()[1], 0 );
+
+}


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk