From: John Roth Date: 2001-12-08T03:35:11+09:00 Subject: [ruby-talk:27832] Re: John Roth dolt ( Re: A challenge to proponents of Unit Testing. ) "David B Lightstone" wrote in message news:je5Q7.350$lw2.92827794@newssvr16.news.prodigy.com... > > "Keith Ray" wrote in message > news:k1e2i3t4h5r6a7y-4F0A2E.07090507122001@netnews.attbi.com... > > In article , > > stephen.hill@motorola.com (Steve Hill) wrote: > > > > > You might actually be surprised at how many tests are needed. In "The > > > art of software testing" (Myers, 1979) the 1st chapter starts with a > > > quiz.... > > > > > > 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. > > > > > > I think the answer is over 20.... certainly close on 20 > > > > > > Steve > > > > Kent Beck's response to that example: > > > > http://groups.yahoo.com/group/extremeprogramming/message/37242 > > > > "The biggest problem is that it doesn't balance the cost and benefits > > of tests. He has a triangle example which he writes (I think) 29 > > tests for. The test-first version can be done confidently with 5 > > tests." > > It is rather hard to access either your response or Mr Beck's intent. > What to you believe? > > (1) Mr Beck may have read the 29 test cases and concluded that > the 5 tests he favors are adequate. (the original 29 hasd redundancy) > > (2) Mr Beck may have read the 29 test cases and concludes that > pruning a number of them was appropriate (impossible situations > by virtue of a priori knowledge about other aspects of the system). > (Hence he is doing integration testing, rather than unit testing) > > (3) Mr Beck may have determined that the customer can afford > to take the risk because the expected loss associated with > the pruned test cases is acceptable. > > Any other possible alternative explinations for Mr Beck's intet? > > Which is applicable to your situation? 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.) Since XP writes the test cases before writing the code, it's not possible to write an open box test, based on inspecting the code that doesn't exist yet. Assuming I write fairly simple code (I'm not going to attempt to do "simplest" because that's kind of subjective) I might implement this in Python as: def kindOfTriangle(a, b, c): if (a == b) and (b == c) and (a == c): print "equilateral" elif (a == b) or (b == c) or (a == c): print "iscosceles" else: print "scalene" John Roth