日期:2012-05-28  浏览次数:20399 次

 

用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