using System; using System.Collections.Generic; using System.Linq; using System.Text; using Azimuth.DenseLinearAlgebra; namespace Azimuth.UnitTests.DenseLinearAlgebra { public class IRectangularMatrixTests : UnitTestSharp.TestFixture { public class ExtractColumn : UnitTestSharp.TestFixture { public void Works() { var matrix = new RectangularMatrix(new Scalar[,] { { 1, 2, }, { 6, 5, }, { 7, 9, } }); CheckEqual(new DenseVector(new Scalar[] { 1, 6, 7 }), matrix.ExtractColumn(0)); CheckEqual(new DenseVector(new Scalar[] { 2, 5, 9 }), matrix.ExtractColumn(1)); } } public class ExtractRow : UnitTestSharp.TestFixture { public void Works() { var matrix = new RectangularMatrix(new Scalar[,] { { 1, 2, }, { 6, 5, }, { 7, 9, } }); CheckEqual(new DenseVector(new Scalar[] { 1, 2 }), matrix.ExtractRow(0)); CheckEqual(new DenseVector(new Scalar[] { 6, 5 }), matrix.ExtractRow(1)); CheckEqual(new DenseVector(new Scalar[] { 7, 9 }), matrix.ExtractRow(2)); } } public class MatrixMultiply : UnitTestSharp.TestFixture { public void x11() { RectangularMatrix a = new Scalar[,] { { 2 } }; RectangularMatrix b = new Scalar[,] { { 3 } }; RectangularMatrix c = new Scalar[,] { { 6 } }; CheckEqual(c, a.MatrixMultiply(b)); CheckEqual(c, b.MatrixMultiply(a)); } public void x22() { RectangularMatrix a = new Scalar[,] { { 2, 3 }, {4, -2} }; RectangularMatrix b = new Scalar[,] { { 7, 3 }, {1, 2} }; RectangularMatrix c = new Scalar[,] { { 17, 12 }, {26, 8} }; RectangularMatrix d = new Scalar[,] { { 26, 15 }, { 10, -1 } }; CheckEqual(c, a.MatrixMultiply(b)); CheckEqual(d, b.MatrixMultiply(a)); } public void WrongSize() { RectangularMatrix a = new Scalar[,] { { 2, 3 }, { 4, -2 } }; RectangularMatrix b = new Scalar[,] { { 1, 2 } }; CheckThrow(typeof(Exception)); a.MatrixMultiply(b); } public void DifferentSizes() { RectangularMatrix a = new Scalar[,] { { 2, 3 }, { 4, -2 } }; RectangularMatrix b = new Scalar[,] { { 1, 2 } }; RectangularMatrix c = new Scalar[,] { { 10, -1 } }; CheckEqual(c, b.MatrixMultiply(a)); } } } }