Skip to content

Commit 062af3e

Browse files
committed
Added int array equal check to Tester.
1 parent 413e10c commit 062af3e

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

Tester.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
package com.cunningdj.grokJava;
2+
import java.util.Arrays;
23
import java.util.HashMap;
34

45
public class Tester {
@@ -30,6 +31,47 @@ public Tester() {
3031

3132

3233
// PUBLIC
34+
public void testEquals(Object expected, Object actual, String testTitle) {
35+
if (expected == actual) {
36+
printTestSuccess(testTitle);
37+
} else {
38+
printTestFailure(testTitle, String.valueOf(expected), String.valueOf(actual));
39+
}
40+
}
41+
42+
public void testIntArrayEquals(int[] expected, int[] actual, String testTitle) {
43+
if (Arrays.equals(expected, actual)) {
44+
printTestSuccess(testTitle);
45+
} else {
46+
printTestFailure(testTitle, toString(expected), toString(actual));
47+
}
48+
}
49+
50+
private static String toString(int[] values) {
51+
if (values == null) {
52+
return "null";
53+
}
54+
if (values.length < 1) {
55+
return "";
56+
}
57+
String str = String.valueOf(values[0]);
58+
for (int i=1; i < values.length; ++i) {
59+
str += "-" + String.valueOf(values[i]);
60+
}
61+
return str;
62+
}
63+
64+
private static String toString(Object[] values) {
65+
if (values.length < 1) {
66+
return "";
67+
}
68+
String str = String.valueOf(values[0]);
69+
for (int i=1; i < values.length; ++i) {
70+
str += "-" + String.valueOf(values[i]);
71+
}
72+
return str;
73+
}
74+
3375
public void booleanEquals(boolean expected, boolean actual, String testTitle) {
3476
if (expected == actual) {
3577
printTestSuccess(testTitle);

0 commit comments

Comments
 (0)