第2周个人作业:WordCount

Github网页链接:https://github.com/Middamn/WordCount

PSP2.1

PSP阶段

预估耗时

(分钟)

实际耗时

(分钟)

Planning

计划

 30

 20

· Estimate

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

 10

 10

Development

开发

 60

 未计

· Analysis

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

 60

 120

· Design Spec

· 生成设计文档

 60

 30

· Design Review

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

 60

 未计

· Coding Standard

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

 30

 10

· Design

· 具体设计

 120

 90

· Coding

· 具体编码

 240

 未计

· Code Review

· 代码复审

 60

 未计

· Test

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

 120

 120

Reporting

报告

 60

 90

· Test Report

· 测试报告

 60

 60

· Size Measurement

· 计算工作量

 20

 20

· Postmortem & Process Improvement Plan

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

 20

 未计

 

合计

 1020

 未计

标注:因为水平有限,实在没法在短时间内自己完成,所以代码部分采用的是1504成建伟的

需求分析

这个项目的需求可以概括为:对程序设计语言源文件统计字符数,单词书,行数,统计结果以指定格式输出到默认文件中,以及其他扩展功能,并能够快速地处理多个文件。大体思路分为一读取命令行,二统计各项数据,打算采用自底向上一层层来实现相应功能。最后再通过使用编译器生成jar包后,由第三方软件exe4j即可将jar包转换成exe文件。

程序设计实现过程

可以划分为主函数和调用函数其中调用又可以分为五个方面 ——参数处理 ,文件写入,读行,读字符 以及读单词

代码

基本功能

while((line=br.readLine())!=null)
                {
                    
                    linecount++;
                    sb.append(line);
                    charcount+=line.length();
                     String[] split = line.split("\\s++|\\.|,|\\;|\\(|\\)|\\[|\\]|\\<|\\>|\\=|\\-|\\+|\\*|\\/|\\{|\\}|\\_");  
                     for (int i = 0; i < split.length; i++) { 
//                       获取到每一个单词  
                         Integer integer = map.get(split[i]);  
//                       如果这个单词在map中没有,赋值1  
                         if(null==integer){  
                             map.put(split[i], 1);  
                         }else{  
//                           如果有,在原来的个数上加上一  
                             map.put(split[i], ++integer);  
                         }  
                     }  
                 }
                
//               遍历,根据key获取所对应的value  
                 Set<String> keySet = map.keySet();  
                 for (String string : keySet)
                     if(!(string.equals("")))//{
                     wordcount+=map.get(string);
                 //    System.out.println(string);}
                   br.close();
                   isr.close();
                   fis.close();
            }
            catch(FileNotFoundException e){
                e.printStackTrace();
            }
            catch(UnsupportedEncodingException e){
                e.printStackTrace();
            }
            catch(IOException e){
                e.printStackTrace();
            }
        }
            String message=null;
            if(action1.equals("-l"))
                  message=(sourcefile+",   行数:"+linecount+"\r\n");//换行"\r\n"不是"\n"
            else if(action1.equals("-c"))
                 message=(sourcefile+",   字符数:"+charcount+"\r\n");//换行"\r\n"不是"\n"
            else if(action1.equals("-w"))
                 message=(sourcefile+",   单词数:"+wordcount+"\r\n");//换行"\r\n"不是"\n"
           return message;
    }

扩展功能

static String moredata(String myfile)throws FileNotFoundException { 
File file=new File(myfile);
// 记录注释行数 
long annotationLine = 0; 
// 记录空白行数 
long blankLine = 0; 
// 记录有效代码的行数 
long codeLine = 0; 
//假注释
long notLine=0;
if (file == null || !file.exists()) 
throw new FileNotFoundException(file + ",文件不存在!"); 
BufferedReader br = null; 
// 判断此行是否为注释行 
boolean comment = false; 
int whiteLines = 0; 
int commentLines = 0; 
int normalLines = 0; 
try { 
br = new BufferedReader(new FileReader(file)); 
String line = ""; 
while ((line = br.readLine()) != null) { 
line = line.trim(); 
if (line.matches("^[//s&&[^//n]]*$")||line.equals("{")||line.equals("}")) { 
// 空行 :本行全部是空格或格式控制字符,如果包括代码,则只有不超过一个可显示的字符,例如“{”
whiteLines++; 
} 
/* 本行不是代码行,并且本行包括注释。一个有趣的例子是有些程序员会在单字符后面加注释:
* }//注释
*/
else if (line.startsWith("/*") && !line.endsWith("*/")||((line.startsWith("{/*")||line.startsWith("}/*"))&&!line.endsWith("*/"))){
// 判断此行为"/*"开头的注释行 
commentLines++; 
comment = true; 
} else if (comment == true && !line.endsWith("*/")&&!line.startsWith("*/")) { 
// 为多行注释中的一行(不是开头和结尾)
notLine++;
commentLines++; 
} else if (comment == true && (line.endsWith("*/")||line.startsWith("*/"))) { 
// 为多行注释的结束行 
commentLines++; 
comment = false; 
} else if (line.startsWith("//")|| line.startsWith("}//")||line.startsWith("{//")||
((line.startsWith("{/*") ||line.startsWith("}/*")||line.startsWith("/*")) && line.endsWith("*/"))) { 
// 单行注释行 
commentLines++; 
} else { 
// 正常代码行 
//System.out.println(line);
normalLines++; 
} 
} 

测试设计过程
测试采用白盒测试的方法,覆盖标准有逻辑覆盖、循环覆盖和基本路径测试。其中逻辑覆盖包括语句覆盖、判定覆盖、条件覆盖、判定/条件覆盖、条件组合覆盖和路径覆盖。
六种覆盖标准:语句覆盖、判定覆盖、条件覆盖、判定/条件覆盖、条件组合覆盖和路径覆盖发现错误的能力呈由弱至强的变化。语句覆盖每条语句至少执行一次。判定覆盖每个判定的每个分支至少执行一次。条件覆盖每个判定的每个条件应取到各种可能的值。判定/条件覆盖同时满足判定覆盖条件覆盖。条件组合覆盖每个判定中各条件的每一种组合至少出现一次。路径覆盖使程序中每一条可能的路径至少执行一次。
测试用例分为10种,分别对相应功能进行测试,并对组合的功能进行整体测试。如下:

1. wc.exe -w -c -l test.c

2. wc.exe -w -c D:\test\test.c

3,wc.exe -w test.c -e stoplist.txt -o out.txt

4. wc.exe -a -c -l -w test.c -e stoplist.txt

5. wc.exe -a -c test.c -o out.txt

6. wc.exe -s -w test.c -e stoplist.txt

7. wc.exe -w -l D:\test\test.c -o out.txt

8.wc.exe -a -l -c -w test.c

9.wc.exe -l test.c -e stoplist.txt

10. wc.exe -s -w test.c -o out.txt

总结

   因为没自学过java,作业布置下来时完全没法着手,导致这次软件测试作业并未能自己按时按量完成。一是能力问题,二是我最近也有很多其他事情要处理
。这次作业虽然交了,但是并不是完全自己完成的,希望下次能做好准备。

posted @ 2018-03-23 18:20  middamn  阅读(191)  评论(1编辑  收藏  举报