WordCount小组作业

一.github地址

https://github.com/Adogssky/WordCountGroupWork

 

二.psp表格

PSP2.1表格

PSP2.1

PSP阶段

预估耗时

(分钟)

实际耗时

(分钟)

Planning

计划

   

· Estimate

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

425  400

Development

开发

   

· Analysis

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

 30  30

· Design Spec

· 生成设计文档

 60 45 

· Design Review

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

 30 20 

· Coding Standard

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

 30 30 

· Design

· 具体设计

 30 30 

· Coding

· 具体编码

 45 30 

· Code Review

· 代码复审

 30 30 

· Test

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

 60 75 

Reporting

报告

   

· Test Report

· 测试报告

 60 45 

· Size Measurement

· 计算工作量

 20 20 

· Postmortem & Process Improvement Plan

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

 30 30 
 

合计

 425 400 

 

三.接口实现

个人任务为输出模块的编码,以及整合所有模块。

首先是输出模块

public class WCoutput {
    //输出文件
    public static void writeFile(String outputFileContent) throws IOException 
    {
        String outputFilePath = "result.txt";
        try {  
            File file = new File(outputFilePath);  
            if (!file.exists()) {  
                file.createNewFile();  
            } 
            FileWriter fw = new FileWriter(outputFilePath, true);  
            BufferedWriter bw = new BufferedWriter(fw);
            bw.write(outputFileContent);
            bw.close();
            fw.close(); 
        } catch (FileNotFoundException e) {   
            e.printStackTrace();  
        }        
    }

输出模块分为两个部分,也就是两个函数。

第一个函数是将输出内容写入文件函数,也就是通过文件流,打开文件,并写入内容,result.txt不存在时,则新建 文件。

//输出文件内容构造
    public static String contentConstruct(List<Map.Entry<String, Integer>> list) throws IOException 
    {
        String outputFileContent = "";
        for(Map.Entry<String,Integer> entry: list)
        {
            outputFileContent += entry.getKey() + " " + entry.getValue() + "\r\n";
        }    
        return outputFileContent;
    }

第二个函数就是输出到文件的内容的构造,通过接收之前的词频统计传过来的内存map的动态数组,将其中的词频遍历输出,并且构造格式,最后整合为输出内容。

然后是整合模块。

public class Main {
    static ArrayList<String> postSplit;
    static String outputContent;
    public static void main(String args[]) throws Exception 
    {
        
        WCinpute inputPart = new WCinpute();   
        WCwordsplit wordSplitPart = new WCwordsplit();
        WCoutput outputPart = new WCoutput();
        WCwordcount wordCountPart = new WCwordcount();
        postSplit = wordSplitPart.split(inputPart.inpute(args));
        wordCountPart.setInput(postSplit);
        wordCountPart.count();
        outputContent = outputPart.contentConstruct(wordCountPart.list);
        outputPart.writeFile(outputContent);
    }
}

整合模块既是将所有模块通过新建类,实例化的方式引用接口模块,最后完成任务。

四.测试用例

因为我负责的是输出和整合模块,整合模块不便测试,所以主要测试输出模块,输出模块因为没有条件判断,为顺序执行,无法 覆盖所有用例,所以皆为黑盒测试。

将所有测试分为了四个部分

测试之前有测试参数的初始化

//构造文件测试参数
    static Map<String,Integer> map = new HashMap<String,Integer>();
    static List<Map.Entry<String, Integer>> list = new ArrayList<>();
    static InputStreamReader inputStreamreader;
    static BufferedReader bufferReader;

 

一为单一测试输出函数

@Test
    //写文件测试1
    void testWriteFile_1() throws IOException {
        WCoutput.writeFile("fda");
        
    }
    
    
    //写文件测试2
    @Test
    void testWriteFile_2() throws IOException {
        WCoutput.writeFile("1");
        
    }
    
    //写文件测试3
    @Test
    void testWriteFile_3() throws IOException {
        WCoutput.writeFile("1");
        WCoutput.writeFile("eqwe");
        
    }
    
    
    //写文件测试4
    @Test
    void testWriteFile_4() throws IOException {
        WCoutput.writeFile("1fafaf");
    }
    
    //写文件测试5
    @Test
    void testWriteFile_5() throws IOException {
        WCoutput.writeFile("s");
        
    }

包括了多行输出,字符,整型输出

然后是文件构造的测试

//文件构造测试1
    @Test
    void testContentConstruct_1() throws IOException {
        map.put("sa",1);
        for(Map.Entry<String, Integer> entry : map.entrySet()){
            list.add(entry); 
       }
        WCoutput.contentConstruct(list);
        
    }

    //文件构造测试2
    @Test
    void testContentConstruct_2() throws IOException {
        map.put(" ",1);
        for(Map.Entry<String, Integer> entry : map.entrySet()){
            list.add(entry); 
       }
        WCoutput.contentConstruct(list);
    }
    
    //文件构造测试3
    @Test
    void testContentConstruct_3() throws IOException {
        map.put("sa",1);
        map.put("dad", 2);
        for(Map.Entry<String, Integer> entry : map.entrySet()){
            list.add(entry); 
       }
        WCoutput.contentConstruct(list);
        
    }
    //文件构造测试4
    @Test
    void testContentConstruct_4() throws IOException {
        map.put("sa",1);
        map.put("mp", 1);
        for(Map.Entry<String, Integer> entry : map.entrySet()){
            list.add(entry); 
       }
        WCoutput.contentConstruct(list);
    }
    
    //文件构造测试5
    @Test
    void testContentConstruct_5() throws IOException {
        map.put("sa",1);
        map.put("cm", 1);
        for(Map.Entry<String, Integer> entry : map.entrySet()){
            list.add(entry); 
       }
        WCoutput.contentConstruct(list);        
    }

进行多种文件构造,多方面测试

第三部分为综合测试,既是两个函数的综合测试

    //综合测试1
    @Test
    void testAll_1() throws IOException {
        String outputFileContent;
        map.put("sa",1);
        map.put("cm", 1);
        for(Map.Entry<String, Integer> entry : map.entrySet()){
            list.add(entry); 
       }
        outputFileContent = WCoutput.contentConstruct(list);    
        WCoutput.writeFile(outputFileContent);
    }

    //综合测试2
    @Test
    void testAll_2() throws IOException {
        String outputFileContent;
        map.put("sa",1);
        map.put("mp", 1);
        for(Map.Entry<String, Integer> entry : map.entrySet()){
            list.add(entry); 
       }
        outputFileContent = WCoutput.contentConstruct(list);    
        WCoutput.writeFile(outputFileContent);
    }
    
    //综合测试3
    @Test
    void testAll_3() throws IOException {
        String outputFileContent;
        map.put(" ", 1);
        for(Map.Entry<String, Integer> entry : map.entrySet()){
            list.add(entry); 
       }
        outputFileContent = WCoutput.contentConstruct(list);    
        WCoutput.writeFile(outputFileContent);
    }

最后一部分是打开结果文件,观察测试结果

//读文件比较
    @Test
    void testReadFile() throws IOException {
        File file = new File("result.txt"); 
        inputStreamreader = new InputStreamReader(new FileInputStream(file));
        bufferReader = new BufferedReader(inputStreamreader);
        String s;
        while ((s = bufferReader.readLine()) != null) {
            System.out.println(s);
            }     
        inputStreamreader.close();
        bufferReader.close();
    }

 

 测试清单

 

五.运行截图

结果正常

 

六.小组贡献

 赵一帆:0.3

游晨宇:0.26

何思聪:0.22

邹会江:0.22

 

扩展任务

七.规范理解

开发文档:《阿里巴巴Java开发手册

https://files.cnblogs.com/files/han-1034683568/%E9%98%BF%E9%87%8C%E5%B7%B4%E5%B7%B4Java%E5%BC%80%E5%8F%91%E6%89%8B%E5%86%8C%E7%BB%88%E6%9E%81%E7%89%88v1.3.0.pdf

 

其中指出:

可以看到采用==来进行判断时,有可能导致堆上产生,我自己写的代码中也有这种问题。

八.代码评价分析

评价对象:邹会江  17113 负责模块:输入模块

并没有按照规范采用equals方法比较,有可能产生问题,且编码中缺少注释,建议加上注释。

九.静态代码分析工具

checkstyle

下载地址:https://sourceforge.net/projects/checkstyle/files/checkstyle/

十.分析结果截图

 

 

十一.小组代码问题

小组中除了游晨宇同学以外判断都没有采用equals方法,且都缺少注释,建议修改。

 

posted @ 2018-04-08 12:15  一狗先森  阅读(312)  评论(1编辑  收藏  举报