zoukankan      html  css  js  c++  java
  • 软件测试实验二

    1.(1)写一个程序,用于分析一个字符串中各个单词出现的频率,并将单词和它出现的频率输出显示。

     (2)编写单元测试进行测试;

       (3)用ElcEmma查看代码覆盖率,要求覆盖率达到100%。

    import java.util.HashMap;

    import java.util.Iterator;

    import java.util.Map;  

    public class one

    {

         private Map<String, Integer> wordsMap;  

        public one(String strWords)

       {

        wordsMap=this.getArray(strWords);

       }

    public Map<String,Integer> getArray(String strWords){  String[] wordsArray = strWords.split("\s");  

     Map<String, Integer> wordsMap=new HashMap<String, Integer>();

     int arrLength=wordsArray.length;  int currentNum=0;

     for(int i=0;i<arrLength;i++)

    {

      if("".equals(wordsArray[i].trim()))

    {  

    continue;

     }

     if(!wordsMap.containsKey(wordsArray[i]))

     {      wordsMap.put(wordsArray[i],1);  }

     else {

    currentNum=wordsMap.get(wordsArray[i])+1;  

    wordsMap.remove(wordsArray[i]);  

    wordsMap.put(wordsArray[i],currentNum);  }  

    }     

       return wordsMap;

     }  

    public void outputResult(){

     Iterator iterator=wordsMap.entrySet().iterator();

     while(iterator.hasNext())

    { Map.Entry entry=(Map.Entry)iterator.next();  

    System.out.println(entry.getKey()+"出现了"+entry.getValue());     }

     }  

    }

    --------------------------------------------------------------------------------------------------------------------------

    import static org.junit.Assert.*;

    import org.junit.Test;

    public class oneTest {

     public void test() {  

      String str="Whatever is worth doing is worth doing well";  

      one wordFreq=new one(str);  

       wordFreq.outputResult();  

     }

    }

    2.

    (1)把一个英语句子中的单词次序颠倒后输出。例如输入“how are you”,输出“you are how”;

    (2)编写单元测试进行测试;

    (3)用ElcEmma查看代码覆盖率,要求覆盖率达到100%

    public class two {  

     public String Bee(String str) {  

    String[] wordsArray = str.split("\s");  

    StringBuffer result = new StringBuffer();

     for(int i = wordsArray.length -1;i >=0; i--)

    {

         if("".equals(wordsArray[i].trim()))

        {  

       continue;

        }

     result.append(wordsArray[i] + " ");  

        }

     return result.toString();  

       }

    }

    ----------------------------------------------------------------------------------------

    public class two {  

     public String Bee(String str) {

     String[] wordsArray = str.split("\s");  

    StringBuffer result = new StringBuffer();

     for(int i = wordsArray.length -1;i >=0; i--)

    {

    if("".equals(wordsArray[i].trim()))

    {  

        continue;

     }  

       result.append(wordsArray[i] + " ");  

    }

        return result.toString();  }

    }

  • 相关阅读:
    mac下配置Node.js开发环境、express安装、创建项目
    基于bootstrap模态框的二次封装
    生成二维码、微信自定义分享到朋友圈、ipa不从应用商店安装
    浏览器设备判断
    微信浏览中的下载自动被拦截,加遮罩在浏览其中打开
    css:图标与文字对齐的两种方法
    js获取当前域名
    JS动态修改微信浏览器中的title
    UWP 播放直播流 3MU8
    vb6 读写文件
  • 原文地址:https://www.cnblogs.com/Darlingtuan/p/5365843.html
Copyright © 2011-2022 走看看