用c# 呵nunit 做开发呵测试工具
using system;
using system.collections;
using nunit.framework;
namespace cn.lovetyping.unittest
{
/// <summary>
/// sort 的摘要说明。
/// </summary>
///
[testfixture]
public class sort
{
/// <summary>
/// the orignal data which is used to compare with the new
/// data.if there is some data exist in the newdata but not in orignal data.
/// add it to the result.
/// </summary>
/// input:
/// <param name="orignal"></param>
/// <param name="newdata"></param>
/// output
/// <returns>arraylist</returns>
public arraylist sortdata(string[] orignal,string[] newdata)
{
arraylist result = new arraylist();
int oindex=0,nindex=0;
//according to the condition
while(oindex<orignal.length && nindex<newdata.length)
{
if(newdata[nindex].compareto(orignal[oindex]) <0)
{
result.add(newdata[nindex]);
nindex++;
}
else if(newdata[nindex].compareto(orignal[oindex]) ==0)
{
oindex++;nindex++;
}
else if(newdata[nindex].compareto(orignal[oindex]) > 0)
{
oindex++;
continue;
}
}
//if the
if(nindex == newdata.length || oindex< orignal.length)
{
return result;
}
else if( nindex < newdata.length)
{
while(nindex< newdata.length)
{
result.add(newdata[nindex++]);
}
}
return result;
}
[test]
public void testsort()
{
string[] code1 = new string[]{"0","4","6","9"};
string[] code2 = new string[]{"1","3","6","7","9","12"};
arraylist result = this.sortdata(code1,code2);
assert.istrue(result.count == 4);
for(int i=0;i<result.count;i++)
{
console.writeline(result[i]);
}
console.writeline("---------------another data------------");
code1 = new string[]{"0","4","6","9"};
code2 = new string[]{"1","3","6"};
result = this.sortdata(code1,code2);
assert.istrue(result.count == 2);
for(int i=0;i<result.count;i++)
{
console.writeline(result[i]);
}
console.writeline("---------------another data------------");
code1 = new string[]{"0","4","6","9"};
code2 = new string[]{"1","3","7"};
result = this.sortdata(code1,code2);
assert.istrue(result.count == 3);
for(int i=0;i<result.count;i++)
{
console.writeline(result[i]);
}
console.writeline("---------------another data------------");
code1 = new string[]{"0","11","13","3","3","9"};
code2 = new string[]{"1","11","15","16","19","3","7"};
result = this.sortdata(code1,code2);
assert.istrue(result.count == 5);
for(int i=0;i<result.count;i++)
{
console.writeline(result[i]);
}
}
}
}
新闻热点
疑难解答