I. Introduction of the topic
Write a program that calculates the frequency of English words for a set of text documents.
Second, the source of GitHub links
Https://github.com/liuxu8257/zuoye2
Third, the design of the module test cases, test results
This implementation has three methods, the three methods were tested:
Three Tests to get the string method in the file:
1 @Test 2 public void Tsetnullfile () throws ioexception{3 file file =null; 4 Deal dos = new Deal (); 5
string result = dos.getstring (file); 6 assertnull (result); 7 } 8 9 @Test10 public void Testnocontentfile () throws IOException {11 File file =new file ("D:/empty.txt"); Deal dos = new Deal (); String result = dos.getstring (file) , Assertequals ("", result); }16 17 @Test18 public void Testnormalfile () throws IOException { file file =new file ("D:/normal.txt"); 20 Deal dos = new Deal (); String result = dos.getstring (file) , Assertequals ("hello,my name is matin,i am thirty-three years old.", result); (+ }
The methods for extracting words are tested as follows:
1 @Test 2 public void Testtakeword () throws IOException {3 File file =new file ("D:/normal.txt"); 4 Deal D OS = new Deal (); 5 String str = dos.getstring (file), 6 list<string> result = Dos.takeword (str); 7 for (String show: Result) {8 System.out.print (show); 9 }10 }
The test prints the result: Hello my name is matin I am thirty three years old
The following tests are done for calculating the word frequency:
1 @Test 2 public void Testfrequency () {3 list<string> List = new Arraylist<string> (); 4 List.add ("three"); 5 List.add ("three"), 6 list.add ("a"), 7 list.add ("a"), 8 list.add ("three"), 9 list.add (" One "), List.add (" one "), Deal dos = new Deal (); HashMap map = dos.getfrequency (list); 14 the Iterator iter = Map.entryset (). Iterator (); + (Iter.hasnext ()) {map.entry Entry = (map.entry) Iter.next (); string key = (String) entry.getkey (); int val = (Integer) entry.getvalue (); System.out.println (key+ ":" +val); }22 }
The test prints the result:
Three:3
Two:2
One:2
Test results:
Iv. problems and solutions, experience.
This homework I learned some of the software testing operations, a preliminary understanding of software testing has stimulated a strong interest in learning will be good to learn such courses
Software Engineering Practice Job 2