### Question:
SparseMatrix extends Matrix { public int getRowCapacity(final int row) { return this.cols[row].length; } SparseMatrix(final int numRows, final int numCols, final int initialCapacityPerRow); @Override final void forEach(final ReadOnlyElementVisitorFunction func); @Override MatrixNonZeroElementRowIterator getNonZeroElementRowIterator(final int row); int getNonZeroColumnCount(final int row); int getRowCapacity(final int row); @Override String toString(); int getNumEntries();  }### Answer:
@Test public void rowCanBeReallocatedIfHigherColumnElementDoesNotFit() { final SparseMatrix sparseMatrix = new SparseMatrix(3, 2, 1); sparseMatrix.setAt(0, 0, 5.0); MatcherAssert.assertThat(sparseMatrix.getRowCapacity(0), IsEqual.equalTo(1)); sparseMatrix.setAt(0, 1, 3.0); MatcherAssert.assertThat(sparseMatrix.getRowCapacity(0), IsEqual.equalTo(2)); MatcherAssert.assertThat(sparseMatrix.getAt(0, 0), IsEqual.equalTo(5.0)); MatcherAssert.assertThat(sparseMatrix.getAt(0, 1), IsEqual.equalTo(3.0)); }
@Test public void rowCanBeReallocatedIfLowerColumnElementDoesNotFit() { final SparseMatrix sparseMatrix = new SparseMatrix(3, 2, 1); sparseMatrix.setAt(0, 1, 5.0); MatcherAssert.assertThat(sparseMatrix.getRowCapacity(0), IsEqual.equalTo(1)); sparseMatrix.setAt(0, 0, 3.0); MatcherAssert.assertThat(sparseMatrix.getRowCapacity(0), IsEqual.equalTo(2)); MatcherAssert.assertThat(sparseMatrix.getAt(0, 1), IsEqual.equalTo(5.0)); MatcherAssert.assertThat(sparseMatrix.getAt(0, 0), IsEqual.equalTo(3.0)); }