Start with the simplest possible examples, then work up to more and more complicated examples.
One way to write this is in a Scheme comment, e.g.
; Cube function: find the third power of a number ; cube: number => number ; (cube 0) => 0 ; (cube -3/5) => -27/125 ; (cube (cube 3)) => 19683
Another is to write it directly in the Definitions window, specifying the correct answers with "should be..." , but then insert the function definition in front of it, e.g.
; Cube function: find the third power of a number ; cube: number => number function definition will go here (cube 0) "should be 0" (cube -3/5) "should be -27/125" (cube (cube 3)) "should be 19683"
Both of these approaches are sort of a pain in practice: you have to go through the actual answers, one by one, and compare them with what you said the right answers should be. A more convenient approach uses a built-in function named check-expect: you give it the expression you want to test, and the right answer, and it'll run all your tests and give you a report on how many of them worked, and which didn't. For example,
; Cube function: find the third power of a number ; cube: number => number function definition will go here (check-expect (cube 0) 0) (check-expect (cube -3/5) -27/125)If you're using a version of DrScheme that starts with a "3", you'll need to add the "testing.ss" teachpack (go to the Language menu, choose "Add Teachpack", and find it on the left hand side), and you'll need to add the single line
(generate-report)at the very end of your Definitions pane, after all of thecheck-expect
s for all of the functions. If you're using a DrScheme version starting with a "4", you don't need to do either of these things.
Last modified: Mon Aug 25 11:54:40 EDT 2008 Stephen Bloch / sbloch@adelphi.edu