我有一个带有一堆重载运算符的类:
public static double[,] operator +(Matrix matrix, double[,] array)
public static double[,] operator -(Matrix matrix, double[,] array)
public static double[,] operator *(Matrix matrix, double[,] array)
对于所有这些,我想测试操作数是否为空。我对此进行了NUnit
测试:
public void MatrixOperatorOperandIsNullThrows(Func<Matrix, double[,], double[,]> op)
{
Matrix m = null;
var right = new double[,] {{1, 1}, {1, 1}};
Assert.Throws<ArgumentException>(() => op(m, right));
}
如何为每个运算符传递一个 lambda,例如(l,r) => l + r
?