public void Add_SumOfTwoMatrices() { DiagonalMatrix <int> expectedMatrix = new DiagonalMatrix <int>( new int[][] { new int[] { 2, 0, 0 }, new int[] { 0, 12, 0 }, new int[] { 0, 0, 22 } } ); Func <int, int, int> sumFunc = (int x, int y) => x + y; DiagonalMatrix <int> resMatrix = matr1.Add(matr1, sumFunc); bool equalFlag = true; for (int i = 0; i < resMatrix.Size; i++) { for (int j = 0; j < resMatrix.Size; j++) { if (resMatrix[i, j] != expectedMatrix[i, j]) { equalFlag = false; } } } Assert.IsTrue(equalFlag); }
static void Main(string[] args) { int[,] first = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} }; int[,] second = { {1, 2, 3}, {2, 5, 6}, {3, 6, 9} }; int[,] third = { {1, 0, 0}, {0, 5, 0}, {0, 0, 9} }; SquareMatrix<int> matrix = new SquareMatrix<int>(3); SquareMatrix<int> lol1 = new SquareMatrix<int>(first); SymmetricMatrix<int> lol2 = new SymmetricMatrix<int>(second); DiagonalMatrix<int> lol3 = new DiagonalMatrix<int>(third); matrix.MatrixChange += ShowChanges; for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) matrix[i, j] = i*j; var lol4 = lol3.Add(lol1); System.Console.ReadLine(); }
public void Add_TwoDiagonalMatrices_ReturnDiagonalMatrix() { int[,] diagonal = new int[, ] { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } }; var first = new DiagonalMatrix <int>(diagonal); var second = new DiagonalMatrix <int>(diagonal); var result = first.Add(second); int[,] expectedValues = { { 2, 0, 0 }, { 0, 2, 0 }, { 0, 0, 2 } }; for (int i = 0; i < result.Size; i++) { for (int j = 0; j < result.Size; j++) { Assert.AreEqual(expectedValues[i, j], result[i, j]); } } }
public void ValidationTest_DiagonalPlusSquare_InvalidOperationException() { var matrix1 = new DiagonalMatrix <int>(2); var matrix2 = new SquareMatrix <int>(3); Assert.Throws <InvalidOperationException>(() => matrix1.Add(matrix2)); }
public void Add_DiagonalAndSymmetricalMatrices_ReturnSymmetricalMatrix() { var valuesForSymmetrical = new int[, ] { { 11, 2, -8 }, { 2, 2, 10 }, { -8, 10, 5 } }; var valuesForDiagonal = new int[, ] { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } }; var diagonalMatrix = new DiagonalMatrix <int>(valuesForDiagonal); var symmetricalMatrix = new SymmetricalMatrix <int>(valuesForSymmetrical); var expectedValues = new int[, ] { { 12, 2, -8 }, { 2, 3, 10 }, { -8, 10, 6 } }; var result = diagonalMatrix.Add(symmetricalMatrix); for (int i = 0; i < result.Size; i++) { for (int j = 0; j < result.Size; j++) { Assert.AreEqual(expectedValues[i, j], result[i, j]); } } }
public void Add_SymmetricalAndDiagonalMatrixes_WorksCorrectly() { var lhs = new DiagonalMatrix <int>(2); lhs[0, 0] = 1; lhs[1, 1] = 2; var rhs = new SymmetricMatrix <int>(2); rhs[0, 0] = -100; rhs[0, 1] = 1; rhs[1, 0] = 22; rhs[1, 1] = 50; var result = new SymmetricMatrix <int>(2); result[0, 0] = -99; result[0, 1] = 1; result[1, 0] = 22; result[1, 1] = 52; var actual = lhs.Add(rhs); for (int i = 0; i < result.Size; i++) { for (int j = 0; j < result.Size; j++) { Assert.AreEqual(result[i, j], actual[i, j]); } } }
public int[,] AddTestInt(int[,] elements) { var lhs = new DiagonalMatrix <int>(elements); var rhs = new DiagonalMatrix <int>(elements); lhs = lhs.Add(rhs) as DiagonalMatrix <int>; return(lhs?.ToArray()); }
public string[,] AddTestString(string[,] elements) { var lhs = new DiagonalMatrix <string>(elements); var rhs = new DiagonalMatrix <string>(elements); lhs = lhs.Add(rhs, (x, y) => x + y) as DiagonalMatrix <string>; return(lhs?.ToArray()); }
public void Add_IntDiagonalAndSymmetricMatrixes_ReturnesSymmetricMatrix() { var m1 = new DiagonalMatrix<int>(new int[][] { new int[] { 1, 0, 0 }, new int[] { 0, 1, 0 }, new int[] { 0, 0, 1 } }); var m2 = new SymmetricMatrix<int>(new int[][] { new int[] { 1, 4, 5 }, new int[] { 4, 2, 6 }, new int[] { 5, 6, 3 } }); dynamic actual = m1.Add(m2); Assert.IsTrue(actual is SymmetricMatrix<int>); }
public void Add_Diagonal_Tests() { DiagonalMatrix <int> lhs = new DiagonalMatrix <int>(diag); SquareMatrix <int> rhs1 = new SquareMatrix <int>(diag); DiagonalMatrix <int> rhs2 = new DiagonalMatrix <int>(diag); SymmetricMatrix <int> rhs3 = new SymmetricMatrix <int>(diag); int[,] expected = new int[, ] { { 2, 0, 0 }, { 0, 2, 0 }, { 0, 0, 2 } }; CollectionAssert.AreEqual(new SquareMatrix <int>(expected), lhs.Add(rhs1)); CollectionAssert.AreEqual(new DiagonalMatrix <int>(expected), lhs.Add(rhs2)); CollectionAssert.AreEqual(new SymmetricMatrix <int>(expected), lhs.Add(rhs3)); }
public void Add_DiagonalMatrices_DoubleSourceArray() { int[,] sourceArray = new int[,] { {1, 0}, {0, 4} }; DiagonalMatrix<int> lhs = new DiagonalMatrix<int>(sourceArray); DiagonalMatrix<int> rhs = new DiagonalMatrix<int>(sourceArray); lhs.Add(rhs); int[,] actual = lhs.Add(rhs).ToArray(); bool areDouble = true; for (int i = 0; i < sourceArray.GetLength(0); i++) for (int j = 0; j < sourceArray.GetLength(1); j++) areDouble &= (sourceArray[i, j] * 2) == actual[i, j]; Assert.IsTrue(areDouble); }
public void AddingDiagonalMatrix() { Matrix<int> m = new DiagonalMatrix<int>(new int[2][] { new int[2] { 1, 0 }, new int[2] { 0, 3 } }); Matrix<int> m1 = new DiagonalMatrix<int>(new int[2][] { new int[2] { 1, 0 }, new int[2] { 0, 3 } }); Matrix<int> m2 = m.Add(m1); Matrix<int> m3 = new SquareMatrix<int>(new int[2][] { new int[2] { 2, 0 }, new int[2] { 0, 6 } }); Assert.IsTrue(m2.Equals(m3)); }
public void Add_IntDiagonalAndSymmetricMatrixes_GivesCorrectValue() { var m1 = new DiagonalMatrix<int>(new int[][] { new int[] { 1, 0, 0 }, new int[] { 0, 1, 0 }, new int[] { 0, 0, 1 } }); var m2 = new SymmetricMatrix<int>(new int[][] { new int[] { 1, 4, 5 }, new int[] { 4, 2, 6 }, new int[] { 5, 6, 3 } }); dynamic actual = m1.Add(m2); var expected = new SymmetricMatrix<int>(new int[][] { new int[] { 2, 4, 5 }, new int[] { 4, 3, 6 }, new int[] { 5, 6, 4 } }); Assert.AreEqual(expected, actual); }
public void AdditionTest() { testMatrix = new DiagonalMatrix <float>(1, 2, 9); var square = new SquareMatrix <float>(3u, 5); var sum1 = testMatrix.Add(square); var sum2 = square.Add(testMatrix); Assert.IsInstanceOf(typeof(SquareMatrix <float>), sum1); Assert.IsInstanceOf(typeof(SquareMatrix <float>), sum2); CollectionAssert.AreEqual(sum1.GetElements(), sum2.GetElements()); CollectionAssert.AreEqual(new float[9] { 6, 5, 5, 5, 7, 5, 5, 5, 14 }, sum1.GetElements()); var symmetric = new SymmetricMatrix <float>(new float[3, 3] { { 3, 3, 3 }, { 3, 2, 2, }, { 3, 2, 1 } }); sum1 = testMatrix.Add(symmetric); sum2 = symmetric.Add(testMatrix); Assert.IsInstanceOf(typeof(SymmetricMatrix <float>), sum1); Assert.IsInstanceOf(typeof(SymmetricMatrix <float>), sum2); CollectionAssert.AreEqual(sum1.GetElements(), sum2.GetElements()); CollectionAssert.AreEqual(new float[9] { 4, 3, 3, 3, 4, 2, 3, 2, 10 }, sum1.GetElements()); var diagonal = new DiagonalMatrix <float>(3, 7); sum1 = testMatrix.Add(diagonal); sum2 = diagonal.Add(testMatrix); Assert.IsInstanceOf(typeof(DiagonalMatrix <float>), sum1); Assert.IsInstanceOf(typeof(DiagonalMatrix <float>), sum2); CollectionAssert.AreEqual(sum1.GetElements(), sum2.GetElements()); CollectionAssert.AreEqual(new float[9] { 8, 0, 0, 0, 9, 0, 0, 0, 16 }, sum1.GetElements()); Assert.Throws <InvalidOperationException>(() => diagonal.Add(new DiagonalMatrix <float>(2))); }
public void Add_DiagonalAddToDiagonalMatrixTests(DiagonalMatrix <int> firstMatrix, DiagonalMatrix <int> secondMatrix, DiagonalMatrix <int> expectedMatrix) { DiagonalMatrix <int> result = firstMatrix.Add(secondMatrix); for (int i = 0; i < result.Order; i++) { for (int j = 0; j < result.Order; j++) { Assert.AreEqual(expectedMatrix[i, j], result[i, j]); } } }
public void AddTestResultMatrixType() { var array = new[, ] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; AbstractSquareMatrix <int> matrix1 = new SquareMatrix <int>(array); AbstractSquareMatrix <int> matrix2 = new SquareMatrix <int>(array); var result = matrix1.Add(matrix2); Assert.AreEqual(typeof(SquareMatrix <int>), result.GetType()); matrix1 = new SquareMatrix <int>(array); matrix2 = new DiagonalMatrix <int>(array); result = matrix1.Add(matrix2); Assert.AreEqual(typeof(SquareMatrix <int>), result.GetType()); matrix1 = new SquareMatrix <int>(array); matrix2 = new SymmetricMatrix <int>(array); result = matrix1.Add(matrix2); Assert.AreEqual(typeof(SquareMatrix <int>), result.GetType()); matrix1 = new DiagonalMatrix <int>(array); matrix2 = new SquareMatrix <int>(array); result = matrix1.Add(matrix2); Assert.AreEqual(typeof(SquareMatrix <int>), result.GetType()); matrix1 = new DiagonalMatrix <int>(array); matrix2 = new DiagonalMatrix <int>(array); result = matrix1.Add(matrix2); Assert.AreEqual(typeof(DiagonalMatrix <int>), result.GetType()); matrix1 = new DiagonalMatrix <int>(array); matrix2 = new SymmetricMatrix <int>(array); result = matrix1.Add(matrix2); Assert.AreEqual(typeof(SymmetricMatrix <int>), result.GetType()); matrix1 = new SymmetricMatrix <int>(array); matrix2 = new SymmetricMatrix <int>(array); result = matrix1.Add(matrix2); Assert.AreEqual(typeof(SymmetricMatrix <int>), result.GetType()); matrix1 = new SymmetricMatrix <int>(array); matrix2 = new DiagonalMatrix <int>(array); result = matrix1.Add(matrix2); Assert.AreEqual(typeof(SymmetricMatrix <int>), result.GetType()); matrix1 = new SymmetricMatrix <int>(array); matrix2 = new SquareMatrix <int>(array); result = matrix1.Add(matrix2); Assert.AreEqual(typeof(SquareMatrix <int>), result.GetType()); }
public void Add_TwoDiagonalMatrices_ThrowsNotSupportedException() { var values = new string[, ] { { "1", null, null }, { null, "1", null }, { null, null, "1" } }; var first = new DiagonalMatrix <string>(values); var second = new DiagonalMatrix <string>(values); Assert.Throws <NotSupportedException>(() => first.Add(second)); }
public void AddExtensionsIntTests_Diagonal(int[] masA, int[] masB, int[] result) { var matrixA = new DiagonalMatrix <int>(masA); var matrixB = new DiagonalMatrix <int>(masB); var resultMatrix = new DiagonalMatrix <int>(result); matrixA.Add(matrixB); Console.WriteLine(matrixA); Console.WriteLine(resultMatrix); CollectionAssert.AreEquivalent(matrixA.InnerMatrix, resultMatrix.InnerMatrix); }
public void SumOfDiagonalMatrixes() { var fdm = new DiagonalMatrix <int>(firstDiagonalMatrix); var sdm = new DiagonalMatrix <int>(secondDiagonalMatrix); var result = fdm.Add(sdm); CollectionAssert.AreEqual(new int[, ] { { 2, 0, 0 }, { 0, 3, 0 }, { 0, 0, 4 } }, new int[, ] { { result[0, 0], result[0, 1], result[0, 2] }, { result[1, 0], result[1, 1], result[1, 2] }, { result[2, 0], result[2, 1], result[2, 2] } }); }
public void SumsTwoMatrixes_Successfully() { DiagonalMatrix <int> matr1 = new DiagonalMatrix <int>(new int[, ] { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } }); SymmetricalMatrix <int> matr2 = new SymmetricalMatrix <int>(new int[, ] { { 1, 3, 0 }, { 3, 2, 6 }, { 0, 6, 5 } }); SquareMatrix <int> res = matr1.Add(matr2); SquareMatrix <int> expectedRes = new SquareMatrix <int>(new int [, ] { { 2, 3, 0 }, { 3, 3, 6 }, { 0, 6, 6 } }); Assert.AreEqual(expectedRes, res); }
public void DiagonalMatrixTest() { DiagonalMatrix <int> dm1 = new DiagonalMatrix <int>(3, 6, 2, 1); DiagonalMatrix <int> dm2 = new DiagonalMatrix <int>(3, 6, 2, 1); BaseMatrix <int> dm3 = dm1.Add(dm2); int[,] matrix = dm3.Matrix; for (int i = 0; i < matrix.GetLength(0); i++) { for (int j = 0; j < matrix.GetLength(1); j++) { Console.Write(matrix[i, j] + " "); } Console.WriteLine(); } }
public void SumMatrixesTest_InputDiagonalMatrixAndDiagonal_AssertExpectedAndActualResult() { int[] firstArray = { 1, 2, 5 }; Martix <int> firstMatrix = new DiagonalMatrix <int>(3, firstArray); int[] secondArray = { 1, 2, 5 }; Martix <int> secondMatrix = new DiagonalMatrix <int>(3, secondArray); int[] expectedArray = { 2, 4, 10 }; var expectedMatrix = new DiagonalMatrix <int>(3, expectedArray); DiagonalMatrix <int> actualMatrix; actualMatrix = (DiagonalMatrix <int>)firstMatrix.Add <int>(secondMatrix); CollectionAssert.AreEqual(expectedMatrix, actualMatrix); }
public void AdditionTest() { matrix = new SymmetricMatrix <string>("sym1", "sym3", "sym3", "sym1"); var square = new SquareMatrix <string>(new string[2, 2] { { "sq1", "sq2" }, { "sq3", "sq4" } }); var sq1 = matrix.Add(square); var sq2 = square.Add(matrix); Assert.IsInstanceOf(typeof(SquareMatrix <string>), sq1); Assert.IsInstanceOf(typeof(SquareMatrix <string>), sq2); CollectionAssert.AreEqual(new string[4] { "sym1sq1", "sym3sq2", "sym3sq3", "sym1sq4" }, sq1.GetElements()); CollectionAssert.AreEqual(new string[4] { "sq1sym1", "sq2sym3", "sq3sym3", "sq4sym1" }, sq2.GetElements()); var symmetric = new SymmetricMatrix <string>(new string[2, 2] { { "1sym", "3sym" }, { "3sym", "1sym" } }); var sum1 = matrix.Add(symmetric); var sum2 = symmetric.Add(matrix); Assert.IsInstanceOf(typeof(SymmetricMatrix <string>), sum1); Assert.IsInstanceOf(typeof(SymmetricMatrix <string>), sum2); CollectionAssert.AreEqual(new string[4] { "sym11sym", "sym33sym", "sym33sym", "sym11sym" }, sum1.GetElements()); CollectionAssert.AreEqual(new string[4] { "1symsym1", "3symsym3", "3symsym3", "1symsym1" }, sum2.GetElements()); var diagonal = new DiagonalMatrix <string>(2, "DIAGONAL"); sum1 = sum1.Add(diagonal); sum2 = diagonal.Add(sum2); Assert.IsInstanceOf(typeof(SymmetricMatrix <string>), sum1); Assert.IsInstanceOf(typeof(SymmetricMatrix <string>), sum2); CollectionAssert.AreEqual(new string[4] { "sym11symDIAGONAL", "sym33sym", "sym33sym", "sym11symDIAGONAL" }, sum1.GetElements()); CollectionAssert.AreEqual(new string[4] { "DIAGONAL1symsym1", "3symsym3", "3symsym3", "DIAGONAL1symsym1" }, sum2.GetElements()); }
public void AddTest() { DiagonalMatrix<int> m1 = new DiagonalMatrix<int>(new int[] { 1, 5, 7 }, 3); DiagonalMatrix<int> m2 = new DiagonalMatrix<int>(new int[] { 9, 5, 3 }, 3); DiagonalMatrix<int> m3 = new DiagonalMatrix<int>(new int[] { 10, 10, 10 }, 3); m2.Add(m1); for (int i = 1; i <= m1.Size; i++) { for (int j = 1; j <= m1.Size; j++) { Assert.AreEqual(m2[i, j], m3[i, j]); } } }
public void SumTest_DiagonalPlusDiagonal_Diagonal() { var matrix1 = new DiagonalMatrix <int>(2); matrix1[0, 0] = 1; matrix1[1, 1] = 2; var matrix2 = new DiagonalMatrix <int>(2); matrix2[0, 0] = 1; matrix2[1, 1] = 2; matrix1.Add(matrix2); int[] array = { 2, 0, 0, 4 }; Assert.IsTrue(IsEqual(matrix1, array)); }
public void SumTest_DiagonalPlusSquare_Square() { var matrix1 = new DiagonalMatrix <int>(2); matrix1[0, 0] = 1; matrix1[1, 1] = 2; var matrix2 = new SquareMatrix <int>(2); matrix2[1, 0] = 2; matrix2[1, 1] = 2; var matrix = matrix1.Add(matrix2); int[] array = { 1, 0, 2, 4 }; AssertMatrixTest_MatrixAndExpectedResult(matrix, array); }
public void AdditionTest() { testMatrix = new SquareMatrix <int>(9, 8, 7, 6, 0, 4, 3, 2, 1); var square = new SquareMatrix <int>(1, 2, 3, 4, 10, 6, 7, 8, 9); var sum1 = testMatrix.Add(square); var sum2 = square.Add(testMatrix); Assert.IsInstanceOf(typeof(SquareMatrix <int>), sum1); Assert.IsInstanceOf(typeof(SquareMatrix <int>), sum2); CollectionAssert.AreEqual(sum1.GetElements(), sum2.GetElements()); CollectionAssert.AreEqual(Enumerable.Repeat(10, 9), sum1.GetElements()); var symmetric = new SymmetricMatrix <int>(new int[3, 3] { { 3, 3, 3 }, { 3, 2, 2, }, { 3, 2, 1 } }); sum1 = sum1.Add(symmetric); sum2 = symmetric.Add(sum2); Assert.IsInstanceOf(typeof(SquareMatrix <int>), sum1); Assert.IsInstanceOf(typeof(SquareMatrix <int>), sum2); CollectionAssert.AreEqual(sum1.GetElements(), sum2.GetElements()); CollectionAssert.AreEqual(new int[9] { 13, 13, 13, 13, 12, 12, 13, 12, 11 }, sum1.GetElements()); var diagonal = new DiagonalMatrix <int>(-13, -12, -11); sum1 = sum1.Add(diagonal); sum2 = diagonal.Add(sum2); Assert.IsInstanceOf(typeof(SquareMatrix <int>), sum1); Assert.IsInstanceOf(typeof(SquareMatrix <int>), sum2); CollectionAssert.AreEqual(sum1.GetElements(), sum2.GetElements()); CollectionAssert.AreEqual(new int[9] { 0, 13, 13, 13, 0, 12, 13, 12, 0 }, sum1.GetElements()); var matrix1 = new SquareMatrix <bool>(true); var matrix2 = new SquareMatrix <bool>(false); Assert.Throws <NotSupportedException>(() => matrix1.Add(matrix2)); }
public void MatrixAdd_Diagonal_Matrix() { int[,] matrixIn1 = { { 1, 0, 0, 0 }, { 0, 2, 0, 0 }, { 0, 0, 3, 0 }, { 0, 0, 0, 4 } }; int[,] matrixIn2 = { { 1, 0, 0, 0 }, { 0, 2, 0, 0 }, { 0, 0, 3, 0 }, { 0, 0, 0, 4 } }; int[,] result = { { 2, 0, 0, 0 }, { 0, 4, 0, 0 }, { 0, 0, 6, 0 }, { 0, 0, 0, 8 } }; var matrix1 = new DiagonalMatrix <int>(matrixIn1); var matrix2 = new DiagonalMatrix <int>(matrixIn2); Func <int, int, int> addFunc = (x1, x2) => x1 + x2; var sumMatrix = matrix1.Add(matrix2, addFunc); for (int i = 0; i < sumMatrix.Size; i++) { for (int j = 0; j < sumMatrix.Size; j++) { Assert.AreEqual(sumMatrix[i, j], result[i, j]); } } }
public void Add_CorrectMatrixesPassed_WorksCorrectly() { var lhs = new DiagonalMatrix <int>(2); lhs[0, 0] = 1; lhs[1, 1] = 2; var rhs = new DiagonalMatrix <int>(2); rhs[0, 0] = -100; rhs[1, 1] = 50; var result = new DiagonalMatrix <int>(2); result[0, 0] = -99; result[1, 1] = 52; var actual = lhs.Add(rhs); Assert.AreEqual(result[0, 0], actual[0, 0]); Assert.AreEqual(result[1, 1], actual[1, 1]); }
public void Add_DiagonalMatrixAndDiagonalMatrix_CorrectResult(int order, int[] values) { var matrix = new DiagonalMatrix <int>(order); matrix.Copy(values); int[] reverseValues = new int[values.Length]; Array.Copy(values, reverseValues, values.Length); Array.Reverse(reverseValues); var reverseMatrix = new DiagonalMatrix <int>(order); reverseMatrix.Copy(reverseValues); var actual = matrix.Add(reverseMatrix); int i = 0; foreach (var element in actual) { Assert.AreEqual(values[i] + reverseValues[i], element); i++; } }
static void Main(string[] args) { BinarySearchTree <int> intTree = new BinarySearchTree <int>(5); intTree.Add(new[] { 8, 10, 3, 2, 7, 6 }); foreach (var item in intTree.Inorder()) { Console.Write(item + " "); } Console.WriteLine(); BinarySearchTree <int> intTree2 = new BinarySearchTree <int>(5, new IntComparer()); intTree2.Add(new[] { 8, 10, 3, 2, 7, 6 }); foreach (var item in intTree2.Inorder()) { Console.Write(item + " "); } Console.WriteLine(); BinarySearchTree <string> stringTree = new BinarySearchTree <string>("5"); stringTree.Add(new[] { "8", "9", "3", "2", "7", "6" }); foreach (var item in stringTree.Inorder()) { Console.Write(item + " "); } Console.WriteLine(); BinarySearchTree <string> stringTree2 = new BinarySearchTree <string>("5", new Logic.Comparers.StringComparer()); stringTree2.Add(new[] { "8", "9", "3", "2", "7", "6" }); foreach (var item in stringTree2.Inorder()) { Console.Write(item + " "); } Console.WriteLine(); BinarySearchTree <Book> bookTree = new BinarySearchTree <Book>(new Book("Aaa", "Bbb", 102)); bookTree.Add(new [] { new Book("Ccc", "Aaa", 1356), new Book("Zzz", "Qqq", 803), new Book("Lll", "Bbb", 1234) }); foreach (var item in bookTree.Inorder()) { Console.Write("\"{0}\", {1}, {2}. ", item.Title, item.Author, item.Pages); } Console.WriteLine(); BinarySearchTree <Book> bookTree2 = new BinarySearchTree <Book>(new Book("Aaa", "Bbb", 102), new BookComparer()); bookTree2.Add(new[] { new Book("Ccc", "Aaa", 1356), new Book("Zzz", "Qqq", 803), new Book("Lll", "Bbb", 1234) }); foreach (var item in bookTree2.Inorder()) { Console.Write("\"{0}\", {1}, {2}. ", item.Title, item.Author, item.Pages); } Console.WriteLine(); BinarySearchTree <Point> pointTree = new BinarySearchTree <Point>(new Point(10, 12), new PointComparer()); pointTree.Add(new[] { new Point(10, 6), new Point(11, 2), new Point(94, 1), new Point(5, 11), new Point(99, 0) }); foreach (var item in pointTree.Inorder()) { Console.Write("X:{0}; Y:{1}. ", item.X, item.Y); } Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); SymmetricMatrix <int> symmatr1 = new SymmetricMatrix <int>(new int[, ] { { 0, 1, 2 }, { 1, 0, 3 }, { 2, 3, 0 } }); SymmetricMatrix <int> symmatr2 = new SymmetricMatrix <int>(new int[, ] { { 0, 1, 2 }, { 1, 0, 3 }, { 2, 3, 0 } }); Console.WriteLine(symmatr1.Add(symmatr2, (a, b) => a + b)); SquareMatrix <int> sqmatr = new SquareMatrix <int>(new int[, ] { { 2, 1, 7 }, { 1, 0, 3 }, { 2, 3, 8 } }); Console.WriteLine(sqmatr.Add(symmatr2, (a, b) => a + b)); DiagonalMatrix <int> dmatr = new DiagonalMatrix <int>(new int[, ] { { 0, 1, 7 }, { 1, 0, 3 }, { 2, 3, 0 } }); Console.WriteLine(dmatr.Add(symmatr2, (a, b) => a + b)); }
public void DiagonalMatrixIntegersSumTests(DiagonalMatrix <int> source1, DiagonalMatrix <int> source2, DiagonalMatrix <int> expected) => Assert.AreEqual(source1.Add(source2, new SumIntegers()), expected);
public void DiagonalMatrixStringsSumTests(DiagonalMatrix <string> source1, DiagonalMatrix <string> source2, DiagonalMatrix <string> expected) => Assert.AreEqual(source1.Add(source2, new SumStrings()), expected);