Re: Testing, Scale and 0 vs 0.00

63 views
Skip to first unread message

Noel Grandin

unread,
Jul 6, 2012, 3:08:08 AM7/6/12
to h2-da...@googlegroups.com, Mark
Yeah, sorry, we're not planning on being compatible to that degree.

On 2012-07-05 22:23, Mark wrote:
> If this is something that is out of scope for H2, I undersand. I just
> wanted to make sure I wasn't missing something obvious.
>
>

Mark

unread,
Jul 6, 2012, 10:16:26 AM7/6/12
to h2-da...@googlegroups.com, Mark
No problem. Thanks for the reply. I think H2's behavior is a much more sane approach anyway. Now if I could convince Oracle to fix their implementation. :)

Mark

Christoph Läubrich

unread,
Jul 6, 2012, 12:10:47 PM7/6/12
to h2-da...@googlegroups.com
Hi Mark,

just wondering, why do you compare against a specific scale and not
using the compareTo Method?
http://docs.oracle.com/javase/1.5.0/docs/api/java/math/BigDecimal.html#compareTo%28java.math.BigDecimal%29
This would be working with either 0 and 0.00 ...

Mark

unread,
Jul 6, 2012, 3:04:27 PM7/6/12
to h2-da...@googlegroups.com
Good question. We are trying to use JUnit to do things like:

assertThat(payment.getAmount(), is(new BigInteger("0.00")))

I can do something like:
assertTrue(payment.getAmount().compareTo(new BigInteger("0.00"));

But the team wanted the feed back that said "Expected 0.00, but was 5.00" instead of "Expected True, but was False."

I'll probably use the compareTo or setScale method. I just wanted to make sure there wasn't an easy way to get H2 and Oracle to return the same thing.

Thanks. I appreciate the feedback and suggestion.

Mark

Christoph Läubrich

unread,
Jul 7, 2012, 2:53:05 AM7/7/12
to h2-da...@googlegroups.com
Maybe as a workaround you can use:

assertTrue("Expected 0.00, but was "+payment.getAmount(), payment.getAmount().compareTo(new BigInteger("0.00"));

(Alternativly you could define a convinience Method to compare BigDecimals)

You should always test the real contract, if the scale does not matter (so $1 == $1.00 == $1.0000000 ....) you should not use the equal Method to compare BigDecimals!
--
You received this message because you are subscribed to the Google Groups "H2 Database" group.
To view this discussion on the web visit https://groups.google.com/d/msg/h2-database/-/_gb5roAuX7sJ.
To post to this group, send email to h2-da...@googlegroups.com.
To unsubscribe from this group, send email to h2-database...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/h2-database?hl=en.

Reply all
Reply to author
Forward
0 new messages