我试图测试功能如何测试函数返回的IEnumerable <Integer>
public static IEnumerable<Integer> Divisors(Integer n)
{
int max = (int)System.Math.Sqrt(n);
if (n != 0)
yield return 1;
for (int i = 2; i <= max; i++)
if (n % i == 0)
yield return i;
}
,我需要写这样
[Test]
public void DivisorsTest()
{
Integer n = 0;
IEnumerable<Integer> expected = 0 ; //error
IEnumerable<Integer> actual;
actual = Science.Mathematics.NumberTheoryFunctions.Divisors(n);
Assert.AreEqual(expected, actual);
}
测试功能如何修改这条线测试输出我需要测试不仅是零的返回值
欢迎来到StackOverflow!为了将来的参考,一个写得很好(并且格式良好)的问题并不要求“即将可用”的答案将会更加有利。 – Donut 2010-12-17 21:37:59
顺便说一句,你使用的UT框架? NUnit,VS单元测试? – 2010-12-17 22:43:02
我正在使用NUnit框架 – Emykindman 2010-12-17 23:29:06