2015-04-24 Practice Assignment 2

Source: Internet
Author: User

I. Introduction of the topic

Write a program that calculates the frequency of English words for a set of text documents.

Ability to practise:

Basic source code control skills such as regression testing, unit testing, performance analysis, performance optimization, etc.

Second, the source of GitHub links

Https://github.com/WreckBear/2ndHomeWork

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 DoSomething dos = new  dosomething (); 5 String result =  dos.getstring (file); 6  Assertnull (re Sult); 7 } 8 9  @Test10 public void Testnocontentfile () throws  IOException {One file file =new file ("d:/empty.t XT ""), dosomething dos = new  dosomething (), String result =  dos.getstring (file), and Assertequals ("" Span>,result) }16  @Test18 public void Testnormalfile () throws  IOException {file file =new Fil E ("D:/normal.txt" ); dosomething dos = new  dosomething (); String result =  dos.getstring (file); 22 Assertequals ("Hello,my name is matin,i am thirty-three years old.") , result);              
The methods for extracting words are tested as follows:
    @Test 2 public     void Testtakeword () throws IOException {3         File file =new file ("D:/normal.txt"); 4         DoS Omething dos = new dosomething (); 5         String str = dos.getstring (file); 6         list<string> result =
        
          Dos.takeword (str); 7 
          
            for

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:

    @Test 2 public     void testfrequency () {3         list<string> List = new arraylist<string>(); 4         List.add ("Hello"), 5         list.add ("Hello"),6         list.add ("Bye"), 7 list.add ("Bye"), 8 List.add ( "Hello"); 9 List.add ("queue"), List.add ("Hello"), dosomething dos = new dosomething (), HashMap map = do S.getfrequency (list), Iterator iter = map.entryset (). Iterator (); + While (Iter.hasnext ()) {Map.entry Entry = (map.entry) Iter.next (); string key = (String) entry.getkey (); int val = (Integer) entry.getval UE (); System.out.println (key+ ":" + }22}           

The test prints the result:

Hello:4

Queue:1

  Bye:2

  Test results:

  

Iv. problems and solutions, experience

  Problem:

The method that obtains the word from the article is imperfect, for example if the article appears the continuous non-character, may obtain the word to be cut off, this method continues to improve.

Experience:

Although this task is not difficult, not complex, not the obvious results of the test, but also can clearly feel the convenience of JUnit to test, lamented the simplicity of JUnit magic.

In addition this test work also let oneself test have a different understanding, again is not simple write a Mian method test, but with comprehensive to method safety and robustness of detection, can not say receipt.

  

2015-04-24 Practice Assignment 2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.