From: olczyk@... (Thaddeus L Olczyk) Date: 2001-12-12T01:23:13+09:00 Subject: [ruby-talk:28238] Re: John Roth dolt ( Re: A challenge to proponents of Unit Testing. ) On 11 Dec 2001 07:35:20 -0800, rbinder@rbsc.com (Bob Binder) wrote: >Robert C. Martin wrote in message news:... >> On 10 Dec 2001 09:35:08 -0800, rbinder@rbsc.com (Bob Binder) wrote: >> >> >Robert C. Martin wrote in message news:... >> >> On Sat, 08 Dec 2001 00:35:43 -0600, Robert C. Martin > >> objectmentor . com> wrote: >> >> >> >> >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.length(); // 1 = equilateral, 2=isoceles, 3=scalene. >> ^^^^^^^^^--oops. >> >> > >> >> >What am I missing? >> > >> >In this example, wouldn't using an int set for the sides prevent >> >representing any triangle with two or more equal lengths -- I think a >> >bag would do the job. Assuming that your set would reject identical >> >values, any test suite which did not include tests like 3,3,4 or 3,3,3 >> >would miss that bug. >> >> The intent was to return a 1 for equilateral, 2 for isoceles, and 3 >> for scalene. Representing the triangle was not part of the job. >> > >Ok, this is clever way to do the classification. But it seems to me >this is only a fragment of the solution to the scope of the complete >triangle problem, and conclusions drawn about testing this fragment >versus testing a complete solution are skewed. > >Unless Set objects silently reject dups, the client code will have to >have a catch block, which means part of the classification scheme >resides in the client. The client will have to constrain lengths to 1 >or greater, and assure that the sides are constructable for the >isoceles and scalene cases. If not, your code will claim that 1,1,10 >and 1,2,10 are sides of triangle, which they are not. As the >implementation of these constraints is necessary for producing correct >answers, it should be included in scope of the test suite. > You must also add a reporting mechanism for the violation of these tests. And then you need to add more tests for the reporting mechanism.