Software Test second Job

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%.

1) Import java.util.ArrayList;

Import java.util.Collections;

Import Java.util.Comparator;

Import Java.util.HashMap;

Import java.util.List;

Import Java.util.Map;

Import Java.util.Map.Entry;

public class Mapsort {

public static void Main (string[] args) {

String str = "Hello World My first Hello Unit Test";

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

map<string, integer> map = new hashmap<string, integer> ();

for (String S:items) {

if (Map.containskey (s))

Map.put (S, map.get (s) + 1);

else {

Map.put (S, 1);

}

}

list<entry<string, integer>> list = new arraylist<entry<string, integer>> ();

For (entry<string, integer> entry:map.entrySet ()) {

List.add (entry);

}

Collections.sort (list, new Entrycomparator ());

For (entry<string, integer> obj:list) {

System.out.println (Obj.getkey () + "\ T" + obj.getvalue ());

}

}

}

Class Entrycomparator implements Comparator<entry<string, integer>> {

public int Compare (entry<string, integer> O1, entry<string, integer> O2) {

return O1.getvalue () > O2.getvalue ()? 0:1;

}

}

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%.

1) package junit4.demo;

import Java.util.Scanner;

Public class Reversal {

Public Static void Main (string[] args) {

Scanner input = new Scanner (System. in);

System. out. Print ("Please enter English:");

String str = input.nextline ();

string[] Strarr = Str.split ("\\s+|[,]");

StringBuffer result = new stringbuffer ();

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

Result.append (Strarr[i] + "");

}

Result.setcharat (Str.length ()-0, (char) 0);

System. out. println ("Reversed order results are:" +result.tostring ());

}

}

Software Test second Job

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.