第四周小组作业:WordCount优化

软件质量测试wordCount优化

 

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

二、PSP表格

PSP2.1PSP阶段预估耗时(分钟)实际耗时(分钟)
· Planning · 计划 15 10
· Estimate · 估计这个任务需要多少时间 20 20
· Development · 开发 350 450
· Analysis · 需求分析 (包括学习新技术) 30 35
· Design Spec · 生成设计文档 10 5
· Design Review · 设计复审 (和同事审核设计文档) 5 5
· Coding Standard · 代码规范 (为目前的开发制定合适的规范) 20 20
· Design · 具体设计 40 65
· Coding · 具体编码 80 75
· Code Review · 代码复审 60 50
· Test · 测试(自我测试,修改代码,提交修改 150 180
· Reporting · 报告 100 80
· Test Report · 测试报告 40 60
· Size Measurement · 计算工作量 20 10
· Postmortem & Process Improvement Plan · 事后总结, 并提出过程改进计划 40 20
  · 合计 980 1085

三、接口实现

  我主要负责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个等价类

  保存成功 保存失败
输入参数正确 test1 test2
输入参数不正确 test3 test4

   

  测试脚本:

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不存在
    参数格式错误
    参数格式错误
    参数格式错误
    输出文件已存在

 

posted @ 2018-04-08 23:26  yeeeti  阅读(180)  评论(1编辑  收藏  举报