/** test add failure */ public void testAddFail() { OpenMapRealMatrix m = createSparseMatrix(testData); OpenMapRealMatrix m2 = createSparseMatrix(testData2); try { m.add(m2); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException ex) { // ignored } }
/** test add */ public void testAdd() { OpenMapRealMatrix m = createSparseMatrix(testData); OpenMapRealMatrix mInv = createSparseMatrix(testDataInv); OpenMapRealMatrix mDataPlusInv = createSparseMatrix(testDataPlusInv); RealMatrix mPlusMInv = m.add(mInv); for (int row = 0; row < m.getRowDimension(); row++) { for (int col = 0; col < m.getColumnDimension(); col++) { assertEquals( "sum entry entry", mDataPlusInv.getEntry(row, col), mPlusMInv.getEntry(row, col), entryTolerance); } } }