軟體測試第三次作業(WordCount的C#實現)
wordCount的c#實現
合作者:201631092112 , 201631092126
碼雲(gitee)地址:https://gitee.com/ulysses497/wordCount
本次作業地址:https://edu.cnblogs.com/campus/xnsy/Test/homework/2203
(1)互審程式碼情況
在此次作業中,我們互相寫了完整的wordCount程式碼後,互相進行了程式碼的審查,發現了很多問題,下列舉幾個模組審查問題
在合作同學的程式碼中他將對資料的處理寫為一類,讀寫,操作,寫出,寫為一類,顯得主函式太過冗長,我將程式碼的讀入,操作,主函式歸為三類
使得程式碼更為精簡
基本功能概述:
wc.exe -c file.c //返回檔案 file.c 的字元數
wc.exe -w file.c //返回檔案 file.c 的單詞總數
wc.exe -l file.c //返回檔案 file.c 的總行數
wc.exe -o outputFile.txt //將結果輸出到指定檔案outputFile.txt
拓展功能概述:
wc.exe -a file.c //統計程式碼行/空行/註釋行
wc.exe -s //呼叫其他-指令
註釋:
程式碼行:本行包括多於一個字元的程式碼。
空 行:本行全部是空格或格式控制字元,如果包括程式碼,則只有不超過一個可顯示的字元,例如“{”。
註釋行:本行不是程式碼行,並且本行包括註釋。一個有趣的例子是有些程式設計師會在單字元後面加註釋:}//註釋
在這種情況下,這一行屬於註釋行。
如下圖中的空行/註釋行/程式碼行的計數方法中,我們發現將註釋行的if語句巢狀,後對codecount的計數會發生影響
於是進行了改正:
還有很多不便一一贅述,將在下列測試中繼續列舉。
專案實現
main函式類:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace WordCount { class Program { static void Main(string[] args) { Console.WriteLine("WordCount"); Console.WriteLine("統計字元數 wc.exe -c file.c "); Console.WriteLine("統計單詞總數 wc.exe -w file.c "); Console.WriteLine("統計總行數 wc.exe -l file.c "); Console.WriteLine("統計輸出到檔案 wc.exe -o file.c "); Console.WriteLine("統計程式碼行/空行/註釋行 wc.exe -a file.c "); Console.WriteLine("呼叫其他-指令 wc.exe -s "); Console.WriteLine("請輸入指令:"); readFile readfile = new readFile(); readfile.Read();//呼叫讀入檔案類的Read()方法 Console.WriteLine(); Console.WriteLine("按任意鍵退出"); Console.ReadKey(); } } } readFile類(對讀取的命令進行操作的審查) using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace WordCount { class readFile { public string name = ""; public void Read() { string getcmd = ""; Console.Write("wc.exe "); getcmd = Console.ReadLine(); this.check(getcmd);//呼叫審查命令函式,進行對cmd的操作是否錯誤的審查 } string cmd = ""; public void check(string getcmd) //判斷輸入格式是否正確 { try { this.name = getcmd; string[] file = getcmd.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries);//分割讀取的檔名與操作 string filename = ""; bool isopen = true; foreach (string s in file) { if(s.Length>2) { string[] f = s.Split(new char[1] { '.' }, StringSplitOptions.RemoveEmptyEntries); //(f[f.Length - 1] != "c" && f[f.Length - 1] == "t") || (f[f.Length - 1] != "txt") if(f[f.Length-1]!="c") { if(f[f.Length-1]!="txt") { isopen = false; } else { filename = s; } } else { filename = s; } } if (s.Length == 2 && s.Substring(0, 1) == "-")//判斷是否為操作命令 { cmd = cmd + s; if (s != "-c" && s != "-w" && s != "-l" && s != "-a"&&s !="-s"&&s!="-o")//處理操作錯誤 { isopen = false; } if (isopen == false) { Console.WriteLine("----------------------------------------------------------"); Console.WriteLine(" 請輸入正確的檔名或您的操作有誤 "); Console.WriteLine("----------------------------------------------------------"); this.Read(); break; } } if (s.Length < 2)//處理操作錯誤 { isopen = false; Console.WriteLine("----------------------------------------------------------"); Console.WriteLine(" 請輸入正確的檔名或您的操作有誤 "); Console.WriteLine("----------------------------------------------------------"); this.Read(); break; } } if (isopen == true&&cmd!="") { if (cmd.Contains("-s") == false) { this.openFilename(filename); } } else { Console.WriteLine("----------------------------------------------------------"); Console.WriteLine(" 請輸入正確的檔名或您的操作有誤 "); Console.WriteLine("----------------------------------------------------------"); this.Read(); } if(cmd.Contains("-s")) { handleFile hdfile = new handleFile(); hdfile.checkCmd(cmd); } } catch (Exception e) { Console.WriteLine(e); Console.WriteLine("----------------------------------------------------------"); Console.WriteLine(" 請輸入正確的檔名或您的操作有誤 "); Console.WriteLine("----------------------------------------------------------"); this.Read(); } } public void openFilename(string name)//開啟檔案操作 { FileStream fs = new FileStream(@name, FileMode.Open); StreamReader sr = new StreamReader(fs); string allStr = sr.ReadToEnd(); sr.Close(); fs.Close(); handleFile hdfile = new handleFile();//呼叫操作檔案類 hdfile.allstr = allStr; hdfile.cmd = cmd; hdfile.name = name; hdfile.checkCmd(cmd); } } }
handleFile類(處理檔案類)
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; namespace WordCount { class handleFile//處理檔案 { public string name = ""; public string allstr = ""; public string cmd = ""; public bool isout; public void checkCmd(string cmdstr) //檢查指令 { if(cmdstr.Contains("-o"))//是否進行輸出到outfile.txt的操作 { this.isout = true; } else { this.isout = false; } if (cmdstr.Contains("-s")) { cmdstr = cmdstr.Replace("-s", ""); this.handleS(cmdstr); } else { for (int i = 0; i < cmdstr.Length; i++)//判斷是什麼命令 { if (cmdstr[i] == '-') { if (cmdstr[i + 1] == 'c') { this.handleC(); } else if (cmdstr[i + 1] == 'w') { this.handleW(); } else if (cmdstr[i + 1] == 'l') { this.handleL(); } else if (cmdstr[i + 1] == 'a') { this.handleA(); } } } } } public void handleC()//呼叫正則表示式對字元數的統計進行審查 { var cStr = this.allstr; Regex re = new Regex(@"(\r\n)|(\S)|(\u0020)|(\u3000)"); //換行和回車符不是同一個 int count = re.Matches(this.allstr).Count; Console.WriteLine(); Console.WriteLine(this.name+" "+ "字元數:"+count); this.rstFile(Convert.ToString(this.name + " " + "字元數:" + count)); this.outputFile(Convert.ToString(this.name + " " + "字元數:" + count), this.isout); } public void handleW() { string wStr = this.allstr; string[] sArray = wStr.Split(new char[3] { ' ', ',','\r' }, StringSplitOptions.RemoveEmptyEntries); //" "與","作為分割符 int count = 0; foreach (string s in sArray)//遍歷統計單詞數量 { count++; } Console.WriteLine(); Console.WriteLine(this.name + " " + "單詞數:"+count); this.rstFile(Convert.ToString(this.name + " " + "單詞數:" + count)); this.outputFile(Convert.ToString(this.name + " " + "單詞數:" + count), this.isout); } public void handleL() { FileStream fs = new FileStream(@name, FileMode.Open); StreamReader sr = new StreamReader(fs); int lines = 0; while (sr.ReadLine() != null)//遍歷統計行數(包含空行) { lines++; } sr.Close(); fs.Close(); Console.WriteLine(this.name + " " + "行數:"+lines); this.rstFile(Convert.ToString(this.name + " " + "行數:" + lines)); this.outputFile(Convert.ToString(this.name + " " + "行數:" + lines), this.isout); } public void handleA()//空行/註釋行/程式碼行的計數 { FileStream fs = new FileStream(@name, FileMode.Open); StreamReader sr = new StreamReader(fs); string lines = ""; int nullcount = 0; int notedcount = 0; int codecount = 0; while ((lines =sr.ReadLine()) != null) { lines = lines.Trim(' ');//每一行去掉兩頭空白字元 lines = lines.Trim('\t');//每一行去掉兩頭TAB字元 if (lines == "" || lines.Length <= 1) { nullcount++;//空行計數加一 } else if (lines.Length > 2 && (lines.Substring(0, 2) == "//" || lines.Substring(1, 2) == "//")) { notedcount++;//註釋行計數加一 } else if (lines.Length == 2 && (lines.Substring(0, 2) == "//")) { notedcount++; //註釋行計數加一 } else { codecount++;//程式碼行計數加一 } } sr.Close(); fs.Close(); string outstr = this.name + " " + "空行/註釋行/程式碼行:" + nullcount.ToString() + "/" + notedcount.ToString() + "/" + codecount.ToString(); Console.WriteLine(); Console.WriteLine(this.name + " "+"空行/註釋行/程式碼行:" +@"{0}/{1}/{2}", nullcount, notedcount, codecount); this.rstFile(outstr); this.outputFile(outstr, this.isout); } public void handleS(string cmd)//-s命令呼叫其它命令函式 { string rootPath = Directory.GetCurrentDirectory(); string[] files = Directory.GetFiles(rootPath, "*.c"); foreach (string file in files) { FileStream fs = new FileStream(@file, FileMode.Open); StreamReader sr = new StreamReader(fs); this.allstr = sr.ReadToEnd(); sr.Close(); fs.Close(); this.name = file; this.checkCmd(cmd); } } public void rstFile(string str)//輸出函式 { string filePath = Directory.GetCurrentDirectory(); StreamWriter sw = new StreamWriter(@filePath+"//"+"result.txt", true, Encoding.UTF8); sw.WriteLine(str); sw.Close(); } public void outputFile(string str, bool isout)//-0命令,輸出到output.txt { if (isout) { string filePath = Directory.GetCurrentDirectory(); StreamWriter sw = new StreamWriter(@filePath + "//" + "output.txt", true, Encoding.UTF8); sw.WriteLine(str); sw.Close(); } } } }
效能測試
測試工具:VS2013的效能測試工具
原來對字元數等命令統計使用的是for迴圈遍歷的方法
程式碼如下
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; namespace WordCount { class DataProcess { //開啟.c檔案並將內容以字串形式讀取出來 public string openFile(string fstr) { FileStream fs = new FileStream(fstr, FileMode.Open); byte[] array = new byte[fs.Length]; fs.Read(array,0, array.Length); fs.Close(); string str = Encoding.UTF8.GetString(array); return str; } //統計字元數 public int cProcess(string fstr) { string str = openFile(fstr); int charCount = 0; charCount = str.Length; foreach(char c in str) { if(c=='\n') { charCount--; } } StreamWriter sw = new StreamWriter("result.txt", true); sw.WriteLine(fstr + " 字元數: " + Convert.ToString(charCount)); sw.Close(); return charCount; } //統計行數 public int lProcess(string fstr) { string str = openFile(fstr); int lineCount = 1; foreach (char l in str) { if (l == '\n') { lineCount++; } } StreamWriter sw = new StreamWriter("result.txt", true); sw.WriteLine(fstr + " 行數: " + Convert.ToString(lineCount)); sw.Close(); return lineCount; } //統計單詞書 public int wProcess(string lstr) { string str = openFile(lstr); int count = 1; bool isBlank = true; foreach(char s in str) { if(s!=' ' && s!= '\n' &&s!=','&& isBlank==true) { count++; isBlank = false; } else if((s==' '||s=='\n'||s==',')&&isBlank==false) { isBlank = true; } } StreamWriter sw = new StreamWriter("result.txt", true); sw.WriteLine(lstr + " 單詞數:" + Convert.ToString(count - 1)); sw.Close(); return count - 1; } //統計程式碼行/空行/註釋行 public string aProcess(string astr) { FileStream fs = new FileStream(astr, FileMode.Open); StreamReader sr = new StreamReader(fs); string lines = ""; int codeLineCount = 0; int nullLineCount = 0; int noteLineCount = 0; while ((lines = sr.ReadLine()) != null) { lines = lines.Trim(' '); lines = lines.Trim('\t'); if (lines == "" || lines.Length <= 1) { nullLineCount++; } else if (lines.Length > 2 && lines.Substring(0, 2) == "//" || lines.Substring(1, 2) == "//") { noteLineCount++; } else if(lines.Length==2 && lines.Substring(0, 2) == "//") { noteLineCount++; } else { codeLineCount++; } } string complexLineCount = Convert.ToString(codeLineCount) + "/"+Convert.ToString(nullLineCount) +"/"+ Convert.ToString(noteLineCount); StreamWriter sw = new StreamWriter("result.txt", true); sw.WriteLine(astr + " 程式碼行/空行/註釋行:" + Convert.ToString(codeLineCount)+"/"+Convert.ToString(nullLineCount)+"/"+Convert.ToString(noteLineCount)); sw.Close(); return complexLineCount; } //將統計的資料存入指定檔案 public string oProcess(string oFile) { System.IO.File.WriteAllText(oFile, string.Empty); string str = openFile("result.txt"); StreamWriter sw = new StreamWriter(oFile, true); sw.WriteLine(str); sw.Close(); return oFile; } } }
對其進行效能測試
後改用正則表示式的方法,並在對其他程式碼進行優化後再進行效能測試
程式碼如下:
using
System;
using
System.Collections.Generic;
using
System.IO;
using
System.Linq;
using
System.Text;
using
System.Text.RegularExpressions;
using
System.Threading.Tasks;
namespace
WordCount
{
class
handleFile
//處理檔案
{
public
string
name =
""
;
public
string
allstr =
""
;
public
string
cmd =
""
;
public
bool
isout;
public
void
checkCmd(
string
cmdstr)
//檢查指令
{
if
(cmdstr.Contains(
"-o"
))
//是否進行輸出到outfile.txt的操作
{
this
.isout =
true
;
}
else
{
this
.isout =
false
;
}
if
(cmdstr.Contains(
"-s"
))
{
cmdstr = cmdstr.Replace(
"-s"
,
""
);
this
.handleS(cmdstr);
}
else
{
for
(
int
i = 0; i < cmdstr.Length; i++)
//判斷是什麼命令
{
if
(cmdstr[i] ==
'-'
)
{
if
(cmdstr[i + 1] ==
'c'
)
{
this
.handleC();
}
else
if
(cmdstr[i + 1] ==
'w'
)
{
this
.handleW();
}
else
if
(cmdstr[i + 1] ==
'l'
)
{
this
.handleL();
}
else
if
(cmdstr[i + 1] ==
'a'
)
{
this
.handleA();
}
}
}
}
}
public
void
handleC()
//呼叫正則表示式對字元數的統計進行審查
{
var
cStr =
this
.allstr;
Regex re =
new
Regex(
@"(\r\n)|(\S)|(\u0020)|(\u3000)"
);
//換行和回車符不是同一個
int
count = re.Matches(
this
.allstr).Count;
Console.WriteLine();
Console.WriteLine(
this
.name +
" "
+
"字元數:"
+ count);
this
.rstFile(Convert.ToString(
this
.name +
" "
+
"字元數:"
+ count));
this
.outputFile(Convert.ToString(
this
.name +
" "
+
"字元數:"
+ count),
this
.isout);
}
public
void
handleW()
{
string
wStr =
this
.allstr;
string
[] sArray = wStr.Split(
new
char
[3] {
' '
,
','
,
'\r'
}, StringSplitOptions.RemoveEmptyEntries);
//" "與","作為分割符
int
count = 0;
foreach
(
string
s
in
sArray)
//遍歷統計單詞數量
{
count++;
}
Console.WriteLine();
Console.WriteLine(
this
.name +
" "
+
"單詞數:"
+ count);
this
.rstFile(Convert.ToString(
this
.name +
" "
+
"單詞數:"
+ count));
this
.outputFile(Convert.ToString(
this
.name +
" "
+
"單詞數:"
+ count),
this
.isout);
}
public
void
handleL()
{
FileStream fs =
new
FileStream(@name, FileMode.Open);
StreamReader sr =
new
StreamReader(fs);
int
lines = 0;
while
(sr.ReadLine() !=
null
)
//遍歷統計行數(包含空行)
{
lines++;
}
sr.Close();
fs.Close();
Console.WriteLine(
this
.name +
" "
+
"行數:"
+ lines);
this
.rstFile(Convert.ToString(
this
.name +
" "
+
"行數:"
+ lines));
this
.outputFile(Convert.ToString(
this
.name +
" "
+
"行數:"
+ lines),
this
.isout);
}
public
void
handleA()
//空行/註釋行/程式碼行的計數
{
FileStream fs =
new
FileStream(@name, FileMode.Open);
StreamReader sr =
new
StreamReader(fs);
string
lines =
""
;
int
nullcount = 0;
int
notedcount = 0;
相關推薦
軟體測試第三次作業(WordCount的C#實現)
wordCount的c#實現
合作者:201631092112 , 201631092126
碼雲(gitee)地址:https://gitee.com/ulysses497/wordCount
本次作業地址:https://edu.cn
軟體測試第三次作業-WordCount
Wordcount
一、開頭:
(1)合作者:201631062509,201631062609
(2)程式碼地址:https://gitee.com/zhangyangjing/learngit/blob/master/wordcount.jar
(3)本次作業的連結地址:https://edu.c
WordCount軟體測試第三次作業
一、專案簡介
原始碼地址:https://gitee.com/rickeyqi/WordCount.git
專案需求:對程式設計語言原始檔統計字元數、單詞數、行數,統計結果以指定格式輸出到預設檔案中,可執行程式命名為:wc.exe。
軟體測試第三次作業_wordCount實現
wordCount的實現
合作者學號:201631062605,歐連紅 201631062405 黃慶
一本文程式碼
Github程式碼下載連結:https://github.com/OuLianhHong00/WordCo
WorldCount程式碼檢查與優化——軟體測試第三次作業
一.互審程式碼情況:
1.高階功能測試:
發現的問題:無法開啟result.txt,output.txt(儲存輸出結果)等檔案,經判斷這些檔案都是gbk編碼,原程式未指定編碼格式。
修改:指定為utf-8編碼,並忽略讀取特殊字元的編碼錯誤。
第三次作業(WC擴充套件)
(1)碼雲地址: (2)參與者:201631062316,201631062216
WordCount作業思路
使用c語言編寫wc擴充套件功能,並進行相關測試
程式設計實現過程
程式碼說明
1.統計空行
int count_blankL(char*filename_counted)
{
F
第三次作業(互查)
碼雲地址:https://gitee.com/zhujunlin/wc.git 學號:201631062102常顥玟 201631062130楊鑫 一、程式碼自審 本次作業過程中,修正了上次作業中程式碼的不規範性,同時擴充了WordCount中的功能:包括統計空行數量、註釋行以及程式碼行。更為重要的是,在審查
軟件工程——第三次作業(二)
images blog 重定向 logs width 效能 2-2 ima mage 對上周作業中的功能4 (僅由文件重定向讀入,不由控制臺讀入) 做效能分析。
功能4:(還沒改出來,出錯,待續。)
git:
軟件工程——第三次作業(二)
第三次作業(第四次不要電梯了吧)
字符 ace end 內容 第四次 關閉 uri ifs ios 電梯
倉庫地址:https://github.com/vjudge0913/FZU_homework3
題目:
一棟10層的大樓(樓層編號1-10),設有一臺無限載重的電梯,初始時電梯停在1層。電梯移動1層的
軟件測試第三次作業_wordCount實現
定義 plist 內容 alt turn 通配符 得到 遍歷文件夾 and wordCount的實現
合作者學號:201631062605,歐連紅 201631062405 黃慶
一本文代碼
Github代碼下載鏈接:https://github.com
軟件測試第三次作業
blog 資源 代碼 amp 簡潔 ret 所有 執行 eap 一、開頭
(1)合作者:201631062122,201631062321
(2)代碼地址:https://gitee.com/Damocleses/wc/
(3)本次作業鏈接地址:https://edu.cn
1600802047 android 第三次作業(音樂播放器)
一、實現的功能
播放、暫停、上一首、下一首 顯示列表
二、UI介面截圖
第一首歌
第二首歌
第三首歌
第四首歌
list列表
點選播放音樂時圖片旋轉,點選上一首切換上一
軟體測試第5次作業
1.1 實驗步驟
1、構建執行緒組
2、在Sampler中構建http請求,新增相應的網址
3、線上程組的監聽器中新增“用表格察看結果”
4、啟動
為了設計不同的負載,可以線上程組中改變變數值,例如執行緒數等等
1.2 設計三組不同的負載,採集網站相應時間資料,用表格形式畫出網站
軟體測試 : 第6次作業 -- 本地化和國際化測試
實驗步驟
開啟學校官網:www.ntu.edu.cn
點開可能會出現國際化Bug的頁面
沒有發現國際化Bug(因為根本沒有做國際化
由於沒有做國際化,也沒有發現本地化Bug
打開了一個可以切換語言的頁面,切換語言
發現一個Bug
發現的
軟體工程第三次作業——關於軟體質量保障初探
問:對教材與參考資料閱讀後關於軟體質量保障你的體會是什麼?
軟體測試在整個軟體生命週期中的重要性使其存在於整個專案週期,這個環節在整個專案中佔了很大的比重,能主導整個軟體專案的走向。質量這個關鍵詞對於企業來說究竟有多重要自然不必多說,輕則關乎到軟體的最終執行狀態和結果,重則直接影響到企業形象,不
軟體工程第三次作業
小組成員:胡啟霞、何飛、高健、姚鳳、殷健
調研方向:微信和地圖軟體是否解決了人們在生活中遇到的實際性的問題
小組的成員們通過調查問卷的方式,隨機對巢湖學院的學生進行訪問。發現大多數同學,會使用高德地圖來查詢附近吃喝玩樂的地方,優點是節省了不少時間和精力,使用起來方便快捷。微信不僅是年輕人喜歡用的軟體,也是我們
第三次會議(3.25)
make 解決 並且 方法 maker 開發 針對 關於 敵人 人員:全員
地點:地下室
主要議題:
1.分享上周學習成果;
2.討論並解決上周每個人遇到的問題;
3.討論並初步確定遊戲模式問題。
會議結果:
1.房分享了需求分析初稿,針對遊戲模式方面提出了
福大軟工 · 第八次作業(課堂實戰)——項目UML設計(團隊)
uml 團隊 image 技術分享 .com 分享 img alt jpg
福大軟工 · 第八次作業(課堂實戰)——項目UML設計(團隊)
福大軟工 · 第八次作業(課堂實戰)- 項目UML設計(團隊)
課堂 imp 需求 文檔 des 軟工 info post 實戰 團隊信息
隊名:小白吃隊
成員:
盧澤明 031602328
蔡文斌 031602301
葛亮 031602617
劉浩 031602423
張揚 031602345
李泓 031602321
何家偉 0
軟工1816 · 第八次作業(課堂實戰)- 項目UML設計(團隊)
planning 版本 and 網絡 調度 mea 分配 管理 軟件 本次作業博客
團隊信息
隊名:起床一起肝活隊
原組長:
白晨曦(101)
原組員:
李麒 (123)
陳德斌(104)
何裕捷(214)
黃培鑫(217)
王煥仁(233)
林誌華(128)
樂忠豪(