@Test
public void testSolve() throws Exception {

    {
        // symmetric case
        DenseMatrix matA = DenseMatrix.randSymmetric(5);
        DenseMatrix b = DenseMatrix.rand(5, 7);
        DenseMatrix x = matA.solve(b);
        DenseMatrix b0 = matA.multiplies(x);
        assertEqual2D(b.getArrayCopy2D(), b0.getArrayCopy2D());
    }
    {
        // non-symmetric case
        DenseMatrix matA = DenseMatrix.rand(5, 5);
        DenseMatrix b = DenseMatrix.rand(5, 7);
        DenseMatrix x = matA.solve(b);
        DenseMatrix b0 = matA.multiplies(x);
        assertEqual2D(b.getArrayCopy2D(), b0.getArrayCopy2D());
    }
    {
        // under determined case
        DenseMatrix matA = DenseMatrix.rand(3, 5);
        DenseMatrix b = DenseMatrix.rand(3, 7);
        DenseMatrix x = matA.solve(b);
        DenseMatrix b0 = matA.multiplies(x);
        assertEqual2D(b.getArrayCopy2D(), b0.getArrayCopy2D());
    }
    {
        // over determined case
        DenseMatrix matA = DenseMatrix.rand(5, 3);
        DenseVector b = DenseVector.rand(5);
        DenseVector x = matA.solve(b);
        DenseVector r = matA.multiplies(x).minus(b);
        double nr = r.normL2Square();
        for (int i = 0; i < 10; i++) {
            DenseVector x0 = DenseVector.rand(3);
            double nr0 = matA.multiplies(x0).minus(b).normL2();
            Assert.assertTrue(nr <= nr0);
        }
    }
}