From: brabuhr@... Date: 2009-11-24T02:33:17+09:00 Subject: Re: Distinct Sets (#225) On Mon, Nov 23, 2009 at 11:10 AM, Rob Biedenharn wrote: > On Nov 22, 2009, at 1:51 AM, lith wrote: >>> http://gist.github.com/240457 >> >> Both of your tests use rather small input sets. It would be >> interesting to know how the solutions deal with input that contains >> many (10, 50, 100, ....) sets and/or many different signs (not just >> letters). > > I accept your challenge!  The gist has been updated with sets that use > numbers and symbols as well as strings.  There are also some tests of large > sets (which worked fine, but getting the test setup by hand was nasty). Thanks. > ruby1.8 -v -rubygems distinct_sets_test.rb ruby 1.8.7 (2009-06-12 patchlevel 174) [i486-linux] /var/lib/gems/1.8/gems/shoulda-2.10.2/lib/shoulda/context.rb:4: warning: method redefined; discarding old contexts Loaded suite distinct_sets_test Started ..................EEE..... Finished in 3.424045 seconds. 1) Error: test: non-uniform contents should handle matching on symbols. (DistinctSetsTest): ArgumentError: comparison of String with :bill failed ./distinct_sets.rb:7:in `sort' 2) Error: test: non-uniform contents should handle mix of strings and symbols (matching on string). (DistinctSetsTest): ArgumentError: comparison of String with :bill failed ./distinct_sets.rb:7:in `sort' 3) Error: test: non-uniform contents should handle mix of strings, numbers, and symbols. (DistinctSetsTest): ArgumentError: comparison of Fixnum with :emergency failed ./distinct_sets.rb:7:in `sort' 26 tests, 175 assertions, 0 failures, 3 errors > The only change that I has to make was in how I sorted the final array to > account for symbols or mixed contents: Numerics compare "naturally" with <=> > and non-numeric or mixed are compared using the #to_s representation. Simply not sorting: 26 tests, 202 assertions, 17 failures, 0 errors Simply sort_by{to_s}: 26 tests, 202 assertions, 3 failures, 0 errors More complex sort{}: 26 tests, 202 assertions, 0 failures, 0 errors