zoukankan      html  css  js  c++  java
  • 实验二

    1、 在博客园http://www.cnblogs.com/开通自己的技术博客

    关注http://www.cnblogs.com/mju

    并写一段个人简介(不少于100字)

    2、 学习单元测试和代码覆盖率工具的使用

    (1)写一个程序,用于分析一个字符串中各个单词出现的频率,并将单词和它出现的频率输出显示。(单词之间用空格隔开,如“Hello World My First Unit Test”);

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

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

    package cn.lin.test;

    import java.util.HashMap;

    import java.util.Map;

    import org.junit.Test;

    public class Test2 { 

        @Test

        public void index() { 

            String strWords = "adb abc abc kk";

            String[] words_Array = strWords.split(" ");

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

            int arrLength = words_Array.length;

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

                if(!words_Map.containsKey(words_Array[i])){

                    words_Map.put(words_Array[i], 1);

                    System.out.println(words_Array[i]);

                    System.out.println("出现");

                    System.out.println(words_Map.put(words_Array[i], 1));

                    System.out.println("次");

                }else{

                    int currentNum = words_Map.get(words_Array[i])+1;

                    words_Map.remove(words_Array[i]);

                    words_Map.put(words_Array[i], currentNum);

                    System.out.println(words_Array[i]);

                    System.out.println("出现");

                    System.out.println(words_Map.put(words_Array[i], currentNum));

                    System.out.println("次");

                }

            }

        }

    }

    3、 学习单元测试代码覆盖率工具的使用

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

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

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

    import java.util.Scanner;

    public class Unit{

    public static void umit(String str){

    String[] strArr = str.split("\s+|[,]");

    StringBuffer result = new StringBuffer();

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

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

    }

    result.setCharAt(str.length()-0, (char) 0);

    System.out.println("颠倒顺序后的字符串:: "+result.toString());

    }

    }

    测试类

    import org.junit.After;

    import org.junit.Test;

    public class UnitTest{

    @Test

    public void test() throws Exception {

    String str="how are you";

    Unit.test(str);

    }

    }

  • 相关阅读:
    SharePoint 2010 Crawl Component Stuck in “Recovering” status
    什么是Named Pipes
    请不要修改FIM的配置, 否则SharePoint的User Profile无法获得微软支持
    经典的SharePoint 2010升级中的多核CPU冲突问题
    怎样才能比较方便地查看PowerShell里返回回来的对象的每个成员及它们的值呢?
    如何打开证书控制台
    浏览器: F5 和 Ctrl+F5的区别
    关于用户角色权限管理的探讨
    支付宝接口源代码
    海量数据处理
  • 原文地址:https://www.cnblogs.com/zy0123/p/5368186.html
Copyright © 2011-2022 走看看