(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)