单元测试

第一题
(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";
  }

  }

复制代码第二题

 

  import java.util.Scanner;

  public class Test {
  public void test(){
  Scanner input = new Scanner(System.in);
  System.out.print("请输入英文:");
  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("颠倒顺序后的结果为:"+result.toString());
  }
  }

  (2)实例化这个方法:

  import java.util.Scanner;

  public class Text{
  public static void main(String[] args){
  Test test = new Test();
  test.test();

  }
  }

  2.单元测试:

  import static org.junit.Assert.*;

  import org.junit.Test;

  public class TestRun {

  @Test
  public void test() {
  String str = "how are you";
  }

  }

 

posted @ 2016-04-01 10:57  simon940816  阅读(201)  评论(0编辑  收藏  举报