Java Utililty Methods Assert Equal

List of utility methods to do Assert Equal

  1. HOME
  2. Java
  3. A
  4. Assert Equal

Description

The list of methods to do Assert Equal are organized into topic(s).

Method

double assertAboveEqual(final double number, final double value)
assert Above Equal
if (number < value) {
 return value;
return number;
void assertApproxEquals(double a, double b, double relative, double absolute)
assert Approx Equals
assertApproxEquals(a, b, relative, absolute, null);
boolean assertArrayEquals(double[] p1, double[] p2, double eps)
assert Array Equals
if (p1.length != p2.length) {
 return false;
for (int i = 0; i < p1.length; i++) {
 if (Math.abs(p1[i] - p2[i]) > eps) {
 return false;
return true;
void assertArrayLengthEqual(Object[] array, String name, Object[] array1, String name1)
Check if the lengths of the two arrays are equal.
if (array.length != array1.length) {
 throw new IllegalArgumentException("The length of " + name + " should be the same as that of " + name1);
boolean assertCharacterArraysEqual(char[] first, char[] second)
Asserts that the specified first array of characters is identical to the specified second array of characters.
int firstLength = first.length;
int secondLength = second.length;
if (firstLength != secondLength) {
 return false;
for (int index = 0; index < firstLength; index++) {
 char firstCharacter = first[index];
 char secondCharacter = second[index];
...
void assertDatesEqual(Calendar first, Calendar second)
assert Dates Equal
if (first == null && second != null) {
 throw new AssertionError("dates are not equal. first is null, second is not");
} else if (first != null && second == null) {
 throw new AssertionError("dates are not equal. second is null, first is not");
boolean yearsNotEqual = first.get(Calendar.YEAR) != second.get(Calendar.YEAR);
boolean monthsNotEqual = first.get(Calendar.MONTH) != second.get(Calendar.MONTH);
boolean daysNotEqual = first.get(Calendar.DAY_OF_MONTH) != second.get(Calendar.DAY_OF_MONTH);
...
boolean assertEqual(final double d1, final double d2, final double precisionRange)
Asserts if the given two doubles are equal within the given precision range by the operation:
 Math.abs(d1 - d2) < precision 
.
return Math.abs(d1 - d2) < precisionRange;
void assertEqual(Object obj1, Object obj2)
Method assertEqual.
if (obj1 == null || obj2 == null) {
 throw new RuntimeException("assertion: " + obj1 + " must be equal to " + obj2);
if (obj1 != null && !obj1.equals(obj2)) {
 throw new RuntimeException("assertion: " + obj1 + " must be equal to " + obj2);
if (obj2 != null && !obj2.equals(obj1)) {
 throw new RuntimeException("assertion: " + obj1 + " must be equal to " + obj2);
...
void assertEquality(Object original, Object equal, Object... notEqual)
assert Equality
if (!original.equals(equal)) {
 throw new AssertionError("Objects where not equal " + original + " != " + equal);
if (original.hashCode() != equal.hashCode()) {
 throw new AssertionError("Equal objects did not have same hash :" + original + "(" + original.hashCode()
 + ")" + " " + equal + "(" + equal.hashCode() + ")");
for (Object notEqualObject : notEqual) {
...
void assertEquals(double x, double y)
assert Equals
assertEquals(x, y, 1e-10);


AltStyle によって変換されたページ (->オリジナル) /