I am very new to hamcrest. What is the recommended way in hamcrest to
test two BigDecimals that they contain the same value? Normally it is
written 'value1.compareTo(value2) == 0'. equal() also compares scale
which is not what I want to do.
Thanks for the help.
--
Miroslav Šulc
However, if you need to compare BigDecimals differently than equals
you'll have to write a new Matcher. The Hamcrest wiki has a tutorial
that shows you how.
--Nat
In case of BigDecimal the behavior is this:
10.0 equals 10 = false (values are the same but scales are different)
10 equals 10 = true
10.0 compareTo 10 = true (just values compared)
which I think is correct.
The same is in case of Calendar and maybe there are even other classes
that implement this behavior. I think that some compareTo() in hamcrest
would come handy in these cases.
--
Miroslav Šulc
Nat Pryce napsal(a):
Strange. The equals(o) method should return the same boolean value as compareTo(o) == 0. If it doesn't, the class is breaking the contract of the Comparable interface. However, if you need to compare BigDecimals differently than equals you'll have to write a new Matcher. The Hamcrest wiki has a tutorial that shows you how. --Nat On 05/08/07, fordfrog <mirosl...@startnet.cz> wrote:
--Nat