test/testlibrary/com/oracle/java/testlibrary/Asserts.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File 8035857 Sdiff test/testlibrary/com/oracle/java/testlibrary

test/testlibrary/com/oracle/java/testlibrary/Asserts.java

Print this page
rev 6131 : 8035857: Add tests to verify correctness of operations with BMI1 and LZCNT instructions
Reviewed-by: duke
Contributed-by: filipp.zhinkin@oracle.com


 361      *
 362      * @see #assertTrue(boolean, String)
 363      */
 364     public static void assertTrue(boolean value) {
 365         assertTrue(value, "Expected value to be true");
 366     }
 367 
 368     /**
 369      * Asserts that {@code value} is {@code true}.
 370      *
 371      * @param value The value assumed to be true.
 372      * @param msg A description of the assumption.
 373      * @throws RuntimeException if the assertion isn't valid.
 374      */
 375     public static void assertTrue(boolean value, String msg) {
 376         if (!value) {
 377             error(msg);
 378         }
 379     }
 380 




























































 381     private static <T extends Comparable<T>> int compare(T lhs, T rhs, String msg) {
 382         assertNotNull(lhs, msg);
 383         assertNotNull(rhs, msg);
 384         return lhs.compareTo(rhs);
 385     }
 386 
 387     private static String format(Object o) {
 388         return o == null? "null" : o.toString();
 389     }
 390 
 391     private static void error(String msg) {
 392         throw new RuntimeException(msg);
 393     }
 394 
 395 }


 361      *
 362      * @see #assertTrue(boolean, String)
 363      */
 364     public static void assertTrue(boolean value) {
 365         assertTrue(value, "Expected value to be true");
 366     }
 367 
 368     /**
 369      * Asserts that {@code value} is {@code true}.
 370      *
 371      * @param value The value assumed to be true.
 372      * @param msg A description of the assumption.
 373      * @throws RuntimeException if the assertion isn't valid.
 374      */
 375     public static void assertTrue(boolean value, String msg) {
 376         if (!value) {
 377             error(msg);
 378         }
 379     }
 380 
 381     /**
 382      * Asserts that two strings are equal.
 383      *
 384      * If strings are not equals, then exception message
 385      * will contain {@code msg} followed by list of mismatched lines.
 386      *
 387      * @param str1 First string to compare.
 388      * @param str2 Second string to compare.
 389      * @param msg Adescription of the assumption.
 390      * @throws RuntimeException if strings are not equal.
 391      */
 392     public static void assertStringsEnqual(String str1, String str2,
 393                                            String msg) {
 394         String str1Lines[] = str1.split(System.
 395                                         getProperty("line.separator"));
 396         String str2Lines[] = str2.split(System.
 397                                         getProperty("line.separator"));
 398 
 399         int minLength = Math.min(str1Lines.length, str2Lines.length);
 400         String longestStringLines[] = ((str1Lines.length == minLength) ?
 401                                        str2Lines : str1Lines);
 402         int line;
 403 
 404         boolean stringsAreDifferent = false;
 405 
 406         StringBuilder messageBuilder = new StringBuilder(msg);
 407 
 408         messageBuilder.append("\n");
 409 
 410         for (line = 0; line < minLength; line++) {
 411             if (!str1Lines[line].equals(str2Lines[line])) {
 412                 messageBuilder.append(String.
 413                                       format("[line %d] '%s' differs " +
 414                                              "from '%s'\n",
 415                                              line,
 416                                              str1Lines[line],
 417                                              str2Lines[line]));
 418                 stringsAreDifferent = true;
 419             }
 420         }
 421 
 422         if (line < longestStringLines.length) {
 423             String stringName = ((longestStringLines == str1Lines) ?
 424                                  "first" : "second");
 425             messageBuilder.append(String.format("Only %s string contains " +
 426                                                 "following lines:\n",
 427                                                 stringName));
 428             stringsAreDifferent = true;
 429             for(; line < longestStringLines.length; line++) {
 430                 messageBuilder.append(String.
 431                                       format("[line %d] '%s'", line,
 432                                              longestStringLines[line]));
 433             }
 434         }
 435 
 436         if (stringsAreDifferent) {
 437             error(messageBuilder.toString());
 438         }
 439     }
 440 
 441     private static <T extends Comparable<T>> int compare(T lhs, T rhs, String msg) {
 442         assertNotNull(lhs, msg);
 443         assertNotNull(rhs, msg);
 444         return lhs.compareTo(rhs);
 445     }
 446 
 447     private static String format(Object o) {
 448         return o == null? "null" : o.toString();
 449     }
 450 
 451     private static void error(String msg) {
 452         throw new RuntimeException(msg);
 453     }
 454 
 455 }
test/testlibrary/com/oracle/java/testlibrary/Asserts.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File