姓名 | 學號 | 博客園首頁 | 碼雲主頁 |
---|---|---|---|
孫志威 | 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的,結對編程仍是有不少收穫的。
例如在考慮問題的解決方案的時候,一我的本身思考的時候很容易被本身過去的經驗所影響,容易被本身的思惟定勢束縛住。而在結對編程的時候,因爲一邊寫一邊審,互相之間會交流爲何用這種算法,算法有什麼優缺點等,能更好地找到更佳的解決方案,因此結對編程也仍是有好處的。
隊友的感想見博客野原澤君