using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using System.IO;namespace NunitTest
{
public class MathCompute
{
public int Largest(int[] array)
{
if (null == array || 0 == array.Length)
{
throw new Exception("参数传递错误@!!!!!");
}
int largest = Int32.MinValue;
foreach (int element in array)
{
if (element > largest)
{
largest = element;
}
}
return largest; }
}
[TestFixture]
public class TestMathCompute
{
private MathCompute mc;
[TestFixtureSetUp]
public void init()
{
mc = new MathCompute();
}
[Test]
public void TestLargest()
{
StreamReader sr = new StreamReader("../../DataSet.txt"); string line = null; while (null != (line = sr.ReadLine()))
{
if (line.StartsWith("#"))
{
continue;
}
string[] tokens = line.Split(null); int expected = Int32.Parse(tokens[0]); List<int> list = new List<int>(); for (int i = 1; i < tokens.Length; ++i)
{
list.Add(Int32.Parse(tokens[i]));//运行时这里提示输入字符串的格式不正确!!请问问题在哪儿?
} int[] input = list.ToArray(); Assert.AreEqual(expected, mc.Largest(input));
}
} }
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using System.IO;namespace NunitTest
{
public class MathCompute
{
public int Largest(int[] array)
{
if (null == array || 0 == array.Length)
{
throw new Exception("参数传递错误@!!!!!");
}
int largest = Int32.MinValue;
foreach (int element in array)
{
if (element > largest)
{
largest = element;
}
}
return largest; }
}
[TestFixture]
public class TestMathCompute
{
private MathCompute mc;
[TestFixtureSetUp]
public void init()
{
mc = new MathCompute();
}
[Test]
public void TestLargest()
{
StreamReader sr = new StreamReader("../../DataSet.txt"); string line = null; while (null != (line = sr.ReadLine()))
{
if (line.StartsWith("#"))
{
continue;
}
string[] tokens = line.Split(null); int expected = Int32.Parse(tokens[0]); List<int> list = new List<int>(); for (int i = 1; i < tokens.Length; ++i)
{
list.Add(Int32.Parse(tokens[i]));//运行时这里提示输入字符串的格式不正确!!请问问题在哪儿?
} int[] input = list.ToArray(); Assert.AreEqual(expected, mc.Largest(input));
}
} }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using System.IO; namespace NunitTest
{
public class MathCompute
{
public int Largest(int[] array)
{
if (null == array || 0 == array.Length)
{
throw new Exception("参数传递错误@!!!!!");
}
int largest = Int32.MinValue;
foreach (int element in array)
{
if (element > largest)
{
largest = element;
}
}
return largest; }
}
[TestFixture]
public class TestMathCompute
{
private MathCompute mc;
[TestFixtureSetUp]
public void init()
{
mc = new MathCompute();
}
[Test]
public void TestLargest()
{
StreamReader sr = new StreamReader("../../DataSet.txt"); string line = null; while (null != (line = sr.ReadLine()))
{
if (line.StartsWith("#"))
{
continue;
}
string[] tokens = line.Split(null); int expected = Int32.Parse(tokens[0]); List <int> list = new List <int>(); for (int i = 1; i < tokens.Length; ++i)
{
list.Add(Int32.Parse(tokens[i]));//运行时这里提示输入字符串的格式不正确!!请问问题在哪儿?
} int[] input = list.ToArray(); Assert.AreEqual(expected, mc.Largest(input));
}
} }
}