软件工程实践作业2

一、题目简介  

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

二、源码的github链接

  https://github.com/liuxu8257/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

  测试结果截图:

  

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

这次作业我学会了软件测试的一些操作,对软件测试有了初步的了解  激发了强烈的学习兴趣 以后会好好学习这么课程

原文地址:https://www.cnblogs.com/liuxu8257/p/4486292.html