I am attempting to write some test cases for some classes that involve testing the equality of two dimensional arrays of data. Here is my first stab at it:
double[][] expected = {
{0, 104, 0},
{145.5, 0, 0},
{83, 0, 0}
};
double[][] actual = someObject.getArray();
Now, I see that JUnit does not have an 'arrayEquals' for double arrays, probably due to the floating point issue (you really want to use a delta vs equality). I notice that Junit-Addons has exactly the method I need to determine if they're equal:
static void assertEquals(java.lang.String message, double[] expected, double[] actual, double delta)
Now, that's all well and fine. What I want to be able to do is give a meaningful error message, not just saying that the two are unequal but where they are unequal. Is there an easy way of doing this, short of comparing dimensions, then iterating over each corresponding element and testing for equality? It seems silly to have to do the same thing that's being done in the assertion, just to get a meaningful error message.