From: Stefan Schmiedl Date: 2001-12-08T05:17:32+09:00 Subject: [ruby-talk:27850] Re: John Roth dolt ( Re: A challenge to proponents of Unit Testing. ) lrm@provida.no (2001-12-08 03:35): > In comp.object John Roth wrote: > > > Let's think about this for a moment. 5 test cases appears to > > be adequate for a black box test. You need one for equilateral, > > three for isosceles and one for scalene. If you're deriving > > more test cases, you're doing an open box test, based on the > > actual implementation (or on some set of assumptions about > > frequent defects, or some such.) > > How about bad data? Won't you need tests to ensure that the code can > handle bad (zero or negative) values for any combination of the sides? > Isn't that 7 more tests (illegal data for: {a, b, c, a & b, a & c, b & > c, a & b & c })? The user story (msg 27796) said: "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." So I *know* that the input are valid. Input validation would be done in another method, anyway. Right now we are focusing *only* on deciding what kind of triangle we have. If you check that the numbers make a valid triangle, the Gods of Refactoring will find ye, and lo, show no mercy on thy code. BTW: a solution without if could look like def classifyTriangle(*sides) ["equilateral", "isoceles", "scalene"][sides.uniq.size - 1] end Now, this raises another question. Given that you wrote the method this way ... what could possibly break in this method? I'm not talking about callers here: If a caller sends two or four sides instead of three, it's his fault. 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!