Why doesn't junit4 have Assert.assertArrayEquals () for double [] s?

In Junit4, there are Assert.assertArrayEquals() methods for all non-double primitives, for example

 Assert.assertArrayEquals(int[] expected, int[] actual) 

and

 Assert.assertArrayEquals(char[] expected, char[] actual) 

but not

 Assert.assertArrayEquals(double[] expected, double[] actual, double eps) 

or

 Assert.assertArrayEquals(double[] expected, double[] actual, double[] eps) 

(the latter takes into account variable doubling ranges). Is there a fundamental reason why I shouldn't write such a function?

+6
java assert junit4
source share
4 answers

It has such a method (in 4.7), although it is not registered in the online javadoc here . This was, of course, oversight in javadoc / version, but it is now.

+6
source share

The method seems to have been added in JUnit 4.6, but for some reason is missing in versions 4.5 and previous versions. I would not expect any problems upgrading to a newer version of JUnit.

+7
source share

According to the JUnit error database, they " work on it ." Based on other answers, it seems that the error database is not fully synchronized with reality.

+1
source share

just use:

  AssertTrue(**message**, Arrays.equals(**expected**,**result**) 

You may need this to round your result values ​​to test against the expected:

  public double roundTo2Decimals(double val) { DecimalFormat df2 = new DecimalFormat("###.####"); return Double.valueOf(df2.format(val)); } 

See javdoc for details

0
source share

All Articles