01: /**
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */package com.tc.test;
04:
05: import junit.framework.Assert;
06:
07: /**
08: * Contains a simple method that checks two arrays for equality. Checks that elements at the same index in both arrays
09: * are equal; checks that all other pairs of elements are not equal. (Checks equality both ways, to make sure it's
10: * properly transitive.) Also checks that hash codes are equal when objects are equal.
11: */
12: public class EqualityChecker {
13:
14: public static void checkArraysForEquality(Object[] env1,
15: Object[] env2) {
16: checkArraysForEquality(env1, env2, true);
17: }
18:
19: public static void checkArraysForEquality(Object[] env1,
20: Object[] env2, boolean checkHashCode) {
21: if (env1 == null && env2 == null) {
22: return;
23: }
24: for (int i = 0; i < env1.length; ++i) {
25: for (int j = 0; j < env2.length; ++j) {
26: if (i == j) {
27: Assert.assertEquals(env1[i], env2[j]);
28: if (checkHashCode)
29: Assert.assertEquals(env1[i].hashCode(), env2[j]
30: .hashCode());
31:
32: Assert.assertEquals(env1[i], env1[i]);
33: if (checkHashCode)
34: Assert.assertEquals(env1[i].hashCode(), env1[j]
35: .hashCode());
36:
37: Assert.assertEquals(env2[i], env2[i]);
38: if (checkHashCode)
39: Assert.assertEquals(env2[i].hashCode(), env2[j]
40: .hashCode());
41: } else {
42: Assert
43: .assertFalse(
44: "Object in array #1 at position "
45: + i
46: + " is equal to the object in the same array at position "
47: + j, env1[i]
48: .equals(env1[j]));
49: Assert
50: .assertFalse(
51: "Object in array #1 at position "
52: + i
53: + " is equal to object in array #2 at position "
54: + j, env1[i]
55: .equals(env2[j]));
56: Assert
57: .assertFalse(
58: "Object in array #2 at position "
59: + i
60: + " is equal to the object in the same array at position "
61: + j, env2[i]
62: .equals(env2[j]));
63: }
64: }
65: }
66: }
67:
68: }
|