public void ShouldReturnFalse4x3() { var sol = new ToeplitzMatrix(); Assert.IsFalse(sol.IsToeplitzMatrix(new[] { new[] { 1, 2, 3, 4 }, new[] { 5, 1, 2, 3 }, new[] { 9, 5, 2, 2 } })); Assert.IsFalse(sol.IsToeplitzMatrix(new[] { new[] { 1, 2, 3, 4 }, new[] { 5, 1, 5, 3 }, new[] { 9, 5, 1, 2 } })); Assert.IsFalse(sol.IsToeplitzMatrix(new[] { new[] { 1, 2, 3, 4 }, new[] { 5, 1, 2, 4 }, new[] { 9, 5, 1, 2 } })); Assert.IsFalse(sol.IsToeplitzMatrix(new[] { new[] { 1, 2, 3, 4 }, new[] { 5, 1, 2, 3 }, new[] { 9, 6, 1, 2 } })); }
public void ToeplitzMatrixTestMethod() { ToeplitzMatrix toeplitzMatrix = new ToeplitzMatrix(); int[,] matrix1 = { { 1, 2, 3, 4 }, { 5, 1, 2, 3 }, { 9, 5, 1, 2 } }; int[,] matrix2 = { { 1, 2 }, { 2, 2 } }; Assert.AreEqual(true, toeplitzMatrix.IsToeplitzMatrix(matrix1)); Assert.AreEqual(false, toeplitzMatrix.IsToeplitzMatrix(matrix2)); }
public void ShouldReturnTrue3x2() { var sol = new ToeplitzMatrix(); Assert.IsTrue(sol.IsToeplitzMatrix(new[] { new[] { 1, 2 }, new[] { 2, 1 }, new[] { 4, 2 } })); }
public void ToeplitzMatrixTest() { var toeplitzMatrix = new ToeplitzMatrix(); var matrix = new[] { new [] { 12, 23, -32 }, new [] { -20, 12, 23 }, new [] { 56, -20, 12 }, new [] { 38, 56, -20 } }; var actual = toeplitzMatrix.IsToeplitzMatrix(matrix); var expected = true; Assert.That(actual, Is.EqualTo(expected)); }
public void ShouldReturnTrue1x1() { var sol = new ToeplitzMatrix(); Assert.IsTrue(sol.IsToeplitzMatrix(new[] { new[] { 1 } })); Assert.IsTrue(sol.IsToeplitzMatrix(new[] { new[] { int.MinValue } })); }
public void ShouldReturnTrue4x3() { var sol = new ToeplitzMatrix(); var matrix = new[] { new[] { 1, 2, 3, 4 }, new[] { 5, 1, 2, 3 }, new[] { 9, 5, 1, 2 } }; var result = sol.IsToeplitzMatrix(matrix); Assert.IsTrue(result); }
public void ShouldReturnFalse2x2() { var sol = new ToeplitzMatrix(); Assert.IsFalse(sol.IsToeplitzMatrix(new[] { new[] { 1, 2 }, new[] { 2, 2 } })); Assert.IsFalse(sol.IsToeplitzMatrix(new[] { new[] { 1, 3 }, new[] { 2, 2 } })); }
private static void toep_cholesky_lower_test() //****************************************************************************80 // // Purpose: // // TOEP_CHOLESKY_LOWER_TEST tests TOEP_CHOLESKY_LOWER. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 28 January 2017 // // Author: // // John Burkardt // { double[] g = { 1.0, 0.0, 0.5, 0.5, -0.375, -0.375 }; const int n = 3; Console.WriteLine(""); Console.WriteLine("TOEP_CHOLESKY_LOWER_TEST"); Console.WriteLine(" TOEP_CHOLESKY_LOWER computes the lower Cholesky factor L"); Console.WriteLine(" of a positive definites symmetric Toeplitz matrix"); Console.WriteLine(" defined by a (2,N) array."); typeMethods.r8mat_print(2, n, g, " Compressed Toeplitz matrix G:"); double[] l = ToeplitzMatrix.toep_cholesky_lower(n, g); typeMethods.r8mat_print(n, n, l, " Computed lower Cholesky factor L:"); double[] b = typeMethods.r8mat_mmt_new(n, n, n, l, l); typeMethods.r8mat_print(n, n, b, " Product LL':"); }
private static void toeplitz_cholesky_upper_test() //****************************************************************************80 // // Purpose: // // TOEPLITZ_CHOLESKY_UPPER_TEST tests TOEPLITZ_CHOLESKY_UPPER. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 28 January 2017 // // Author: // // John Burkardt // { double[] a = { 1.0, 0.5, -0.375, 0.5, 1.0, 0.5, -0.375, 0.5, 1.0 }; const int n = 3; Console.WriteLine(""); Console.WriteLine("TOEPLITZ_CHOLESKY_UPPER_TEST"); Console.WriteLine(" TOEPLITZ_CHOLESKY_UPPER computes the upper Cholesky factor L"); Console.WriteLine(" of a positive definites symmetric Toeplitz matrix"); Console.WriteLine(" defined as an NxN array."); typeMethods.r8mat_print(n, n, a, " Toeplitz matrix A:"); double[] r = ToeplitzMatrix.toeplitz_cholesky_upper(n, a); typeMethods.r8mat_print(n, n, r, " Computed upper Cholesky factor R:"); double[] b = typeMethods.r8mat_mtm_new(n, n, n, r, r); typeMethods.r8mat_print(n, n, b, " Product R'R:"); }
private static void t_cholesky_lower_test() //****************************************************************************80 // // Purpose: // // T_CHOLESKY_LOWER_TEST tests T_CHOLESKY_LOWER. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 28 January 2017 // // Author: // // John Burkardt // { const int n = 3; double[] t = { 1.0, 0.5, -0.375 }; Console.WriteLine(""); Console.WriteLine("T_CHOLESKY_LOWER_TEST"); Console.WriteLine(" T_CHOLESKY_LOWER computes the lower Cholesky factor L"); Console.WriteLine(" of a positive definites symmetric Toeplitz matrix"); Console.WriteLine(" defined by the first row."); typeMethods.r8vec_print(n, t, " First row of Toeplitz matrix T:"); double[] l = ToeplitzMatrix.t_cholesky_lower(n, t); typeMethods.r8mat_print(n, n, l, " Computed lower Cholesky factor L:"); double[] b = typeMethods.r8mat_mmt_new(n, n, n, l, l); typeMethods.r8mat_print(n, n, b, " Product LL':"); }
public void TestToeplitzMatrix() { int testNum = 100000; int randNum = 5; Random random = new Random(); ToeplitzMatrix demo = new ToeplitzMatrix(); for (int i = 0; i < testNum; i++) { int width = random.Next(randNum) + 1; int height = random.Next(randNum) + 1; int[][] martix = new int[width][]; for (int j = 0; j < width; j++) { martix[j] = new int[height]; for (int k = 0; k < height; k++) { martix[j][k] = random.Next(2); } } var solution = demo.Solution(martix); var otherSolution = demo.OtherSolution(martix); _output.WriteLine($@" martix:{JsonConvert.SerializeObject(martix)} result:{solution} otherSolution:{otherSolution} "); Assert.Equal(solution, otherSolution); } }