简体   繁体   中英

assertEquals(expected, actual, delta) to compare floating-point numbers in a matrix

I have written a program to find the min and max in from a given matrix with 5 elements. But now I want to find the min and max in a matrix with floating-point numbers . Supposedly using assertEquals that would be possible but I don't truly get it how to use it. I got a hint like this: assertEquals (expected, actual, delta) But I do not go far from that, I don't understand how could I use it. If you could help me I very much appreciate it

Last argument is delta. You can pass expected & actual values in the first two arguments.

True:

Assert.assertEquals(0.0010f, 0.0013f, 0.0003f);

Above is true because 0.0003 <= (0.0013 - 0.0010 = 0.0003)

False:

Assert.assertEquals(0.0010f, 0.0013f, 0.0004f);

Aboove one is false because 0.0004 > (0.0013 - 0.0010 = 0.0003)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM