2015-05-07 实践作业2

一、题目简介  

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

二、源码的github链接

  https://github.com/15964218577/zuoye2

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

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

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

复制代码
 1     @Test
 2     public void tsetNullFile() throws IOException{
 3         File file =null;
 4         Deal dos = new Deal();
 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         Deal dos = new Deal();
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         Deal dos = new Deal();
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         Deal dos = new Deal();
 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("three");
 5         list.add("three");
 6         list.add("two");
 7         list.add("two");
 8         list.add("three");
 9         list.add("one");
10         list.add("one");
11         
12         Deal dos = new Deal();
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     }
复制代码

  该测试打印结果:

  three:3

      two:2

  one:2

  测试结果截图:

  

 

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

通过这次作业我学会了测试,感受到了测试的魅力,让我受益匪浅,在软件工程知识方面获得了以前学不到的知识,让我喜欢上了这个课程,我会认真学习这门课程的。

posted @ 2015-05-07 21:19  Bg丶王  阅读(123)  评论(2编辑  收藏  举报