第4周小组作业:WordCountPro

1 github地址

https://github.com/wzfhuster/software_test_tasks

PSP表格 

PSP2.1

PSP阶段

预估耗时

(分钟)

实际耗时

(分钟)

Planning

计划

  

· Estimate

· 估计这个任务需要多少时间

 20 25

Development

开发

  

· Analysis

· 需求分析 (包括学习新技术)

 10 5

· Design Spec

· 生成设计文档

 20 25

· Design Review

· 设计复审 (和同事审核设计文档)

 15 15

· Coding Standard

· 代码规范 (为目前的开发制定合适的规范)

 5 10

· Design

· 具体设计

 10 10

· Coding

· 具体编码

 60 60

· Code Review

· 代码复审

 15 10

· Test

· 测试(自我测试,修改代码,提交修改)

 20 10

Reporting

报告

  

· Test Report

· 测试报告

 15 10

· Size Measurement

· 计算工作量

 5 5

· Postmortem & Process Improvement Plan

· 事后总结, 并提出过程改进计划

 10 10
 

合计

 235 190

3 接口实现

 本次作业我和李锋同学负责排序和输出模块,wcProOutput.java

输出模块接口 public static String output(Map<String, Integer> map,String filename)

wcProOutput传入的参数是统计了每个单词和单词对应的个数的map,对map进行排序后将单词统计结果按照要求写入指定的 result.txt 文件中

 

  通过ArrayList构造函数把map.entrySet()转换成list

       list = new ArrayList<Map.Entry<String, Integer>>(map.entrySet());

  通过比较器实现比较排序

          Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {
              public int compare(Map.Entry<String, Integer> map1, Map.Entry<String, Integer> map2) {
                    
                  //优先使用单词的个数由大到小的排序
                  if(map1.getValue()>map2.getValue()) 
                      return -1;
                  else if(map1.getValue()<map2.getValue()) 
                      return 1;
                  else //单词的词频相同时,按照单词字母排序
                      return map1.getKey().compareTo(map2.getKey());

  按照顺序写入文件,当单词个数超过100个时候,写入前100个

            for(;i<len-1&&i<99;i++)
            {
                w.write(list.get(i).getKey() + " " + list.get(i).getValue()+"\r\n\r\n");
                s+=(list.get(i).getKey() + " " + list.get(i).getValue()+" \n ");
            }
            //输出文件末尾多余的换行符应去除
            if(len>0)
            {
                w.write(list.get(i).getKey() + " " + list.get(i).getValue());
                s+=(list.get(i).getKey() + " " + list.get(i).getValue());
            }

4 测试用例

针对输出模块以及排序模块写了20个测试用例。因为这部分可写的测试用例较少,所以后面的测试代码测试的功能有一定重复,不再贴出

输出测试:

1 单词的词频从大到小

    @Test  
    public void testOutput1() {
        map.put("in", 80);
        map.put("this", 200);
        map.put("that", 60);
        map.put("i", 180);
        
        //预期输出的结果,不同单词和词频对之间用" \n "来隔开表示换行
        String expectResult = "this 200 \n i 180 \n in 80 \n that 60";
        
        //比较实际输出的结果和预期输出结果,判断输出是否正确
        assertEquals(expectResult,wcProOutput.output(map, "result1.txt"));
    }

2 单词的词频相同时,按照单词字母排序

    @Test  
    public void testOutput2() {
        map.put("in", 180);
        map.put("this", 200);
        map.put("that", 180);
        map.put("i", 180);
        String expectResult = "this 200 \n i 180 \n in 180 \n that 180";
        assertEquals(expectResult,wcProOutput.output(map, "result2.txt"));
    }

3 单词的词频相同时,按照单词字母排序

    public void testOutput4() {
        map.put("ins", 200);
        map.put("i", 345);
        map.put("ij", 180);
        map.put("ik", 180);
        String expectResult = "i 345 \n ins 200 \n ij 180 \n ik 180";
        assertEquals(expectResult,wcProOutput.output(map, "result4.txt"));
    }

4 输出文件已存在时,将覆盖原文件

   //testOutput9()和testOutput10()都输出到result9.txt
    @Test  
    public void testOutput9() {
        map.put("ia", 180);
        map.put("ib", 180);
        String expectResult = "ia 180 \n ib 180";
        assertEquals(expectResult,wcProOutput.output(map, "result9.txt"));
    }

    
    @Test  
    public void testOutput10() {
        map.put("asd", 200);
        map.put("dsd", 345);
        map.put("hy", 180);
        map.put("hh", 180);
        String expectResult = "dsd 345 \n asd 200 \n hh 180 \n hy 180";
        assertEquals(expectResult,wcProOutput.output(map, "result9.txt"));
    }

 

5 运行截图

 

 

 

6小组贡献

  0.2分

 

转载于:https://www.cnblogs.com/flyxie/p/8748071.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值