From d86c49c5395e926f0a69accaf0c76d5daec010b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B7=A6=E7=A8=8B=E4=BA=91?= Date: Sun, 7 Jun 2020 18:09:07 +0800 Subject: [PATCH] add test --- src/class09/Code01_LowestLexicography.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/class09/Code01_LowestLexicography.java b/src/class09/Code01_LowestLexicography.java index 3768253..c5bc3dc 100644 --- a/src/class09/Code01_LowestLexicography.java +++ b/src/class09/Code01_LowestLexicography.java @@ -27,10 +27,7 @@ public class Code01_LowestLexicography { // 已经使用过的字符串的下标,在use里登记了,不要再使用了 // 之前使用过的字符串,拼接成了-> path // 用all收集所有可能的拼接结果 - public static void process(String[] strs, - HashSet use, - String path, - ArrayList all) { + public static void process(String[] strs, HashSet use, String path, ArrayList all) { if (use.size() == strs.length) { all.add(path); } else { @@ -68,7 +65,7 @@ public class Code01_LowestLexicography { char[] ans = new char[(int) (Math.random() * strLen) + 1]; for (int i = 0; i < ans.length; i++) { int value = (int) (Math.random() * 5); - ans[i] = (char) (97 + value); + ans[i] = (Math.random() <= 0.5) ? (char) (65 + value) : (char) (97 + value); } return String.valueOf(ans); } @@ -95,10 +92,21 @@ public class Code01_LowestLexicography { int arrLen = 6; int strLen = 5; int testTimes = 100000; + String[] arr = generateRandomStringArray(arrLen, strLen); + System.out.println("先打印一个生成的字符串"); + for (String str : arr) { + System.out.print(str + ","); + } + System.out.println(); + System.out.println("test begin"); for (int i = 0; i < testTimes; i++) { String[] arr1 = generateRandomStringArray(arrLen, strLen); String[] arr2 = copyStringArray(arr1); if (!lowestString1(arr1).equals(lowestString2(arr2))) { + for (String str : arr1) { + System.out.print(str + ","); + } + System.out.println(); System.out.println("Oops!"); } }