第四周小组作业:WordCount优化

本文介绍了一个WordCount程序的优化过程,包含需求分析、设计、编码、测试等阶段,并详细展示了main函数的实现代码及测试用例。通过白盒测试和黑盒测试验证了程序的稳定性。

软件质量测试wordCount优化

 

一、github项目地址:https://github.com/XueRui97/WordCountPro

二、PSP表格

PSP2.1PSP阶段预估耗时(分钟)实际耗时(分钟)
· Planning· 计划1510
· Estimate· 估计这个任务需要多少时间2020
· Development· 开发350450
· Analysis· 需求分析 (包括学习新技术)3035
· Design Spec· 生成设计文档105
· Design Review· 设计复审 (和同事审核设计文档)55
· Coding Standard· 代码规范 (为目前的开发制定合适的规范)2020
· Design· 具体设计4065
· Coding· 具体编码8075
· Code Review· 代码复审6050
· Test· 测试(自我测试,修改代码,提交修改150180
· Reporting· 报告10080
· Test Report· 测试报告4060
· Size Measurement· 计算工作量2010
· Postmortem & Process Improvement Plan· 事后总结, 并提出过程改进计划4020
 · 合计9801085

三、接口实现

  我主要负责main函数模块。通过调用输入,输出,以及核心模块来实现完整的功能。

四、程序设计实现

  main函数部分代码:

  处理stoplist部分代码

boolean  isout = false,hassl = false;
int eind=-100;
boolean[] para= {true,true,true,false};
ArrayList parachar = new ArrayList();        //keep the load-in parameters in this arr
ArrayList<String> printarr = new ArrayList<String>();
ArrayList<outfile> filearr = new ArrayList<outfile>();    
ArrayList<doc> docarr = new ArrayList<doc>();    //keep the unoutput-to-file doc
outdoc outdocarr = new outdoc();            //a pointer to the current outdoc
for(int i=0;i<args.length;i++){
    if(args[i].charAt(0)=='-'&&args[i].charAt(1)=='e'){        //para is -e
        if(args[i+1].charAt(0)=='-'||args[i+1].charAt(0)=='*')
            throw new Exception("no filename after -e");
        if(hassl ==true)
            throw new Exception("already have a stoplist");
        eind = i;                        //pass the stoplist
        hassl =true;
        String stopstr = readFileByChars(args[i+1]);
        String[] stoparr = stopstr.split(" ");
        doc.stoplist = stoparr;
    }
}

  保存文件代码:

if(hassl&&(i==eind||i==eind+1))            //pass the stoplist
    continue;
if(args[i].charAt(0)=='-'){            //it's a parameter
    if(args[i].length()!=2)
        throw new Exception("a para after a -");
    if(args[i].charAt(1)=='e'){        //para is -e
        throw new Exception("it shouldn't happen");
    }
    else if(args[i].charAt(1)=='o'){    //参数是-o
        isout= true;
        if(i-1<0)                //first param can't be -o
            throw new Exception("-o as the first para");
        if(i+1>=args.length)
            throw new Exception("-o as the last para");
        if(args[i+1].charAt(0)=='-'||args[i-1].charAt(0)=='-')//the para before 
                                                // or after must be filename
            throw new Exception("no filename after||before -o");
        if(docarr.size()==0)                //has to have at least one filename message
            throw new Exception("no file message to write!");
        docarr.clear();
    }
    else{                        //参数不是-o
        parachar.add(args[i].charAt(1));
    }
}

 

五、测试用例

  白盒测试:

  白盒测试原理:白盒测试的测试方法有代码检查法、静态结构分析法、静态质量度量法、逻辑覆盖法、基本路径测试法、域测试、符号测试、路径覆盖和程序变异。白盒测试法的覆盖标准有逻辑覆盖、循环覆盖和基本路径测试。其中逻辑覆盖包括语句覆盖、判定覆盖、条件覆盖、判定/条件覆盖、条件组合覆盖和路径覆盖。六种覆盖标准发现错误的能力呈由弱到强的变化:

  1. 语句覆盖每条语句至少执行一次。

  2. 判定覆盖每个判定的每个分支至少执行一次。

  3. 条件覆盖每个判定的每个条件应取到各种可能的值。

  4. 判定/条件覆盖同时满足判定覆盖条件覆盖。

  5. 条件组合覆盖每个判定中各条件的每一种组合至少出现一次。

  6. 路径覆盖使程序中每一条可能的路径至少执行一次。

  流程图:

  路径:一共有3条路径 

  A->B->C->D->F       wc input.txt -e stoplist.txt 

  A->B->C->E->F  wc input.txt -e stoplist.txt -o output.txt

  A->B->F      wc inout.txt -e,    wc -e stoplist.txt -o output.txt

 

  黑盒测试:

  划分为4个等价类

 保存成功保存失败
输入参数正确test1test2
输入参数不正确test3test4

   

  测试脚本:

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

public class MainTest {

    System.out.println(maintest.("input.txt -e stoplist.txt -o output.txt"));
    System.out.println(maintest.("input.txt -e stoplist.txt -o "));
    System.out.println(maintest.("input.txt -e stoplist.txt"));
    System.out.println(maintest.("nonexist.txt -e stoplist.txt -o output.txt"));
    System.out.println(maintest.("input.txt -e nonexist.txt -o output.txt"));
    System.out.println(maintest.("input.txt -e output.txt"));
    System.out.println(maintest.("input.txt -e -o output.txt"));
    System.out.println(maintest.("-e input.txt -o output.txt"));
    System.out.println(maintest.("-e -o output.txt"));
    System.out.println(maintest.("input.txt -e stoplist.txt -o input.txt"));
}

  测试输出结果:

    保存成功
    参数格式错误
    保存成功
    输入文件不存在
    stoplist不存在
    stoplist不存在
    参数格式错误
    参数格式错误
    参数格式错误
    输出文件已存在

 

转载于:https://www.cnblogs.com/yeeeti/p/8748779.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值