Minjiang College School of the next 2015-2016 years software testing Course-second assignment (personal assignment)

Source: Internet
Author: User

(1) Write a program that parses the frequency of occurrences of each word in a string and displays the word and the frequency at which it appears. (the words are separated by a space, such as "Hello World My First Unit Test");

(2) Writing unit tests for testing;

(3) Use Elcemma to view code coverage, requiring coverage to reach 100%.

Package cn.lin.test;



Import Java.util.HashMap;

Import Java.util.Map;



Import Org.junit.Test;

public class Test2 {

@Test

public void index () {

String strwords = "ADB abc abc KK";



string[] Words_array = Strwords.split ("");

Map<string,integer> words_map=new hashmap<string, integer> ();

int arrlength = Words_array.length;

for (int i=0;i<arrlength;i++) {

if (!words_map.containskey (Words_array[i])) {

Words_map.put (Words_array[i], 1);

System.out.println (Words_array[i]);

System.out.println ("appearing");

System.out.println (Words_map.put (Words_array[i], 1));

System.out.println ("Times");



}else{

int currentnum = Words_map.get (words_array[i]) +1;

Words_map.remove (Words_array[i]);

Words_map.put (Words_array[i], currentnum);

System.out.println (Words_array[i]);

System.out.println ("appearing");

System.out.println (Words_map.put (Words_array[i], currentnum));

System.out.println ("Times");

}



}

}





}





1. Use of the Learning Unit test Code Coverage tool

(1) The order of words in an English sentence is reversed and then output. For example, enter "How IS is", output "you is how";

(2) Writing unit tests for testing;

(3) Use Elcemma to view code coverage, requiring coverage to reach 100%.

Import Java.util.Scanner;

public class Test {



public void reverse (String str) {

string[] Wordarray = Str.split ("");

System.out.print ("Invert output:");

for (int i = wordarray.length-1; I >= 0; i--) {



System.out.print (Wordarray[i] + "");

}

}



public static void Main (string[] args) {

Scanner input = new Scanner (system.in);

System.out.println ("Please enter an English sentence:");

String str = input.nextline ();

Test test = new test ();

Test.reverse (str);

}

}

Minjiang College School of the next 2015-2016 years software testing Course-second assignment (personal assignment)

Related Article

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.