第4周小组作业:WordCount优化
一、github地址
https://github.com/yo123abxd/wordcount2.git
二、PSP表格
|
PSP2.1 |
PSP阶段 |
预估耗时 (分钟) |
实际耗时 (分钟) |
|
Planning |
计划 |
50 |
40 |
|
· Estimate |
· 估计这个任务需要多少时间 |
50 |
40 |
|
Development |
开发 |
420 |
500 |
|
· Analysis |
· 需求分析 (包括学习新技术) |
30 |
40 |
|
· Design Spec |
· 生成设计文档 |
30 |
30 |
|
· Design Review |
· 设计复审 (和同事审核设计文档) |
20 |
30 |
|
· Coding Standard |
· 代码规范 (为目前的开发制定合适的规范) |
20 |
30 |
|
· Design |
· 具体设计 |
40 |
40 |
|
· Coding |
· 具体编码 |
150 |
200 |
|
· Code Review |
· 代码复审 |
30 |
30 |
|
· Test |
· 测试(自我测试,修改代码,提交修改) |
100 |
100 |
|
Reporting |
报告 |
100 |
130 |
|
· Test Report |
· 测试报告 |
60 |
90 |
|
· Size Measurement |
· 计算工作量 |
20 |
20 |
|
· Postmortem & Process Improvement Plan |
· 事后总结, 并提出过程改进计划 |
20 |
20 |
|
|
合计 |
570 |
670 |
三、对接口的实现
我负责的是输出模块,代码主要是output.cpp,实现思路如下:调用fstream类打开待接受输出的文件result.txt,然后把传入的待输出数组toOutPut中的内容输出到该文件中;通过if判断来给除了最后一行以外的行换行;最后关闭文件。
1 #ifndef COUNTER_CURR_OUTPUT_H_ 2 #define COUNTER_CURR_OUTPUT_H_ 3 #include <vector> 4 #include <iostream> 5 #include <fstream> 6 class OutPut { 7 public: 8 void output(const std::vector<std::pair<std::string, int>>& toOutPut); 9 }; 10 11 #endif
1 #include "output.h" 2 void OutPut::output(const std::vector<std::pair<std::string, int>>& toOutPut) { 3 std::fstream out_(std::string("result.txt"), std::ios::out); 4 for(int i = 0; i < toOutPut.size(); i++) { 5 out_ << toOutPut[i].first << " " << toOutPut[i].second; 6 if(i + 1 != toOutPut.size()) { 7 out_<<"\n"; 8 } 9 } 10 out_.close(); 11 }
四、测试用例设计
在设计测试用例时,首先要考虑到语句覆盖度,使得对输出条件的判断的不同情况做到完全覆盖;对输出前100个单词的词频要对边界进行黑盒测试。 
五、单元测试结果
使用gtest框架进行单元测试,测试结果如下图:

六、小组贡献分
经小组协商为0.24
七、扩展功能
选择“3.4.3谷歌C++风格指南”,分析了17036同学的代码,发现了问题,比如#include的顺序问题,等等。
但同时发现了更多的很好的点,比如变量初始化、通用命名规则等,都很好地遵循了相应的规则。
小组使用的静态代码检查工具为Cpplint,安装及使用方法详见[2]。
八、参考资料
[1]fstream的使用方法介绍 https://blog.csdn.net/smstone/article/details/661483
[2]静态代码检测工具Cpplint https://blog.csdn.net/mangobar/article/details/50072465
浙公网安备 33010602011771号