Exercise Variation of the WeinbergMyers Triangle Problem Philippe
Exercise Variation of the Weinberg-Myers Triangle Problem Philippe CHARMAN charman@fr. ibm. com http: //users. polytech. unice. fr/~charman/ Last update: 04 -16 -2013
Different types of triangles – – – – invalid point segment equilateral isosceles right rectangle scalene doesn’t exist reduced to a point reduced to a line segment all sides have the same length 2 sides have the same length rectangled triangle none of above types
Fonction triangle Triangle. Type triangle(double x, ` double y, double z) { // returns the triangle type according // to the values of the 3 sides x, y and z return Triangle. Type; }
First step: Writing the test suite • • Work in pair: 2 testers Tester A writes the tests for testing the triangle function Tester B reviews the test suite Example of the test suite: void all. Tests () { test( triangle(0, 0, 0), point); test( triangle(1, 1, 1), equilateral); test( triangle(3, 4, 5), rectangle); etc. } void test(Triangle. Type computed. Type, Triangle. Type expected. Type) { if (computed. Type == expected. Type) Nb. Success++; else Nb. Fails++; }
Second step: Writing the triangle function • Works in pair: 2 developers • Tester B becomes Developer A • Tester A becomes Developer B • Dev A writes the triangle functio • Dev B reviews the written code
Third step: executing the test suite • Display the number of failures • How many failures after the very first execution • How many test case have been written?
- Slides: 6