### Question:
SparseMatrix extends Matrix { public int getNumEntries() { int numEntries = 0; for (int i = 0; i < this.getRowCount(); i++) { numEntries += this.maxIndices[i]; } return numEntries; } 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 removeLessThanShrinksNumberOfEntries() { final SparseMatrix sparseMatrix = this.createMatrix(1, 6, new double[] {2, -3, -5, 11, -1, 8}); sparseMatrix.removeLessThan(0); MatcherAssert.assertThat(sparseMatrix.getNumEntries(), IsEqual.equalTo(3)); }
@Test public void getNumEntriesReturnsTotalNumberOfNonZeroElements() { final SparseMatrix sparseMatrix = new SparseMatrix(5, 5, 1); sparseMatrix.setAt(0, 0, 5.0); sparseMatrix.setAt(3, 0, 1.0); sparseMatrix.setAt(0, 3, 2.0); sparseMatrix.setAt(2, 1, 3.0); sparseMatrix.setAt(1, 2, 0.0); sparseMatrix.setAt(3, 3, -5.0); MatcherAssert.assertThat(sparseMatrix.getNumEntries(), IsEqual.equalTo(5)); }