1. 程式人生 > >軟件質量測試 第二周 wordcount 作業

軟件質量測試 第二周 wordcount 作業

包括 生成 tab 時間 ces add 圖片 borde col

一.github地址

https://github.com/WKX121/WC

二.PSP

PSP表格

PSP2.1

PSP階段

預估耗時

(分鐘)

實際耗時

(分鐘)

Planning

計劃

25 25

· Estimate

· 估計這個任務需要多少時間

25 25

Development

開發

300 340

· Analysis

· 需求分析 (包括學習新技術)

40 40

· Design Spec

· 生成設計文檔

- -

· Design Review

· 設計復審 (和同事審核設計文檔)

- -

· Coding Standard

· 代碼規範 (為目前的開發制定合適的規範)

- -

· Design

· 具體設計

40 40

· Coding

· 具體編碼

180 200

· Code Review

· 代碼復審

40 60

· Test

· 測試(自我測試,修改代碼,提交修改)

40 100

Reporting

報告

120 180

· Test Report

· 測試報告

60 60

· Size Measurement

· 計算工作量

30 20

· Postmortem & Process Improvement Plan

· 事後總結, 並提出過程改進計劃

60 60

合計

960 1150

三.思路

1.根據需求首先最傳入main函數中的args解析出對應的命令,文件名

2.-c命令通過每次fgetc使wc_char加一

3.-w通過對空格和,的判斷使wc_word加一

4.-l通過對/n判斷使wc_line加一

四.程序的設計實現

通過對args不同數值的情況來處理各種統計模式,看對應哪個命令就調用相應的處理程序進行處理。然後將計數後的結果輸出到指定txt文件當中。

五.代碼說明

#include <stdio.h>
#include <stdlib.h>
#include 
<conio.h> #include <string.h> int main(int argc, char * argv[]) { int wc_char = 0; int wc_word = 1; int wc_line = 1; char filename[80]; FILE *fp = NULL; if (argc == 3) { fp = fopen(argv[2], "r"); if (fp == NULL) { printf("打開有誤!\n"); printf("請按enter鍵繼續...."); _getch(); exit(0); //... } char ch; while (1) { ch = fgetc(fp); wc_char++; if (ch == ||ch==,) { wc_word++; } else if (ch == \n) { wc_word++; wc_line++; } else if (ch == EOF) { break; } } if (strcmp(argv[1],"-c")==0) { printf("The char count is %d\n", wc_char); fp = fopen("result.txt","w"); fprintf(fp,"字符數:%d\n", wc_char); } else if (strcmp(argv[1],"-w")==0) { printf("The word count is %d\n", wc_word); fp = fopen("result.txt","w"); fprintf(fp,"單詞數:%d\n", wc_word); } else if (strcmp(argv[1],"-l")==0) { printf("The line count is %d\n", wc_line); fp = fopen("result.txt","w"); fprintf(fp,"行數:%d\n", wc_line); } fclose(fp); } if (argc == 4) { fp = fopen(argv[3], "r"); if (fp == NULL) { printf("打開有誤!\n"); printf("請按enter鍵繼續...."); _getch(); exit(0); //... } char ch; while (1) { ch = fgetc(fp); wc_char++; if (ch == ||ch==,) { wc_word++; } else if (ch == \n) { wc_word++; wc_line++; } else if (ch == EOF) { break; } } if (strcmp(argv[1],"-c")==0&&strcmp(argv[2],"-w")==0) { printf("The char count is %d\n", wc_char); printf("The word count is %d\n", wc_word); fp = fopen("result.txt","w"); fprintf(fp,"字符數:%d\n單詞數:%d\n", wc_char,wc_word); } if (strcmp(argv[1],"-c")==0&&strcmp(argv[2],"-l")==0) { printf("The char count is %d\n", wc_char); printf("The line count is %d\n", wc_line); fp = fopen("result.txt","w"); fprintf(fp,"字符數%d\n行數:%d\n", wc_char,wc_line); } if (strcmp(argv[1],"-w")==0&&strcmp(argv[2],"-l")==0) { printf("The word count is %d\n", wc_word); printf("The line count is %d\n", wc_line); fp = fopen("result.txt","w"); fprintf(fp,"單詞數:%d\n行數:%d\n", wc_word,wc_line); } fclose(fp); } if (argc == 5) { fp = fopen(argv[4], "r"); if (fp == NULL) { printf("打開有誤!\n"); printf("請按enter鍵繼續...."); _getch(); exit(0); //... } char ch; while (1) { ch = fgetc(fp); wc_char++; if (ch == ||ch==,) { wc_word++; } else if (ch == \n) { wc_word++; wc_line++; } else if (ch == EOF) { break; } } if (strcmp(argv[1],"-c")==0) { printf("The char count is %d\n", wc_char); } else if (strcmp(argv[1],"-w")==0) { printf("The word count is %d\n", wc_word); } else if (strcmp(argv[1],"-l")==0) { printf("The line count is %d\n", wc_line); } if (strcmp(argv[2],"-c")==0) { printf("The char count is %d\n", wc_char); } else if (strcmp(argv[2],"-w")==0) { printf("The word count is %d\n", wc_word); } else if (strcmp(argv[2],"-l")==0) { printf("The line count is %d\n", wc_line); } if (strcmp(argv[3],"-c")==0) { printf("The char count is %d\n", wc_char); } else if (strcmp(argv[3],"-w")==0) { printf("The word count is %d\n", wc_word); } else if (strcmp(argv[3],"-l")==0) { printf("The line count is %d\n", wc_line); } fp = fopen("result.txt","w"); fprintf(fp,"字符數:%d\n單詞數:%d\n行數:%d\n", wc_char,wc_word,wc_line); fclose(fp); } }

六.測試設計過程

10個測試:

1.-c

2.-w

3.-l

4.-c -w

5.-c -l

6.-w -l

7.-c -w -l

8.復雜符號測試

9.代碼測試

10.復雜代碼測試

技術分享圖片

技術分享圖片

七.參考文獻

http://www.cnblogs.com/cool125/p/7560596.html

軟件質量測試 第二周 wordcount 作業