WordCount测试作业

一、本文对应相应的GitHub地址

https://github.com/lakshys/wordcount

二、项目PSP表格

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

三、解题思路

      1、需求分析:仔细阅读需求说明书,弄清客户具体需求点

       2、制定代码规范

       3、具体设计:核心的数据结构及算法的设计

       4、编码实践

       5、调试

       6、设计测试用例

       7、测试

       8、总结

四、关键代码

1、基础功能的计数

public static void count(String contents) throws FileNotFoundException {
w=0;
word=0;
character=0;
line=0;
Scanner s=new Scanner(new File(contents));//扫描器s保存读取文件的内容
while(s.hasNextLine()){
line++;
String str=s.nextLine();//读入一行
//System.out.println(str);
character+=str.length();//字符数为每行的字符数之和
for(int i=0;i<str.length();i++)
{
if(str.charAt(i)==' '||str.charAt(i)==',')
{

w++;
}

}
}
word=w+line;
s.close();

}

2、扩展功能的计数

public static void countLine(String[]contents) throws FileNotFoundException{
lines[0]=0;
lines[1]=0;
lines[2]=0;
for (String line : contents) {
if (line.trim().length() <= 1)
lines[1]++;
else {
if (!line.trim().contains("//")) {
lines[0]++;
} else if (line.replaceAll(" ", "").indexOf("//") > 1) {
lines[0]++;
} else if (line.contains("//")) {
lines[2]++;
}
}
}
}

3、遍历目录

static ArrayList<String> pureFile=new ArrayList<String>();
static ArrayList<String> cFile=new ArrayList<String>();
public static ArrayList<String> traverseFolder2(String path) {
File file = new File(path);
if (file.exists()) {
File[] files = file.listFiles();
if (files.length == 0) {

} else {
for (File file2 : files) {
if (file2.isDirectory()) {
// System.out.println("文件夹:" + file2.getAbsolutePath());

//traverseFolder2(file2.getAbsolutePath());
} else {
//System.out.println("文件:" + file2.getAbsolutePath());
pureFile.add(file2.getAbsolutePath());
}
}
}
} else {
System.out.println("文件不存在!");
}

4、解析参数

public static void main(String[] args) throws IOException{
ArrayList<String> a=traverseFolder2("C:\\Users\\Iridescent\\eclipse-workspace\\wc");
for (String tmp : a) {
System.out.println(tmp);
}


for(int i=0;i<args.length;i++){
if(args[i].endsWith(".c")) {
if(args[i].equals("*.c")) {
ArrayList<String> inputFiles=a;
for(String s:inputFiles) {
inputFile=s;

wordcount.out(args);
}
}
else {
inputFile=args[i];
out(args);
}
if(args[i].equals("-o"))
outputFile=args[i+1];
}
}

五、测试设计

  1. wc.exe -c file.c
  2. wc.exe -c -w file.c
  3. wc.exe -c -w file1.c
  4. wc.exe -c -w -l file1.c
  5. wc.exe -c -w -l -a file1.c
  6. wc.exe -c -w -l -a file2.c -e stopList.txt
  7. wc.exe -c -w -l -a file.c -o output.txt
  8. wc.exe -c -w -l -a file2.c -e stopList.txt -o output.txt
  9. wc.exe -s *.c
  10. wc.exe -c -w -l -a -s *.c -e stopList.txt -o outputFile.txt
  11. wc.exe -c -w -l -a test1.c file.c -e stopList.txt -o output.txt

 

posted @ 2018-03-22 21:48  你有点严格  阅读(414)  评论(1编辑  收藏  举报