第四周小作业
第四周小组作业:WordCount优化
(1)本次项目Github地址:https://github.com/cosensible/WordCountPlus
(2)PSP表格
| PSP2.1 | PSP阶段 | 预估耗时(分钟) | 实际耗时(分钟) |
|---|---|---|---|
| Planning | 计划 | 30 | 30 |
| .Estimate | .估计这个任务开发需要多少时间 | 30 | 30 |
| Development | 开发 | 480 | 500 |
| .Analysis | .需求分析 | 30 | 30 |
| .Design Spec | .生成设计文档 | 20 | 20 |
| .DesignReview | .设计复审(和同事审核设计文档) | 10 | 10 |
| .Coding Standard | .代码规范(为目前开发指定合适规范) | 10 | 10 |
| .Design | .具体设计 | 20 | 20 |
| .Coding | .具体编码 | 20 | 20 |
| .Code Review | .代码复查 | 10 | 10 |
| .Test | .测试(自我测试,修改代码,提交代码) | 60 | 80 |
| Reporting | 报告 | 120 | 120 |
| .Test Report | .测试报告 | 90 | 90 |
| .Size Measurement | .计算工作量 | 20 | 20 |
| .Postmortem & Process Improvement Plan | .时候总结,并提出过程改进计划 | 10 | 10 |
| 合计 | 60*12.5 | 60*16 |
(3)接口实现
我处理的是本次项目的其它模块,主要是main函数,负责连接其它各个模块。
代码如下:
public static void main(String[] args) {
if (args.length == 0) {
System.out.print("please input a *.txt file!");
return;
}
String inputFilePath = args[0];
String resultFilePath = "result.txt";
//构建正则表达式以匹配以.txt结尾的文件
String regex = ".+\\.txt";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(inputFilePath);
if (matcher.matches()) {
//读取输入文件
String[] contents = FileUtil.read(inputFilePath);
//获取统计结果(已按词频从高到低排好序)
String[] resultContents = WordFrequencyCountUtil.countWordFrequency(contents);
//写入输出文件
if (hasResults(resultContents)) {
FileUtil.write(resultFilePath, resultContents, false);
} else {
FileUtil.write(resultFilePath, new String[]{"No Contents!"}, false);
}
} else
System.out.println("it is not a *.txt file!");
return;
}
public static boolean hasResults(String[] resultContents) {
if (resultContents == null) {
return false;
}
for (String contents : resultContents) {
if (contents != null && !contents.trim().isEmpty()) {
return true;
}
}
return false;
}
- 判断是否有输入,有则转到第二步,否则退出
- 判断输入是否符合要求(*.txt文件),符合,则读取文件内容,否则给出错误提示
- 对文件内容进行处理,获取词频统计结果
- 如果词频统计结果为空,则在输出文件给出提示,否则写入文件
(4)测试用例的设计
对main函数的测试主要包括
- 对输入的检验
- 对其它接口调用返回结果的检验
程序流程图如下

a. 白盒测试:共有四条路径

设计四个测试用例来完成路径覆盖

b. 黑盒测试
4.3 黑盒测试
对于输入,可以划分4个等价类

4.3.1 等价类1
{}
4.3.2 等价类2
abc
file.c
4.3.3
haveCentent.txt
4.3.4
noContent.txt
(5)单元测试


浙公网安备 33010602011771号