wordCount-软测作业

1.github地址 https://github.com/zgwe/wordCount

2.

PSP2.1

PSP阶段

预估耗时

实际耗时

(分钟)

(分钟)

Planning

计划

 10

 10

· Estimate

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

 20

 10

Development

开发

 40

 60

· Analysis

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

 60

180

· Design Spec

· 生成设计文档

 60

 100

· Design Review

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

 40

 60

· Coding Standard

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

 60

 60

· Design

· 具体设计

 300

 420

· Coding

· 具体编码

 360

 480

· Code Review

· 代码复审

 50

 80

· Test

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

 100

 120

Reporting

报告

40

 80

· Test Report

· 测试报告

 40

 80

· Size Measurement

· 计算工作量

 20

 10

· Postmortem & Process Improvement Plan

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

 30

 30

合计

 1230

 1780

 3.解题思路

题目是做一个类词法解析器,对目标文件进行读入,计数。

思路是接收到目标文件后,对该文件进行处理,得出所有要求的行数,单词数,字符数等,之后根据参数判断输出内容,并输出到结果文件中。

对目标文件的处理,也是词法分析器的基本功能,-a,-w,-l,-c,-o,都是判断计数的过程,

-s,-e网上找到的参考,链接如下

https://www.cnblogs.com/azhqiang/p/4596793.html JAVA 遍历文件夹下的所有文件

https://blog.csdn.net/yoany/article/details/41216715 文本分类实验中用java实现取名词和去除停用词

4.程序设计实现过程

代码组织;

最开始的设想是有3个类,wordcount,test,getargs,其中wordcount类是功能承担类,所有-a,-w,-l,-c,-o在wordcount中完成,test类作为程序入口,调用wordcount,getargs中的方法,getargs类是对参数处理的类。

代码编写中把getargs整合到test类中了,就是test类和wordcount类进行调用传参。

test类:方法:mian()方法(代码说明中介绍)

wordcount类 方法:wordcount()构造函数;init()初始化方法;

         setfile(),setfile2(),getchar(),getword(),getline(),getmore(),getter和setter方法

          print()输出方法

5.代码说明

main函数简易流程图:

代码:

接收args参数  
//main函数执行基本功能
wordCount a=new wordCount(argR.get(0),argR.get(1)); if(argR2.contains("c")){ //do c a.getchar(); } if(argR2.contains("w")){ //do w a.getword(); } if(argR2.contains("l")){ //do l a.getline(); } if(argR2.contains("a")){ //do a a.getmore(); } if(argR2.contains("o")){ //do o try { a.print(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
try{  //对文件进行统计
         
            File file=new File(name);  
            BufferedReader br= new BufferedReader(new FileReader(file));  
            String str = null;  
              
            while((str=br.readLine())!=null){  
                 
         
                
                countChar += str.length();//字符个数就是字符长度
                countWord += str.split(",| ").length;//split() 方法用于把一个字符串分割成字符串数组,字符串数组的长度,就是单词个数
                countLine++;//因为是按行读取,所以每次增加一即可计算出行的数目
                
                str = str.trim();   
                
                if (str.matches("\s*.?\s*")) {   
                    whiteLine++;   
                } else if (str.startsWith("/*") && !str.endsWith("*/")) {   
                    commentLine++;   
                    comment = true;   
                } else if (true == comment) {   
                    commentLine++;   
                    if (str.endsWith("*/")) {   
                        comment = false;   
                    }   
                } else if (str.startsWith("//")) {   
                        commentLine++;   
                } else {   
                    normalLine++;   
                }   
                
            }  
            
           
          
        }catch(Exception e){  
            e.printStackTrace();  
        }  
        
         
 public void print() throws IOException{
          /* 写入Txt文件 */  
          File writename;
          if(this.name2==null){
              writename = new File(".\result.txt"); // 相对路径,如果没有则要建立一个新的result.txt文件  
          }else{
              writename=new File(".\"+name2);
          }
          
        
        writename.createNewFile(); // 创建新文件  
          BufferedWriter out = new BufferedWriter(new FileWriter(writename));  
          out.write(result); // 
即为换行  
        
          out.flush(); // 把缓存区内容压入文件  
          out.close(); // 最后记得关闭文件 
      }

6.测试设计过程

白盒测试法的覆盖标准有逻辑覆盖、循环覆盖和基本路径测试。
其中逻辑覆盖包括语句覆盖判定覆盖条件覆盖、判定/条件覆盖、条件组合覆盖路径覆盖。六种覆盖标准发现错误的能力呈由弱到强的变化:
1.语句覆盖每条语句至少执行一次。
2.判定覆盖每个判定的每个分支至少执行一次。
3.条件覆盖每个判定的每个条件应取到各种可能的值。
4.判定/条件覆盖同时满足判定覆盖条件覆盖。
5.条件组合覆盖每个判定中各条件的每一种组合至少出现一次。
6.路径覆盖使程序中每一条可能的路径至少执行一次。

7.参考链接

http://blog.csdn.net/w4bobo/article/details/17024019

http://blog.csdn.net/ycy0706/article/details/45457311

http://rensanning.iteye.com/blog/2161201

http://blog.csdn.net/qy20115549/article/details/53588782

原文地址:https://www.cnblogs.com/zgwit/p/8629486.html