CSC151 2007S, Class 27: Testing Your Procedures Admin: * Are there questions on Friday's class? * Are there questions on Assignment 11? * Now Due on Friday * Reading for tomorrow: Analyzing Algorithms. * Cool hint: When DrFu crashes, it often leaves your recent work around, even when you haven't saved * Look in your home directory for #mred...# * Use the one with the largest number for the ellipses * Your TA will be missing class on Thursday and Friday Overview: * Why test? * Strategies for testing. * Our Unit Testing Framework /Why Test/ * To "make sure that they're correct" * See that it at least works on some examples * There are always more tests to run * Tests give you some confidence that your procedure is correct (define square (lambda (x) (* x x))) Definition looks good a > (square 0) 0 > (square -1) 1 > (square 1) 1 > (square 1.5) 2.25 > (square (- 3 5)) 4 Lots of tests look good > (square 2147483648) 1 Whoops. Failed miserably. Problem: Multiplication of exact integers only works correctly if the result is less than 2^31. * So, a precondition of square should be: -sqrt(2^31) < x < sqrt(2^31) Last week, Microsoft Excel would sometimes say something like 32675 + 32000 = 100,000 If you divided the result by two, you'd get something close to 32000 /How to Test/ * Every testing strategy has the flaw that "You haven't tested every case" * Write an expresion, run the program, look at the result * Takes a lot of *human* time to look at the results * Make the computer check! * (if (equal? EXPRESSION EXPECTED_RESULT) "OK" "FAILED") * Takes a lot of *human* time to look at the results * Recent strategy: Unit testing * Combine tests together. At the end, report the number of successes and failures. N tests conducted M succeeded P failed List of tests that failed In this class, we'll use a few helpful procedures for unit testing (begin-tests!) - Start the testing framework (test! exp result) - Run one test to see if it succeeds (end-tests!) - Report on the tests (as above) (begin-tests!) (test! (square 0) 0) (test! (square 1) 1) (test! (square -1) 1) (test-error! (square null)) (end-tests!)\$a Today's goal: Write a procedure that, given three sides, classifies a triangle (define classify-triangle (lambda (side1 side2 side3) ...)) * If it's equilateral, says "equilateral" * If it's isosceles, says "isosceles" * If it's any other kind of triangle, says "scalene" * If it's not a triangle, should crash and burn (that is, report an error, not end DrFu) [01] tri.0000.ss | [04] tri.0001.ss | [X ] tri.0010.ss | [03] tri.0011.ss [01] tri.0100.ss | [X ] tri.0101.ss | [X ] tri.0110.ss | [ ] tri.0111.ss [01] tri.0200.ss | [X ] tri.0201.ss | [ ] tri.0210.ss | [ ] tri.0211.ss [01] tri.1000.ss | [ ] tri.1001.ss | [ ] tri.1010.ss | [02] tri.1011.ss [01] tri.1100.ss | [ ] tri.1101.ss | [ ] tri.1110.ss | [ ] tri.1111.ss [01] tri.1200.ss | [01] tri.1201.ss | [ ] tri.1210.ss | [ ] tri.1211.ss [01] tri.2000.ss | [ ] tri.2001.ss | [ ] tri.2010.ss | [05] tri.2011.ss [01] tri.2100.ss | [ ] tri.2101.ss | [ ] tri.2110.ss | [ ] tri.2111.ss [04] tri.2200.ss | [X ] tri.2201.ss | [X ] tri.2210.ss | [ ] tri.2211.ss Which ones don't work and why? Notation: * Blank means "untested" * [X ] means "failed some test, but I'm not telling you which one" * [01] means "classified 2 2 3 as scalene, rather than isosceles" * [02] means "failed to indicate that 1 1 5 is not a triangle" * [03] means "failed to indicate that 3 7 3 is not a triangle" * [04] means "failed to classify 1 1 1 as an equilateral triangle" * [05] means "seems to think 2 2 5 is a triangle"