单元测试
第一题
(1)import java.util.HashMap; 2 import java.util.Iterator; 3 import java.util.Map; 4 import java.util.Set; 5 private wordFreq (string strWord){
wordsMap = this.getAarryy(strwords);
} 6 7 8 public Map <String,Integer> getArray(String strWords){
string[] wordsArray = str.split(" "); 10 Map<String, Integer> wordsMap = new HashMap<String, Integer>(); 11 for (String word : wordsArray) { 12 13 if (wordsMap.containsKey(word)) { 14 wordsMap.put(word, wordsMap.get(word) + 1); 15 } else { 16 wordsMap.put(word, 1); 17 } 18 } 19 public void OutResult(){ 20 Set<String> setKey = wordsMap.keySet(); 21 Iterator<String> itKey = setKey.iterator(); 22 while (itKey.hasNext()) { 23 String word = itKey.next().toString(); 24 int count = wordsMap.get(word); 25 26 System.out.println("单词 " + word + " 出现" + count + "次"); 27 28 } 29 } 30 31 }
(2)
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 WordFreq {
public static void main(String[] args) {
Test1 test1 = new Test1();
test1.test();
}
}
(3)
import static org.junit.Assert.*;
import org.junit.Test;
public class Word {
@Test
public void test() {
String Str = "Hello World My First Unit Test";
}
}