@@ -33,6 +33,10 @@ private VerifyUtil() {
3333 * 生成最大数值
3434 */
3535 private static final int GENERATE_MAX_VALUE = 1000 ;
36+ /** 是否打印比对情况,自己控制是否打印比对情况 */
37+ private final static boolean WHETHER_TO_PRINT_THE_COMPARISON = true ;
38+ /** 分隔符 */
39+ private final static String DELIMITER = "-------------------------------------------------------------------------" ;
3640
3741 /**
3842 * <p>
@@ -50,17 +54,23 @@ private VerifyUtil() {
5054 public static boolean verify (final Function <List <Number >, List <Number >> sortFunction ,
5155 boolean isAsc , boolean isFloat ) {
5256 for (int i = 0 ; i < VERIFY_COUNT ; i ++) {
57+ if (WHETHER_TO_PRINT_THE_COMPARISON )
58+ System .out .println (DELIMITER );
5359 // 1.生成数组
5460 List <Number > generationDataList = IntStream .rangeClosed (1 , GENERATE_COUNT ).parallel ().mapToObj (v -> {
5561 return isFloat ? (GENERATE_MAX_VALUE * Math .random ()) : (int ) (GENERATE_MAX_VALUE * Math .random ());
5662 }).collect (Collectors .toList ());
5763 // 2.算法排序得出结果
5864 List <Number > sortResult = sortFunction .apply (generationDataList );
65+ if (WHETHER_TO_PRINT_THE_COMPARISON )
66+ System .out .println ("算法排序结果为:" +sortResult );
5967 // 3.正确的排序结果
6068 List <Number > successAscList = generationDataList .stream ()
6169 .sorted ().collect (Collectors .toList ());
6270 if (!isAsc )
6371 Collections .reverse (successAscList );
72+ if (WHETHER_TO_PRINT_THE_COMPARISON )
73+ System .out .println ("正确排序结果为:" +successAscList );
6474 boolean success = compareTwoSets (sortResult , successAscList );
6575 if (!success ) {
6676 // 自己写的算法排序结果错误
@@ -87,7 +97,10 @@ public static boolean verify(final Function<List<Number>, List<Number>> sortFunc
8797 */
8898 public static boolean verify (final Function <int [], int []> sortFunction ,
8999 boolean isAsc ) {
100+ long startTime = System .currentTimeMillis ();
90101 for (int i = 0 ; i < VERIFY_COUNT ; i ++) {
102+ if (WHETHER_TO_PRINT_THE_COMPARISON )
103+ System .out .println (DELIMITER );
91104 int [] generateArr = new int [GENERATE_COUNT ];
92105 List <Integer > generateList = new ArrayList <>(GENERATE_COUNT );
93106 for (int j = 0 ; j < GENERATE_COUNT ; j ++) {
@@ -99,16 +112,25 @@ public static boolean verify(final Function<int[], int[]> sortFunction,
99112 for (int sortResult : sortResults ) {
100113 sortList .add (sortResult );
101114 }
115+ if (WHETHER_TO_PRINT_THE_COMPARISON )
116+ System .out .println ("算法排序结果为:" +sortList );
102117 Collections .sort (generateList );
103118 if (!isAsc )
104119 Collections .reverse (generateList );
120+ if (WHETHER_TO_PRINT_THE_COMPARISON )
121+ System .out .println ("正确排序结果为:" +generateList );
105122 boolean success = compareTwoSets (sortList , generateList );
106123 if (!success ) {
107124 System .out .println ("自己写的算法排序结果为:\r \n " +sortList );
108125 System .out .println ("正确排序结果为:\r \n " +generateList );
109126 return success ;
110127 }
111128 }
129+ long millisecond = (System .currentTimeMillis () - startTime );
130+ System .out .println ("验证结果次数:" +VERIFY_COUNT +"次\t " +"数组大小:" +GENERATE_COUNT +"个元素" );
131+ System .out .println ("总耗时:" +millisecond +"毫秒" );
132+ System .out .println ("总耗时:" +millisecond /1000 +"秒" );
133+
112134 return true ;
113135 }
114136
0 commit comments