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();  }

    }

  • 相关阅读:
    Suricata, to 10Gbps and beyond(X86架构)
    golang语法学习(一):变量,常量以及数据类型
    Linux相关问题-CentOS6.5 x64版本号下Tomcat无法自启动的解决的方法
    软考之路--你存在我深深的脑海里
    Apache虚拟主机-解惑篇
    Apache 性能调优-参考篇
    Jmeter脚本录制
    整理LVS架构压力测试工作
    关于jboss的线程问题+java.lang.outofmemoryError
    CUDA入门
  • 原文地址:https://www.cnblogs.com/Darlingtuan/p/5365843.html
Copyright © 2011-2022 走看看