From: Stefan Schmiedl Date: 2001-12-09T02:57:56+09:00 Subject: [ruby-talk:27950] Re: A challenge to proponents of Unit Testing. John Roth (2001-12-08 23:57): > > "Robert C. Martin" wrote in message > news:6nj21uo76gu2nfq92di0736dr4uags667k@4ax.com... > > On 7 Dec 2001 02:04:08 -0800, stephen.hill@motorola.com (Steve Hill) > > wrote: > > > > >What tests would you write for a function that takes 3 numbers (the > > >side lengths of a triangle) , and returns whether the triangle is > > >equilateral, scalene or isoceles. > > > > Set sides; // data structure allows no duplicates. > > sides.add(a); > > sides.add(b); > > sides.add(c); > > return sides; // 1 = equilateral, 2=isoceles, 3=scalene. > > > This implementation really only requires three unit tests Does it? This implementation, like the Ruby one I posted, moves the solution to language features. If you want to make sure down to this level, you need just two tests, one for two different numbers, one for two equal numbers. If you do this in Ruby, how low-level will you go for testing? def classify(*sides) ["equilateral", "isoceles", "scalene"][sides.uniq.size - 1] end I think, you will trust Ruby, to - collect the arguments into an array - count the items in an array - subtract 1 from a number - extract an element from an array given an index The only "magic" here is uniq, but even this is built-in, hence I tend to trust it unless proven wrong. So: what does the programmer need to test with this implementation? The user will still provide three triangles for checking out return values. s. -- Stefan Schmiedl EDV-Beratung, Programmierung, Schulung Loreleystr. 5, 94315 Straubing, Germany Tel. (0 94 21) 74 01 06 Public Key: http://xss.de/stefan.public shhhh ... I can't hear my code!