matrixwithtest/MatrixProject.Test/MatrixTest.cs

56 lines
1.4 KiB
C#
Raw Normal View History

2024-10-08 10:58:42 +00:00
using System.Reflection;
2024-10-08 10:42:11 +00:00
namespace MatrixProject.Test;
public class MatrixTest
{
[InlineData(10)]
[InlineData(5)]
[InlineData(2)]
[InlineData(3)]
[Theory]
public void CheckRowsBeforeInitMatrixWithRows(int size)
{
Matrix matrix = new Matrix(size);
Assert.Equal(size, matrix.Rows);
Assert.Equal(size, matrix.Columns);
}
[Fact]
public void CheckColumnsBeforeInitMatrix()
{
Matrix matrix = new Matrix();
Assert.Equal(5, matrix.Columns);
}
2024-10-08 10:58:42 +00:00
[Theory]
[MemberData(nameof(testTwoDimArray))]
public void CheckFillMatrixInDefaultConstructor(int row, int column, int fillNumber, double[,] testArray) {
2024-10-08 10:42:11 +00:00
2024-10-08 10:58:42 +00:00
Matrix matrix = new Matrix(row, column, fillNumber);
2024-10-08 10:42:11 +00:00
2024-10-08 10:58:42 +00:00
Assert.True(EqualsTwoDimArray(testArray, matrix));
}
2024-10-08 10:42:11 +00:00
2024-10-08 10:58:42 +00:00
public static TheoryData<int, int,int, double[,]> testTwoDimArray => new () {
{2, 2, 3, new double[,] { { 3, 3 }, { 3, 3 } } }
};
2024-10-08 10:42:11 +00:00
private bool EqualsTwoDimArray(double[,] testMatrix, Matrix matrix) {
if(testMatrix.GetLength(0) != matrix.Rows ||
testMatrix.GetLength(1) != matrix.Columns) return false;
for (int i = 0; i < matrix.Rows; i++)
{
for (int j = 0; j < matrix.Columns; j++)
{
if (testMatrix[i, j] != matrix[i, j]) return false;
}
}
return true;
}
}