static void Main() { Console.OutputEncoding = Encoding.UTF8; Console.Write(Messages.RequestHeightInput); var height = PromptUserMatrixDimension(); Console.Write(Messages.RequestWidthInput); var width = PromptUserMatrixDimension(); var matrix = new CustomMatrix(height, width); matrix.DisplayMatrix(); Console.WriteLine($"\n{Messages.MatrixTraceSum} {matrix.GetTraceSum()}"); }
public void CalculateTraceSumTest_ShouldReturnCorrectSumOfTraceElements(int height, int width) { var matrix = new CustomMatrix(height, width); int expected = 0; int shortestDimension = 0; if (height < width) { shortestDimension = height; } else { shortestDimension = width; } for (var i = 0; i < shortestDimension; i++) { expected += matrix.Matrix[i, i]; } var actual = matrix.GetTraceSum(); Assert.AreEqual(expected, actual); }