### Question:
OGMatrixAlgebra extends MatrixAlgebra { @Override public Matrix multiply(Matrix m1, Matrix m2) { ArgChecker.notNull(m1, "m1"); ArgChecker.notNull(m2, "m2"); if (m1 instanceof TridiagonalMatrix && m2 instanceof DoubleArray) { return multiply((TridiagonalMatrix) m1, (DoubleArray) m2); } else if (m1 instanceof DoubleArray && m2 instanceof TridiagonalMatrix) { return multiply((DoubleArray) m1, (TridiagonalMatrix) m2); } else if (m1 instanceof DoubleMatrix && m2 instanceof DoubleMatrix) { return multiply((DoubleMatrix) m1, (DoubleMatrix) m2); } else if (m1 instanceof DoubleMatrix && m2 instanceof DoubleArray) { return multiply((DoubleMatrix) m1, (DoubleArray) m2); } else if (m1 instanceof DoubleArray && m2 instanceof DoubleMatrix) { return multiply((DoubleArray) m1, (DoubleMatrix) m2); } throw new IllegalArgumentException( "Can only multiply two DoubleMatrix; a DoubleMatrix and a DoubleArray; " + "or a DoubleArray and a DoubleMatrix. have " + m1.getClass() + " and " + m2.getClass()); }  @Override double getCondition(Matrix m); @Override double getDeterminant(Matrix m); @Override double getInnerProduct(Matrix m1, Matrix m2); @Override DoubleMatrix getInverse(Matrix m); @Override double getNorm1(Matrix m); @Override double getNorm2(Matrix m); @Override double getNormInfinity(Matrix m); @Override DoubleMatrix getOuterProduct(Matrix m1, Matrix m2); @Override DoubleMatrix getPower(Matrix m, int p); @Override double getTrace(Matrix m); @Override DoubleMatrix getTranspose(Matrix m); @Override Matrix multiply(Matrix m1, Matrix m2); @Override DoubleMatrix getPower(Matrix m, double p);  }### Answer:
@Test public void testMatrixSizeMismatch() { assertThatIllegalArgumentException() .isThrownBy(() -> ALGEBRA.multiply(B, A)); }
@Test public void testMultiply() { final DoubleMatrix c = (DoubleMatrix) ALGEBRA.multiply(A, B); final int rows = c.rowCount(); final int cols = c.columnCount(); int i, j; for (i = 0; i < rows; i++) { for (j = 0; j < cols; j++) { assertThat(c.get(i, j)).isCloseTo(C.get(i, j), offset(1e-15)); } } final DoubleArray d = (DoubleArray) ALGEBRA.multiply(A, D); assertThat(d.get(0)).isCloseTo(6, offset(1e-15)); assertThat(d.get(1)).isCloseTo(0, offset(1e-15)); assertThat(d.get(2)).isCloseTo(-3, offset(1e-15)); }
@Test public void testTridiagonalMultiply() { final int n = 37; double[] l = new double[n - 1]; double[] c = new double[n]; double[] u = new double[n - 1]; double[] x = new double[n]; for (int ii = 0; ii < n; ii++) { c[ii] = RANDOM.nextRandom(); x[ii] = RANDOM.nextRandom(); if (ii < n - 1) { l[ii] = RANDOM.nextRandom(); u[ii] = RANDOM.nextRandom(); } } final TridiagonalMatrix m = new TridiagonalMatrix(c, u, l); final DoubleArray xVec = DoubleArray.copyOf(x); DoubleArray y1 = (DoubleArray) ALGEBRA.multiply(m, xVec); DoubleMatrix full = m.toDoubleMatrix(); DoubleArray y2 = (DoubleArray) ALGEBRA.multiply(full, xVec); for (int i = 0; i < n; i++) { assertThat(y1.get(i)).isCloseTo(y2.get(i), offset(1e-12)); } }