Mercurial > hg > truffle
comparison test/testlibrary/com/oracle/java/testlibrary/Asserts.java @ 17778:a48e16541e6b
8035857: Add tests to verify correctness of operations with BMI1 and LZCNT instructions
Reviewed-by: iveresov, kvn, iignatyev
Contributed-by: filipp.zhinkin@oracle.com
author | iignatyev |
---|---|
date | Sat, 22 Mar 2014 00:26:48 +0400 |
parents | 1a8fb39bdbc4 |
children |
comparison
equal
deleted
inserted
replaced
17777:460f312abe11 | 17778:a48e16541e6b |
---|---|
376 if (!value) { | 376 if (!value) { |
377 error(msg); | 377 error(msg); |
378 } | 378 } |
379 } | 379 } |
380 | 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 A description of the assumption. | |
390 * @throws RuntimeException if strings are not equal. | |
391 */ | |
392 public static void assertStringsEqual(String str1, String str2, | |
393 String msg) { | |
394 String lineSeparator = System.getProperty("line.separator"); | |
395 String str1Lines[] = str1.split(lineSeparator); | |
396 String str2Lines[] = str2.split(lineSeparator); | |
397 | |
398 int minLength = Math.min(str1Lines.length, str2Lines.length); | |
399 String longestStringLines[] = ((str1Lines.length == minLength) ? | |
400 str2Lines : str1Lines); | |
401 | |
402 boolean stringsAreDifferent = false; | |
403 | |
404 StringBuilder messageBuilder = new StringBuilder(msg); | |
405 | |
406 messageBuilder.append("\n"); | |
407 | |
408 for (int line = 0; line < minLength; line++) { | |
409 if (!str1Lines[line].equals(str2Lines[line])) { | |
410 messageBuilder.append(String. | |
411 format("[line %d] '%s' differs " + | |
412 "from '%s'\n", | |
413 line, | |
414 str1Lines[line], | |
415 str2Lines[line])); | |
416 stringsAreDifferent = true; | |
417 } | |
418 } | |
419 | |
420 if (minLength < longestStringLines.length) { | |
421 String stringName = ((longestStringLines == str1Lines) ? | |
422 "first" : "second"); | |
423 messageBuilder.append(String.format("Only %s string contains " + | |
424 "following lines:\n", | |
425 stringName)); | |
426 stringsAreDifferent = true; | |
427 for(int line = minLength; line < longestStringLines.length; line++) { | |
428 messageBuilder.append(String. | |
429 format("[line %d] '%s'", line, | |
430 longestStringLines[line])); | |
431 } | |
432 } | |
433 | |
434 if (stringsAreDifferent) { | |
435 error(messageBuilder.toString()); | |
436 } | |
437 } | |
438 | |
381 private static <T extends Comparable<T>> int compare(T lhs, T rhs, String msg) { | 439 private static <T extends Comparable<T>> int compare(T lhs, T rhs, String msg) { |
382 assertNotNull(lhs, msg); | 440 assertNotNull(lhs, msg); |
383 assertNotNull(rhs, msg); | 441 assertNotNull(rhs, msg); |
384 return lhs.compareTo(rhs); | 442 return lhs.compareTo(rhs); |
385 } | 443 } |