First, the project Github Address
https://github.com/huangzihaohzh/WordCounter
Two, PSP form
PSP2.1 | Personal Software Process Stages | Estimated time consuming (minutes) | The actual time-consuming (minutes) |
Planning | plan | 60 | 90 |
· Estimate | • Estimate how much time this task requires | 60 | 90 |
Development | Develop | 1260 | 1320 |
· Analysis | · demand analysis | 60 | 45 |
· Design Spec | Generate design documents | 60 | 90 |
· Design Review | · Design Review | 60 | 45 |
· Coding Standard | · Code Specification | 30 | 90 |
· Design | · Specific design | 60 | 150 |
· Coding | · Specific coding | 540 | 480 |
· Code Review | · Code Review | 90 | 60 |
· Test | · Test (self-test, modify the code, submit modifications) | 360 | 360 |
Reporting | report | 180 | 160 |
· Test Report | · testing report | 120 | 120 |
· Size Measurement | · Computing workload | 30 | 20 |
· Postmortem & Process Improvement Plan | · Hindsight, and propose process improvement plan | 30 | 20 |
total | 1500 | 1570 | |
Third, the problem-solving ideas
- Read the requirements document (personal project documentation), requires a general understanding of the topic. From the requirements document, based on questions asked to write a user input parameters, the text file character, word, line number and display technology. It also needs to be tested for the program, and as required, fill out the form and PSP blogging;
- In order to design more rational decision at first reading "Building of the law" for the formulation of PSP table, measure the workload and quality of design and regression testing of software engineering and so on;
- For this project, the user's input parameters need to be checked and divided into two groups and file names, consider the use of regular expressions to be treated, for the realization of all kinds of counting function also consider the use of regular expressions to achieve, for "- a "processing options corresponding lines of code / blank lines / comment line is relatively complex, the need to find further information.
Fourth, the design and implementation process
Mainly related to the realization
- Check user input: use regular expressions for parameters and addresses entered by the user to check, check whether the input parameter format and address format is correct;
- Parameter extraction and storage: classified and stored user input, the user input parameters to the parameter list stored in the address / name of the file into a string field.
Different operating parameters according to the user: The method of the argument list, call parameters corresponding to different count values acquired and displayed.
Flow diagram of the
Five test
unit test
Test code
public class Test {
private TextFile textFile = null;
//Constructor
public Test(String filePath) throws Exception{
this.textFile = new TextFile(filePath);
}
//测试TextFile.charNumCounter()
public void testCharNumCounter(){
int charNum = textFile.charNumCounter();
if(charNum>=0)
System.out.println("文件字符数为:"+charNum);
else
System.out.println("字符数计算出错");
}
//测试TextFile.wordNumCounter()
public void testWordNumCounter(){
int wordNum = textFile.wordNumCounter();
if(wordNum>=0)
System.out.println("文件单词数为:"+wordNum);
else
System.out.println("单词计算出错");
}
//测试TextFile.lineNumCounter()
public void testLineNumCounter() throws IOException {
int lineNum = textFile.lineNumCounter();
if(lineNum>=0)
System.out.println("文件行数为:"+lineNum);
else
System.out.println("行数计算错误");
}
}
Test Results
D:\123.txt
文件字符数为:80
文件单词数为:6
文件行数为:2
Overall test
Empty file tests (there are a blank line, file size 0KB)
Command: java -jar wc.jar -c -w -l " D: \ test_txt \ Empty.txt"
Test results:
文件字符数为:0
文件单词数为:0
文件行数为:1
Only one character test file
Command: java -jar wc.jar -c -w -l " D: \ test_txt \ OnlyOneChar.txt"
Test results:
文件字符数为:1
文件单词数为:0
文件行数为:1
Only one word of the test file
Command: java -jar wc.jar -c -w -l " D: \ test_txt \ OnlyOneWord.txt"
Test results:
文件字符数为:4
文件单词数为:1
文件行数为:1
Only one line of the test file
Command: java -jar wc.jar -c -w -l " D: \ test_txt \ OnlyOneLine.txt"
Test results:
文件字符数为:59
文件单词数为:3
文件行数为:1
A typical test source file
Command: java -jar wc.jar -c -w -l " D: \ test_txt \ Current.txt"
Test results:
文件字符数为:27
文件单词数为:6
文件行数为:2
-x parameter test
Command: java -jar wc.jar -x -c -w -l
test results:
D:\test_txt\OnlyOneChar.txt
文件字符数为:1
文件单词数为:0
文件行数为:1
Test image
to sum up
In this project development process, the following points summarize the lesson:
- To increase the pre-planning and investment analysis time
- Refused to delay disease, early start and early end