public void TestSum_Of_Square_And_Diagonal_Matrix() { var squareMatrix = new SquareMatrix <int>(new int[] { 2, 4, 1, 4, 5, 5, 6, 3, 2 }); var diagonalMatrix = new DiagonalMatrix <int>(new int[] { 2, 4, 1 }); var expected = new SquareMatrix <int>(new int[] { 4, 4, 1, 4, 9, 5, 6, 3, 3 }); Assert.AreEqual(MatrixSum.Sum(squareMatrix, diagonalMatrix), expected); }
public void TestSum_Matrix_Type() { var squareMatrix = new SquareMatrix <int>(new int[] { 2, 4, 1, 4, 5, 5, 6, 3, 2 }); var diagonalMatrix = new DiagonalMatrix <int>(new int[] { 2, 4, 1 }); var symmetricMatrix = new SymmetricMatrix <int>(new int[3][] { new int[] { 1, 2, 3 }, new int[] { 2, 4, 5 }, new int[] { 3, 5, 6 } }); Assert.AreEqual(typeof(SquareMatrix <int>), MatrixSum.Sum(squareMatrix, diagonalMatrix).GetType()); Assert.AreEqual(typeof(DiagonalMatrix <int>), MatrixSum.Sum(diagonalMatrix, diagonalMatrix).GetType()); Assert.AreEqual(typeof(SymmetricMatrix <int>), MatrixSum.Sum(symmetricMatrix, symmetricMatrix).GetType()); Assert.AreEqual(typeof(SquareMatrix <int>), MatrixSum.Sum(diagonalMatrix, symmetricMatrix).GetType()); }
static void TestTaskExecuting() { Console.WriteLine("Hello World!"); var m = new MemoryQueue(); var mult = new MultiplyTask(new Inp { x = 4, y = 5 }); var mult2 = new MultiplyTask(new Inp { x = 4, y = 56 }); var add = new AddTask(new (5, 6)); var swap = new SwapTask(new ("abi", "naber")); var concat = new ConcatTask(new Inp2 { x = new List <string> { "f", "u", "r", "k", "a", "n" } }); var matrix = new Matrix(); matrix.nums = new int[100, 100]; var matrixSum = new MatrixSum(matrix); //TestClient(); m.Enqueue(mult.Serialize()); m.Enqueue(mult2.Serialize()); m.Enqueue(add.Serialize()); m.Enqueue(swap.Serialize()); m.Enqueue(concat.Serialize()); m.Enqueue(matrixSum.Serialize()); // normally these will happen in workers. workers will execute tasks and store their results in // result store. Client will have an TaskResult handle which will update its content when result is ready. // below res1 will be all client have. This program.cs is only for testing purposes normally workers and // client will be different processes. /* Normally it will look like this; * * For Client: * * TaskResult mult=new MultiplyTask(new Inp{x=4,y=5}); this will enqueue task, will get the handle from store(or somewhere else) * TaskResult.result == null => will be true until result is executed by some worker * * For workers: each worker will dequeue from TaskStore and push results to ResultStore like; * * ITask task = queue.Dequeue(); * task.Execute() * resultStore.SetResultOfTask(task); */ Console.WriteLine("tasks queued"); Console.WriteLine("task will be dequed. Now cleaning task registry to simulate a server..."); var registry = (ITaskRegistry)TaskRegistry.Instance; registry.Clear(); registry.DiscoverTasks(); for (long i = m.Length(); i > 0; i--) { string serialized = (string)m.Dequeue(); Console.WriteLine($"dequed task: {serialized}"); var task = new DefaultTaskDeserializer().Deserialize(serialized); Console.WriteLine("task is executing..."); task.Execute(); Console.WriteLine($"time elapsed: {task.GetTimeElapsed().Value.TotalMilliseconds} ms"); } var x = "x"; }
public static void Main(string[] args) { Queue <int> queue = new Queue <int>(7); queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); queue.Enqueue(4); queue.Enqueue(5); queue.Enqueue(6); queue.Enqueue(7); queue.Enqueue(8); queue.Enqueue(9); queue.Enqueue(10); queue.Enqueue(11); foreach (var i in queue) { Console.WriteLine(i); } Console.WriteLine(" "); queue.Clear(); queue.Enqueue(3); queue.Enqueue(5); queue.Enqueue(6); queue.Enqueue(7); foreach (var i in queue) { Console.WriteLine(i); } Console.WriteLine(" "); Console.WriteLine(queue.Peek()); SquareMatrix <int> a = new SquareMatrix <int>(new int[] { 2, 4, 1, 4, 5, 5, 6, 3, 2 }); Console.WriteLine("-------"); foreach (var item in a) { Console.WriteLine(item); } Console.WriteLine("-------"); Console.WriteLine(a.GetValue(1, 1)); a.SetValue(2, 2, 78); Console.WriteLine("-------"); foreach (var item in a) { Console.WriteLine(item); } Console.WriteLine(a.GetValue(2, 2)); DiagonalMatrix <int> a1 = new DiagonalMatrix <int>(new int[] { 2, 4, 1, 4 }); foreach (var item in a1) { Console.WriteLine(item); } SymmetricMatrix <int> a2 = new SymmetricMatrix <int>(new int[][] { new int[] { 1, 2, 3 } }); foreach (var item in a2) { Console.WriteLine(item); } SquareMatrix <int> b1 = new SquareMatrix <int>(new int[] { 2, 4, 1, 4, 5, 5, 6, 3, 2 }); DiagonalMatrix <int> b2 = new DiagonalMatrix <int>(new int[] { 2, 4, 1 }); var c = MatrixSum.Sum(b1, b2); foreach (var item in c) { Console.WriteLine(item); } }
static void Main(string[] args) { int[,] Matrix_1, Matrix_2; string[] FileString; int M1, N1 = 0, M2, N2; using (var file = new StreamReader(Path.GetFullPath("Inlet.txt"))) { int i; string[] Aux; string CheckString = ""; for (i = 0; ; i++) { CheckString = file.ReadLine(); if (CheckString == "------") { break; } N1 = CheckString.Split(' ').Length; } M1 = i; for (i = 0; !file.EndOfStream; i++) { CheckString = file.ReadLine(); } M2 = i; Aux = CheckString.Split(' '); N2 = Aux.Length; file.Close(); } using (var file = new StreamReader(Path.GetFullPath("Inlet.txt"))) { Matrix_1 = new int[M1, N1]; int i, j; for (i = 0; i < M1; i++) { FileString = file.ReadLine().Split(' '); for (j = 0; j < N1; j++) { Matrix_1[i, j] = int.Parse(FileString[j]); } } file.ReadLine(); Matrix_2 = new int[M2, N2]; for (i = 0; i < M2; i++) { FileString = file.ReadLine().Split(' '); for (j = 0; j < N2; j++) { Matrix_2[i, j] = int.Parse(FileString[j]); } } } Matrix Matrix1 = new Matrix(Matrix_1, M1, N1); Matrix Matrix2 = new Matrix(Matrix_2, M2, N2); Matrix MatrixSum, MatrixMultiplication, MatrixDifferent; MatrixSum = Matrix.Summ(Matrix1, Matrix2); MatrixDifferent = Matrix.Diff(Matrix1, Matrix2); MatrixMultiplication = Matrix.Multipication(Matrix1, Matrix2); Console.WriteLine("Сумма двух матриц: "); MatrixSum.PrintMatrix(); Console.WriteLine(); Console.WriteLine("Разность двух матриц: "); MatrixDifferent.PrintMatrix(); Console.WriteLine(); Console.WriteLine("Произведение двух матриц: "); MatrixMultiplication.PrintMatrix(); }