zoukankan      html  css  js  c++  java
  • 2015-04-24 实践作业2

    一、题目简介  

      写一个程序,计算出一组文本文档的英文单词的频率。

      练习的能力:

      回归测试,单元测试,性能分析,性能优化等基本源代码控制技能

    二、源码的github链接

      https://github.com/WreckBear/2ndHomeWork

    三、所设计的模块测试用例、测试结果截图

       本实现有三个方法,分别对三个方法做了测试:

      对获取文件中的字符串方法做的三项测试:

     1     @Test
     2     public void tsetNullFile() throws IOException{
     3         File file =null;
     4         DoSomething dos = new DoSomething();
     5         String result = dos.getString(file);
     6         assertNull(result);
     7     }
     8     
     9     @Test
    10     public void testNoContentFile() throws IOException {
    11         File file =new File("D:/Empty.txt");
    12         DoSomething dos = new DoSomething();
    13         String result = dos.getString(file);
    14         assertEquals("",result);
    15     }
    16     
    17     @Test
    18     public void testNormalFile() throws IOException {
    19         File file =new File("D:/Normal.txt");
    20         DoSomething dos = new DoSomething();
    21         String result = dos.getString(file);
    22         assertEquals("hello,my name is Matin,I am thirty-three years old.",result);
    23     }
     对提取单词的方法做了如下测试:
     1     @Test
     2     public void testTakeWord() throws IOException {
     3         File file =new File("D:/Normal.txt");
     4         DoSomething dos = new DoSomething();
     5         String str = dos.getString(file);
     6         List<String> result = dos.takeWord(str);
     7         for(String show:result){
     8             System.out.print(show);
     9         }
    10     }    

      该测试打印结果为:hello my name is Matin I am thirty three years old 

     对计算单词频率做了如下测试:

     1     @Test
     2     public void testFrequency() {
     3         List<String> list = new ArrayList<String>();
     4         list.add("hello");
     5         list.add("hello");
     6         list.add("bye");
     7         list.add("bye");
     8         list.add("hello");
     9         list.add("queue");
    10         list.add("hello");
    11         
    12         DoSomething dos = new DoSomething();
    13         HashMap map = dos.getFrequency(list);
    14         
    15         Iterator iter = map.entrySet().iterator();
    16         while (iter.hasNext()) {
    17             Map.Entry entry = (Map.Entry) iter.next();
    18             String key = (String) entry.getKey();
    19             int val = (Integer) entry.getValue();
    20             System.out.println(key+":"+val);
    21         }
    22     }

      该测试打印结果:

      hello:4

          queue:1

      bye:2

      测试结果截图:

      

    四、问题及解决方案、心得体会

      问题:

        从文章中获取单词的方法不完善,比如若文章中出现连续的非字符,可能获取单词就会被截止,该方法在继续完善。

      心得体会:

        虽然这次作业难度不大,不复杂,体会不出明显的测试所带来的效果,但也能清楚的感受到Junit给测试带来的便捷性,感叹Junit的简单之中的神奇。

       另外这次的测试作业也让自己测试有了个不同的理解,再也不是简单的写个mian方法测试一下,而是跟全面的去方法安全性和健壮性进行检测,不可不谓收货。

      

  • 相关阅读:
    React生命周期, 兄弟组件之间通信
    React组件式编程Demo-用户的增删改查
    React之this.refs, 实现数据双向绑定
    CCF CSP 201812-4 数据中心
    CCF CSP 201812-4 数据中心
    PAT 顶级 1020 Delete At Most Two Characters (35 分)
    PAT 顶级 1020 Delete At Most Two Characters (35 分)
    Codeforces 1245C Constanze's Machine
    Codeforces 1245C Constanze's Machine
    CCF CSP 201712-4 行车路线
  • 原文地址:https://www.cnblogs.com/WreckBear/p/4468928.html
Copyright © 2011-2022 走看看