> > 1) If you are passed two ints, should the result always be an int, or
> > could it overflow into a long?
[quoted text clipped - 7 lines]
> 2) The result should be int
> 3) The result should be double
Okay. Thinking about unsigned types as well, I think there are *lots*
of combinations you should consider.
I would start by writing a *long* set of unit tests - as many odd (and
normal!) combinations as you can think of. Each test should be
incredibly simple - just assert that the result of the addition is what
you want it to be.
Once you've got that set of unit tests, it'll be a lot easier to start
implementing the production code - you'll have thought of a lot of the
issues involved while writing the tests, and recorded the answers at
the same time. You'll probably want to start off the implementation by
working out whether you're dealing with integer arithmetic or floating
point, and possibly have one private method for each, just to keep
things clean.
Jon
ggeshev - 24 Nov 2006 07:48 GMT
> Okay. Thinking about unsigned types as well, I think there are *lots*
> of combinations you should consider.
[quoted text clipped - 13 lines]
>
> Jon
Thank you Jon!
Thank you for your proposals!
I was wondering if I'm missing some very easy and tricky way of achieving my
aim by casting the input Object values /val1 and val2/ to certain Interfaces
for example, or using reflection probably.
Jon Skeet [C# MVP] - 24 Nov 2006 19:17 GMT
<snip>
> I was wondering if I'm missing some very easy and tricky way of achieving my
> aim by casting the input Object values /val1 and val2/ to certain Interfaces
> for example, or using reflection probably.
No, I don't believe so.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too