• 单元测试


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

      }

  • 相关阅读:
    kafka 学习笔记
    awk命令详解
    apache 的 配置项
    Apache 的 httpd.conf 详解
    如何设置httpd-mpm-conf的参数
    apache 服务器概述--安装(一)
    centos 修改时区
    docker(三)docker镜像和镜像发布方法
    docker(二)部署docker容器虚拟化平台
    sql的存储过程使用详解--基本语法
  • 原文地址:https://www.cnblogs.com/chenchaofan/p/5344169.html
Copyright © 2020-2023  润新知