|
1 | 1 | package com.cunningdj.grokJava;
|
| 2 | +import java.util.Arrays; |
2 | 3 | import java.util.HashMap;
|
3 | 4 |
|
4 | 5 | public class Tester {
|
@@ -30,6 +31,47 @@ public Tester() {
|
30 | 31 |
|
31 | 32 |
|
32 | 33 | // 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 | + |
33 | 75 | public void booleanEquals(boolean expected, boolean actual, String testTitle) {
|
34 | 76 | if (expected == actual) {
|
35 | 77 | printTestSuccess(testTitle);
|
|
0 commit comments