一、本文对应项目GitHub地址
https://github.com/ReWr1te/WCProject
二、项目PSP表格
| PSP2.1 | PSP阶段 | 预估耗时(分钟) | 实际耗时(分钟) |
|---|---|---|---|
| Planning | 计划 | 5 | 10 |
| · Estimate | · 估计这个任务需要多少时间 | 5 | 10 |
| Development | 开发 | 355 | 600 |
| · Analysis | · 需求分析 (包括学习新技术) | 50 | 100 |
| · Design Spec | · 生成设计文档 | 10 | 10 |
| · Design Review | · 设计复审 (和同事审核设计文档) | 25 | 50 |
| · Coding Standard | · 代码规范 (为目前的开发制定合适的规范) | 10 | 20 |
| · Design | · 具体设计 | 100 | 100 |
| · Coding | · 具体编码 | 100 | 200 |
| · Code Review | · 代码复审 | 10 | 20 |
| · Test | · 测试(自我测试,修改代码,提交修改) | 50 | 100 |
| Reporting | 报告 | 40 | 40 |
| · Test Report | · 测试报告 | 25 | 25 |
| · Size Measurement | · 计算工作量 | 5 | 5 |
| · Postmortem & Process Improvement Plan | · 事后总结, 并提出过程改进计划 | 10 | 10 |
| 合计 | 400 | 650 |
三、简单解题思路
- 需求分析:仔细阅读给出需求并细化,重新陈述以及思考解决难度;
- 设计文档:基本设计思路整理;
- 制定代码规范:根据指定的语言(Java)指定相关规范;
- 具体设计:核心算法设计,6个功能主要分为6部分,同时注意衔接;
- 具体编码;
- 代码复审:经验排错;
- 测试:撰写测试用例并完善,同时修改代码以提高质量;
- 总结和撰写报告;
四、实现流程及代码说明
Java类代码分为主函数和几个功能函数,但是并非所有功能都在功能函数里面实现。具体核心代码及说明参见以下代码和注释(更加详细的解释等待补充):
| // 计算字符数 | |
| public static int chars(String str) { | |
| char[] charArray = str.toCharArray(); | |
| int c_num = 0; | |
| for (int i = 0; i < charArray.length; i++) | |
| { | |
| c_num++; | |
| } | |
| return c_num; | |
| } | |
| // 计算单词数 | |
|---|---|
| public static int words(String str) { | |
| char[] charArray = str.toCharArray(); | |
| int w_num = 0; | |
| for (int i = 0; i < charArray.length; i++) | |
| { | |
| if (charArray[i] == ‘ ‘ || charArray[i] == ‘,‘ || charArray[i] == ‘\n‘) | |
| { | |
| w_num++; | |
| if (charArray[i] == ‘ ‘ && charArray[i - 1] == ‘,‘) | |
| w_num--; | |
| if (charArray[i] == ‘\n‘ && | |
| (charArray[i - 1] == ‘\n‘ || | |
| charArray[i - 1] == ‘{‘ || charArray[i - 1] == ‘}‘)) | |
| w_num--; | |
| } | |
| } | |
| return w_num; | |
| } |
| // stopList扣词 | |
|---|---|
| for (int i = 0; i < args.length; i++) | |
| { | |
| System.out.println(args[i]); | |
| if (args[i].equals(str_e)) | |
| { | |
| if (exclude == -1) | |
| { | |
| System.out.println("\n不能单独使用-e参数!\n"); | |
| out = false; | |
| } | |
| else | |
| { | |
| String[] strArray = str_read.split(" "); | |
| String tempStr = e_sb.toString(); | |
| String[] e_str = tempStr.split(" "); | |
| for (int j = 0; j < strArray.length; j++) | |
| { | |
| for (int k = 0; k < e_str.length; k++) | |
| { | |
| System.out.println(strArray[j] + e_str[k]); | |
| if (strArray[j].indexOf(e_str[k]) != -1) | |
| w_num--; | |
| } | |
| } | |
| } | |
| } | |
| } |
| // 输出(若没有指定文件名则输出到result.txt,若没有文件则创建文件) | |
|---|---|
| if (out == true) | |
| { | |
| File file = new File(filename); | |
| if (!file.exists()) | |
| file.createNewFile(); | |
| FileWriter fileWriter = new FileWriter(file.getName(), true); | |
| BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); | |
| bufferedWriter.write(str_output); | |
| bufferedWriter.close(); | |
| } |
五、测试设计
按照白盒测试设计方法,尽量覆盖所有功能:
(功能衔接处会有高风险,多设计两个测试用例)
- wc.exe -c -w -l test1.cpp
- wc.exe -c -w -l test2.c
- wc.exe -c -w -l -a test1.cpp
- wc.exe -c -w -l -a test2.c -e stopList.txt
- wc.exe -c -w -l -a test2.c -o outputFile.txt
- wc.exe -c -w -l -a test2.c -e stopList.txt -o outputFile.txt
- wc.exe -s *.cpp
- wc.exe -s *.c
- wc.exe -c -w -l -a -s *.cpp -e stopList.txt -o outputFile.txt
- wc.exe -c -w -l -a test1.cpp test2.c -e stopList.txt -o outputFile.txt
六、参考文献
本次项目无参考文献。