姓名 | 学号 | 博客园首页 | 码云主页 |
---|---|---|---|
孙志威 | 20152112307 | Agt | Eurekaaa |
孙慧君 | 201521123098 | 野原泽君 | 野原泽君 |
测试用例
html
测试用例完整覆盖了全部函数的各个分支前端
程序整体设计
node
所使用的二叉树算法介绍
python
支持括号
c++
乘方运算
git
回归测试:
测试方法大纲
部分测试用例
算法
代码覆盖率测试
express
字符串生成类编程
class ExpGenerator { public: ExpGenerator(); ~ExpGenerator(); int getGcd(int x, int y); string generateRawExp(); vector<int> findOperator(string exp); string addBracket(string exp); string addPower(string exp); vector<string> apartExp(string exp); vector<string> sortExp(vector<string> items); vector<string> generate(int amount, vector<double>&results); };
生成字符串数组
string ExpGenerator::generateRawExp() { //产生初始表达式 string exp = ""; char ch[5] = { '+','-','*','~','^' }; int maxNum; if (NUMBER < 2) { //表达式位数小于2则报错 exp = "ERROR!"; return exp; } else if (NUMBER == 2) maxNum = 2; else maxNum = rand() % NUMBER + 2; for (int i = 0; i < maxNum; i++) { //以(符号+数字)*maxNum造成第一位为符号的“伪表达式” //随机生成符号 char c = ch[rand() % 4]; exp.push_back(c); //随机生成数字 stringstream ss; string s; int flag = rand() % 10; if (flag != 0) //生成整数(90%) ss << rand() % MAX + 1; else { //生成分数(10%) int mumNum = rand() % MAX + 2; int sonNum = rand() % (mumNum - 1) + 1; sonNum /= getGcd(mumNum, sonNum); mumNum /= getGcd(mumNum, sonNum); ss << sonNum << "/" << mumNum; } ss >> s; exp += s; } //截去第一位符号,生成初始表达式 exp = exp.substr(1, exp.length()); ////cout << exp << endl; return exp; }
拆分字符串并排序
```C++
vector
{
//遍历初始表达式,以“符号+数字”的结构分割返回
vector
int begin = 0;
int end;
unsigned int i;
string str;
exp = "+" + exp;
char c;
for (i = 0; i < exp.length(); i++)
{
c = exp.at(i);
if ((c == '+' || c == '-' || c == '*' || c == '~')
&& (i != 0))
{
end = i;
str = exp.substr(begin, end - begin);
items.push_back(str);
begin = i;
}
}
str = exp.substr(begin, exp.length() - begin);
items.push_back(str);
return items;
}
vector二叉树相关
```C++
class UniqueBinaryTree
{
public:
UniqueBinaryTree();
~UniqueBinaryTree();
// check if the tree contains the expression // if contains return true // else return false // and add the unique new nodes to the tree bool add(vector<string>expressionVec, double answer); // clear the tree but not destoryed it void clear(); // get amount of the nodes int nodeAmount(); // get amount of all the resultsNodes int resultsAmount(); // amount of both result node and the mormal node int amount(); // Debug: show contents to the console void showLayer();
private:
// add the result node to the last node (levelNode)
// return true if new result added
// which represent that the new expression
// has the same expression(without brackets) but
// different answers
bool mountAnswerToNode(PNode levelNode, double answer);
int countAnswerNode(PNode levelNode);
void clearAnswerNode(PNode levelNode);
Node * head = NULL;
};
- add函数
C++
bool UniqueBinaryTree::add(vector
{
// treat empty string as true/contains and ignore it
if (expressionVec.empty())
return true;
int length = expressionVec.size(); PNode curNode = this->head->right; // compare each node from the first PNode fatherNode = this->head; string currentStr; int index = 0; // the current index of stringVector bool isContained = false; while (curNode != NULL) { currentStr = expressionVec.at(index); // record the father node to support the insertion later fatherNode = curNode; if (curNode->data == currentStr) { curNode = curNode->left; // jump to the next string index++; // break when the whole expression finish if (index >= length) break; } else { curNode = curNode->right; } } //if not then it's an new expression // mount it to the tree // begin from the last part they're same // the current node is the last node matches part of the new expression bool first = true; // if it reached the end of the expression in the last loop // will skip it while (index < length) { string curStr = expressionVec.at(index); PNode newNode = new Node(); if (first) { // mount the first newNode as the rightChild fatherNode->right = newNode; first = false; } else { fatherNode->left = newNode; } newNode->data = curStr; newNode->left = NULL; newNode->right = NULL; newNode->answer = NULL; fatherNode = newNode; index++; } // now the new expression has been added to the tree // add the answer of the expression as well // and check if the answer is inside the tree // if it's inside it return false as well PNode lastNode = fatherNode; bool newAnswerAdded = this->mountAnswerToNode(lastNode,answer); // new answer node is unique , and been added to the tree return !newAnswerAdded; } ```
具体代码见码云Agt-TrivialCalculator
码云记录
编码规范文档
PSP2.1 | 我的开发流程 | 预估耗费时间(分钟) | 实际耗费时间(分钟) |
---|---|---|---|
Planning | 计划 | 20 | 30 |
Estimate | 明确需求和其余相关因素,估计每一个阶段的时间成本 | 10 | 30 |
Development | 开发 | 413 | 940 |
Analysis | 需求分析 (包括学习新技术) | 20 | 60 |
Design Spec | 生成设计文档 | 60 | 60 |
Design Review | 设计复审 | 60 | 30 |
Coding Standard | 代码规范 | 3 | 10 |
Design | 具体设计 | 30 | 60 |
Coding | 具体编码 | 120 | 400 |
Code Review | 代码复审 | 60 | 200 |
Test | 测试(自我测试,修改代码,提交修改 | 60 | 120 |
Reporting | 报告 | 60 | 120 |
· | 测试报告 | 10 | 20 |
· | 计算工做量 | 30 | 30 |
· | 并提出过程改进计划 | 60 | 60 |
我认为1+2是大于2的,结对编程仍是有不少收获的。
例如在考虑问题的解决方案的时候,一我的本身思考的时候很容易被本身过去的经验所影响,容易被本身的思惟定势束缚住。而在结对编程的时候,因为一边写一边审,互相之间会交流为何用这种算法,算法有什么优缺点等,能更好地找到更佳的解决方案,因此结对编程也仍是有好处的。
队友的感想见博客野原泽君