equals method for assertEquals

5 views
Skip to first unread message

femto

unread,
Jul 16, 2007, 10:41:52 PM7/16/07
to xruby-devel
hello all, while I'm writing testcase for testing RubyBignum
equality,
assertEquals(ObjectFactory.createBignum("3"), result); (where result
is also a bignum of 3)
produce error, so I add the equals method in RubyBignum for my test:

public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
//if (!super.equals(o)) return false;

RubyBignum that = (RubyBignum) o;

if (value_ != null ? !value_.equals(that.value_) :
that.value_ != null) return false;

return true;
}

I also notice that in ruby's level, there is a test delegating to
ruby's equal:
(in RubyValue)
public boolean equals(Object o) {
if (this == o) {
return true;
} else if (o instanceof RubyValue) {
RubyValue v = RubyAPI.callPublicOneArgMethod(this, (RubyValue)o,
null, CommonRubyID.equalID);
return RubyAPI.testTrueFalse(v);
} else {
return false;
}
}
so then there is some problems, what is an equal? in traditional java
level or in delegating ruby level? tell me what your thoughts.
(and just a note: why doesn't code in RubyValue work, it seems ok now?)

Xue Yong Zhi

unread,
Jul 16, 2007, 11:14:14 PM7/16/07
to xruby...@googlegroups.com

>so then there is some problems, what is an equal? in traditional java
>level or in delegating ruby level? tell me what your thoughts.
>(and just a note: why doesn't code in RubyValue work, it seems ok now?)
>

The problem is Bignum#== is not implemented in xruby 0.2.1 :), so it goes to
Kernel#==, which returns true only if the two are the same instance.

_________________________________________________________________
Local listings, incredible imagery, and driving directions - all in one
place! http://maps.live.com/?wip=69&FORM=MGAC01

femto

unread,
Jul 17, 2007, 1:54:40 AM7/17/07
to xruby-devel
yes, so actually delegating to ruby level's equals still
returns false because ruby's level's bignum's == is Kernel's ==?
then that's no wonder.
but there still needs some clarification between java level equals
and ruby level equals, otherwise it may cause some confusions,
what's everybody's thoughts?

> place! http://maps.live.com/?wip=69&FORM=MGAC01,

Reply all
Reply to author
Forward
0 new messages