From dc725487cb7a366d27522dd7a45a88ff5a61f1b5 Mon Sep 17 00:00:00 2001 From: Matthias Felleisen Date: Wed, 10 Jan 2007 20:14:24 +0000 Subject: [PATCH] testing + docs svn: r5305 --- collects/teachpack/htdp/Docs/mkdocs | 1 + collects/teachpack/htdp/Docs/testing.thtml | 80 ++++++++++++++++++++++ collects/teachpack/htdp/testing.ss | 4 ++ 3 files changed, 85 insertions(+) create mode 100644 collects/teachpack/htdp/Docs/testing.thtml create mode 100644 collects/teachpack/htdp/testing.ss diff --git a/collects/teachpack/htdp/Docs/mkdocs b/collects/teachpack/htdp/Docs/mkdocs index c331b2f544..2d0f9f4ead 100755 --- a/collects/teachpack/htdp/Docs/mkdocs +++ b/collects/teachpack/htdp/Docs/mkdocs @@ -16,6 +16,7 @@ fi (define libraries* '(#"Images" #"Animated Images, Simulating Worlds" + #"Testing" #"Convert" #"Guess" #"Mastermind" diff --git a/collects/teachpack/htdp/Docs/testing.thtml b/collects/teachpack/htdp/Docs/testing.thtml new file mode 100644 index 0000000000..8c2c8c284e --- /dev/null +++ b/collects/teachpack/htdp/Docs/testing.thtml @@ -0,0 +1,80 @@ +{ (define LIBNAME "Testing") + (include "head.tinc") } + +
+

+ This teachpack provides four constructs for testing programs: +

+

+ The first three forms create tests: +

+
  • + ({(idx check-expect)} test-expression expected-value) + where test-expression and + expected-value are both expressions. +
    + The form evaluates test-expression and then + verifies that its value is the same as + expected-value. +
  • +
  • + ({(idx check-within)} test expected delta) + where test-expression, expected, and + delta are expressions. +
    + The form evaluates test-expression and verifies that + it produces a real number such that its value is equal to + expected plus or minus delta. +
  • +
  • + ({(idx check-error)} test message) + where test and expected-message are expressions +
    + The form evaluates test and verifies that it signals + an error with expected-message as the error report. +
  • +
    + You should place them below the relevant function + definitions in the Definitions Window. Eventually you should place + all tests, such as these, at the bottom of the window. +

    + +

    + Finally, generate-report is a function that displays + statistics of running tests: +

    +
  • + {(idx generate-report)} : -> true +
    + (generate-report) displays the results of all tests + created with check-expect, check-within, + and check-error. +
  • +
    + Place it at the end of the program or run the expression from the + Interactions window after clicking RUN. +

    + +Example: Place the following seven lines into the Definitions Window +and click RUN: +
    +
    +(check-expect (+ 1 1) 2)
    +(check-expect (+ 1 1) 3)
    +
    +(check-within (+ 1 1) 2.1 .001)
    +(check-within (+ 1 1) 2.1 .1)
    +
    +(check-error (+ 1 1) "3")
    +(check-error (/ 1 0) "/: division by zero")
    +
    +(generate-report)
    +
    +
    + Before you do so, try to figure out which of these tests succeed and which + fail. After clicking run, you see a separate frame that records how many + succeeded and failed and detail information about the failures, including + links for highlighting the source. +
    + +{(include "foot.tinc")} diff --git a/collects/teachpack/htdp/testing.ss b/collects/teachpack/htdp/testing.ss new file mode 100644 index 0000000000..aee6a8a0c2 --- /dev/null +++ b/collects/teachpack/htdp/testing.ss @@ -0,0 +1,4 @@ +#cs +(module testing mzscheme + (provide (all-from (lib "testing.ss" "htdp"))) + (require (lib "testing.ss" "htdp")))