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();
    }

五.运行截图

结果正常

六.小组贡献

原文地址:https://www.cnblogs.com/yigouxiansen/p/8744147.html

时间: 2024-08-01 00:26:55

WordCount小组作业的相关文章

第四周WordCount小组作业

一.基础功能 小组github地址:https://github.com/kawoyi/Advanced-WordCounter PSP表格: 接口的实现: 我实现的是单词的统计模块,由Counter类完成,其中最主要的功能是由analyse()函数完成功能是将分割出单词并且加入map中供输出结果 public void analyse()//主要功能实现 { strToken = ""; // 置strToken为空串 while (i < buffer.length()) {

第4周小组作业:WordCount优化

第4周小组作业:WordCount优化 一.基本任务:代码编写+单元测试 小组github 地址 https://github.com/iwannastay/WcPro PSP表格 PSP2.1 PSP阶段 预估耗时(分钟) 实际耗时(分钟) Planning 计划 30 60 Estimate 估计任务需要多少时间 30 60 Development 开发 180 240 Analysis 需求分析 20 30 Design Spec 生成设计文档 20 30 Design Review 设计

软件质量与测试第4周小组作业:WordCount优化

软件质量与测试第4周小组作业:WordCount优化 一.GitHub地址 https://github.com/fusidic/WC 二.PSP表格 PSP2.1 PSP阶段 预估耗时(分钟) 实际耗时(分钟) Planning 计划 30 20 · Estimate · 估计这个任务需要多少时间 30 20 Development 开发 470 550 · Analysis · 需求分析 (包括学习新技术) 30 20 · Design Spec · 生成设计文档 20 20 · Desig

软件测试第4周小组作业:WordCount优化

小组github地址 https://github.com/whoNamedCody/wcPro  基本任务 一.PSP表格 PSP2.1 PSP阶段 预估耗时 (分钟) 实际耗时 (分钟) Planning 计划  20  20 · Estimate · 估计这个任务需要多少时间  10  10 Development 开发  60  60 · Analysis · 需求分析 (包括学习新技术)  20  15 · Design Spec · 生成设计文档  50  60 · Design R

第4周小组作业 WordCount优化

github地址:https://github.com/husterC/WordCountGroupwork PSP表格 PSP2.1 PSP阶段 预估耗时 (分钟) 实际耗时 (分钟) Planning 计划  20  20 · Estimate · 估计这个任务需要多少时间  15  10 Development 开发  60  40 · Analysis · 需求分析 (包括学习新技术)  60  90 · Design Spec · 生成设计文档  -  - · Design Revie

第四周小组作业:WordCount优化

Github地址: https://github.com/skz12345/wcPro PSP表格: PSP PSP阶段 预估耗时(分钟) 实际耗时(分钟) Planning 计划 10 5 Estimate 估计这个任务需要多少时间 10 5 Development 开发 60 50 Analysis 需求分析(包括学习新技术) 5 5 Design Spec 生成设计文档 5 5 Design Review 设计复审(和同事审核文档) 5 5 Coding Standard 代码规范(为目前

Storm入门(四)WordCount示例

Storm API文档网址如下: http://storm.apache.org/releases/current/javadocs/index.html 一.关联代码 使用maven,代码如下. pom.xml  和Storm入门(三)HelloWorld示例相同 RandomSentenceSpout.java /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor lice

彻底解密WordCount运行原理(DT大数据梦工厂)

主要内容: 数据流动视角解密WordCount RDD依赖关系视角解密WordCount DAG与Lineage的思考 ==========数据流动视角============ 新建文件,里面输入 Hello Spark Hello Scala Hello Hadoop Hello Flink Spark is awesome 修改代码: package com.dt.spark.SparkApps.cores; import java.util.Arrays; import java.util

Spark入门之WordCount详细版

1 package cn.spark.study.core; 2 3 import java.util.Arrays; 4 5 import org.apache.spark.SparkConf; 6 import org.apache.spark.api.java.JavaPairRDD; 7 import org.apache.spark.api.java.JavaRDD; 8 import org.apache.spark.api.java.JavaSparkContext; 9 impo