private static void ValidateResult(int[,] input, int[,] expectedResult) { var size = input.GetLength(0); var result1 = new int[size, size]; var result2 = new int[size, size]; // Perform deep-copies of the original array for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { result1[i, j] = input[i, j]; result2[i, j] = input[i, j]; } } result1 = Question1_7.RotateMatrix(result1); Question1_7.RotateMatrixInPlace(result2); for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { Assert.AreEqual(expectedResult[i, j], result1[i, j]); Assert.AreEqual(expectedResult[i, j], result2[i, j]); } } }
public void InvalidInputsTest() { // Null matrix TestHelpers.AssertExceptionThrown(() => { Question1_7.RotateMatrix(null); }, typeof(ArgumentNullException)); TestHelpers.AssertExceptionThrown(() => { Question1_7.RotateMatrixInPlace(null); }, typeof(ArgumentNullException)); // Non-square matrix var matrix = new[, ] { { 1, 2, 3 }, { 4, 5, 6 } }; TestHelpers.AssertExceptionThrown(() => { Question1_7.RotateMatrix(matrix); }, typeof(ArgumentException)); TestHelpers.AssertExceptionThrown(() => { Question1_7.RotateMatrixInPlace(matrix); }, typeof(ArgumentException)); }