From: "Brian Schröder" Date: 2005-10-18T02:02:26+09:00 Subject: Re: Nifty Proxy Object for Testing On 17/10/05, Robert Klemme wrote: > Brian Schr�der wrote: > > Hello Group, > > > > I had an idea for a testing method I wanted to share. I develop a c > > extension that efficently implements a priority queue. An inefficent > > pure ruby reference implementation can easily be written, so I have a > > reference implementation and my c implementation and want to assure > > that they behave the same. I achieve this by using a proxy object in > > my tests that does all actions on both implementations and asserts > > that return values and thrown exceptions are equal. > > > > That allows for double testing. I assure that my normal unit tests > > work and additionally for each action it is tested that the right > > thing is returned. Furthermore the teardown method now tests that the > > actions have resulted in the same state in both implementations. > > Maybe I didn't understand this correctly but if you have "normal" unit > tests already, why then do you need a result comparison? I mean, if > instances of both classes pass the unit test results should be the same or > at least compatible. > > Alternatively you could use the Ruby implementation to yield expected > values that are compared with the C version, but that has the same problem > as a comparison only test: you won't catch algorithmic flaws that you made > (if you developed both it's likely that both exhibit the same erroneous > behavior which you won't catch with the comparison approach). > > Kind regards > > robert > > > Hello robert, my idea was that it is a lot easier to write a functional (bugfree) ruby version. Of course it would be possible to write good unit test and use them on both implementations, but I hope to get better coverage using this approach as I'm checking the result of each and every action. But beware, I'm relatively inexperienced in writing good unit tests, so maybe the whole idea does not make much sense. best regards, Brian -- http://ruby.brian-schroeder.de/ Stringed instrument chords: http://chordlist.brian-schroeder.de/