From: Christoph Date: 2002-08-26T22:59:35+09:00 Subject: Re: CompareByValue "Dossy" wrote .... > I don't think this is the /best/ solution, but it's one > that makes all ten tests pass: > > module CompareByValue > def ==(other) > # return true if self.id == other.id > return false unless self.type == other.type > return false unless self.instance_variables == other.instance_variables > self.instance_variables.each { |name| > next if self.id == self.instance_eval(name).id > next if other.id == other.instance_eval(name).id > next if self.id == other.instance_eval(name).id > next if other.id == self.instance_eval(name).id > return false unless self.instance_eval(name) == > other.instance_eval(name) > } > true > end > end > > The commented-out line is not required to make the tests pass (that's > why it's commented out) but it's an optimization that might make the > comparison go faster. Just a stupid style comment - your are using ``self'' too excessively (for my taste;-) . Also you might want to use the #equal? method instead of the comparing the id's directly? > > > http://www.rubygarden.org/ruby?CompareByValueTests (which isn't > > even a thorough test suite, necessarily). > > What kind or class of tests might be missing? The recursive test case looks insufficient - it seems to me that one needs to test that the generated ``local variables name labeled'' id-graphs are ``the same''. /Christoph