姓名 | 學號 | 博客園首頁 | 碼雲主頁 |
---|---|---|---|
孫志威 | 20152112307 | Agt | Eurekaaa |
孫慧君 | 201521123098 | 野原澤君 | 野原澤君 |
測試用例
前端
測試用例完整覆蓋了全部函數的各個分支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
碼雲記錄
編碼規範文檔
PSP表格
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+1>2的效果嗎?
關於結對編程的1+1是否大於2,我還不是很肯定,緣由以下。 1. 在結對編程的過程當中,同一臺電腦,一我的敲代碼,另外一個負責複審,無可厚非會浪費掉一我的敲代碼的時間,但與此同時,又節省了複審時間,這二者之間孰輕孰重我還沒法準確比較; 2. 結對編程的兩我的是不可能實力至關的,因而就會有一部分時間是「隊友教我作做業」的狀態OvO,在這裏對我(沒錯,我弱)的編程能力的提升是有所幫助的。這個時候相比於讓隊友直接上手,咱們更加樂意於「隊友教我作做業」,可是這個時候「教學時間」會花不少時間=-=; 3. 我在編程時,偶爾會邏輯混亂,腦子漿糊,我能夠冷靜下來和個人隊友分析一波,理清思路再繼續編寫,由此完成咱們的項目,我以爲在這裏結對編程相比於一我的完成代碼是有所優點的; 4. 最後一點給結對編程的優勢,在編程時,兩人能夠發揮各自的優點,促進項目的完成,就好比:數據結構的規劃是我想出來的,但我實際構建數據結構會弱一點,那麼個人隊友就負責完成這一個部分,我負責其餘部分。
經過此次結對編程,請談談你的感覺和體會。
至於感覺: 1. 學好英語很重要=-=。英語學很差,命名只能用拼音全拼,很是醜! 2. 一個項目的好的設計可能不是在開始敲代碼以前就完成的,多是編寫時忽然的一個靈感來完善的。在以前,我還沒注意到老師說能夠用二叉樹,數據結構徹底是咱們本身分析出來的。起初決定用單純的樹,當時以爲「嗯,這個結構好像不錯」,後來發現多個度的樹是很難用代碼實現的(OK FINE);接着聯想到了樹轉化爲二叉樹,用左孩子右兄弟的方式存儲,「妙哇,節省空間又很快」;可是發覺答案的存儲又成了一個問題,再次改進運用了指針。 3. 其實,不少時候項目自己不難,若是仔細分析一波,分紅一個個小塊去實現,編寫好項目是很容易的,只是你不肯意去認真而已。 4. 作項目的時候合理控制一下時間。一方面,屁股都坐不住,就不要妄想作好一個項目;另外一方面,沉迷代碼,面對顯示屏過久人也會受不了的,同時也會影響工做效率。
以上就是該博客的所有內容,喜歡請關注+轉發+收藏+硬幣,咱們下次再見。 ↑皮這一下很開心hhhhh。