[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Orekit Users] Overloading of equals method



Le 12/03/2012 16:01, Carlos M. Casas Cuadrado a écrit :
> Hello Luc,

Hi Carlos,

> thanks for your quick answer. I agree that objects which contain
> double fields are difficult to compare. Nevertheless, you could still
> compare them without using a threshold (bit to bit). This won't be
> useful for objects whose fields are the result of a mathematical
> operations, but still it will be useful for pure data handling
> applications.
> 
> In my particular case, I have a regression test which checks that a
> certain impulsive manoeuvre has been successfully read from a XML file
> and loaded into an ImpulsiveManeuver object. Instead of checking the
> result of each getter method in ImpulsiveManeuver, it would be more
> convenient to create a reference ImpulsiveManeuver object, and
> "equals" it against the object whose data is read from the file. In
> this case, double comparisons should be exact since no operation has
> been performed outside the class (and hopefully, the arguments of the
> constructor have gone through the same operations within the class).
> Code would look like:
> 
> ImpulsiveManeuver refMan = new ImpulsiveManeuver(...);
> ImpulsiveManeuver xmlMan = readFromXML(...);
> assert(refMan.equals(xmlMan));
> 
> I understand that you don't want to override the equals method because
> of real field comparison, but leaving the default behaviour could also
> be misleading (it took me some time to find out why the test was
> failed). I couldn't find anything about this issue in the Orekit
> documentation. If it's not already there, could you please add a
> paragraph about it?

Yes, we could explain this in the documentation.

Could you file a request for improvement in our issue tracker at the
orekit forge at <https://www.orekit.org/forge/projects/orekit/issues>?
You would have to register to the forge for this, but its quick. This
would help not forgetting this.

Thanks
Luc

> 
> Regards,
> Carlos.
> 
> 
> On 12 March 2012 13:48, Luc Maisonobe <Luc.Maisonobe@c-s.fr> wrote:
>> Le 12/03/2012 14:27, carlos.marce@gmail.com a écrit :
>>> Hi,
>>
>> Hello Carlos,
>>
>>> I just realised that some classes in Orekit don't override the equals method.
>>> This makes difficult the comparisson of two different objects (i.e. for
>>> regression testing). Do you plan on adding this in the future?
>>
>> It depends on the class. Typically, classes that have some primitive
>> double fields are difficult to compare. Any code change, regardless of
>> the fact it is minor or not (just think about replacing a + (b+c) by
>> (a+b) + c) may slightly change the least significant bits. Using exact
>> comparison would therefore fail despite the change should be considered
>> acceptable. On the other hand, using some threshold for equality is
>> difficult has a difference that would be considered as acceptable in one
>> context may be too large in another one (typically, two orbits differing
>> in position by 1m would be considered the same in station keeping for a
>> regular mission, but different for precise orbit determination
>> applications like altimetry missions). The equals method does not allow
>> user providing a threshold parameter.
>>
>> So we implemented equals scarcely, in some limited cases. We implemented
>> it for AbsoluteDate, we did not implement it for Orbit.
>>
>> For such "difficult" classes, I would recommend using something more
>> robust for regression testing. Equals is clearly not sufficient.
>>
>> For which class would you need an equals method ?
>>
>> best regards,
>> Luc
>>
>>> Regards.
>>>
>>
>