软件自动化测试中的代码覆盖率(上)

发表于:2009-12-22 11:02

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:Donjuan(CSDNBlog)    来源:51Testing软件测试网采编

查看代码覆盖率

  创建一个C#工程WildChar(无所谓是类型库工程还是命令行程序工程),假设我们要写一个将字符串按单词成对反转的程序。将下面的代码贴到工程的一个cs文件中:

  Program.cs

publicstaticstringReverseStringPair(stringinput)

{

   if(string.IsNullOrEmpty(input))

       thrownewArgumentNullException("input");

 

   char[] result =newchar[input.Length];

   intresultIter = 0;

 

   ReverseStringPairImp(input, 0, result, resultIter);

 

   returnnewstring(result);

}

 

privatestaticvoidReverseStringPairImp(stringinput,intinputIter,char[] result,intresultIter)

{

   // skip white space

   while(inputIter < input.Length && input[inputIter] ==' ') inputIter++;

 

   int[] indics =newint[2] {

       inputIter,// first word begin index,

       0// second word begin index

   };

 

   for(; inputIter < input.Length; ++inputIter)

   {

       if(input[inputIter] ==' ')

       {

           if(indics[1] == 0)

               indics[1] = -1;

           elseif(indics[1] > 0)

               break;

       }

       elseif(input[inputIter] !=' '&& indics[1] == -1)

           indics[1] = inputIter;

   }

 

   // copy second word, inputIter points to the end of second word

   if(indics[1] > 0)

   {

       for(inti = indics[1]; i < inputIter; ++i)

           result[resultIter++] = input[i];

 

       indics[1]--;

       // copy white space

       while(indics[1] >= 0 && input[indics[1]] ==' ')

           indics[1]--;

 

       result[resultIter++] =' ';

   }

   else

       indics[1] = input.Length - 1;

 

   // copy the first word

   for(inti = indics[0]; i <= indics[1]; ++i)

       result[resultIter++] = input[i];

 

   // next pair

   if(inputIter < input.Length)

   {

       result[resultIter++] =' ';

       ReverseStringPairImp(input, inputIter, result, resultIter);

   }

}

31/3123>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号