1Using Check Formsπ i
This module provides test forms for use in Racket programs, as well
as parameters to configure the behavior of test reports.
Each check form may only occur at the top-level; results are collected
and reported by the test function. Note that the check forms only
register checks to be performed. The checks are actually run by the
test function. Furthermore, syntax errors in check forms
are intentionally delayed to run time so that students can write tests
without necessarily writing complete function headers.
Checks whether the value of the
expr expression is
equal? to the value produced by the
expected-expr.
It is an error for expr or expected-expr to produce a function
value or an inexact number.
Checks whether the value of the
expr expression is
equal? to the value produced by the
expected-expr.
The form supplies the same random-number generator to both parts. If both
parts request random numbers from the same interval in the same
order, they receive the same random numbers.
Examples:
If the two parts call random for different intervals, they are
likely to fail:
Examples:
Actual value │ 130 │ differs from │ 65 │, the expected value.
It is an error for expr or expected-expr to produce a function
value or an inexact number.
Checks whether the value of the expr expression satisfies
the property? predicate (which must evaluate to a function of one
argument).
Examples:
Actual value │ 1 │ does not satisfy even?.
Changed in version 1.1 of package htdp-lib: allow the above examples to run in BSL and BSL+
Checks whether the value of the
test expression is structurally
equal to the value produced by the
expected expression; every
number in the first expression must be within
delta of the
corresponding number in the second expression.
It is an error for expr or expected to produce a function
value.
Checks that evaluating expr signals an error, where
the error message matches the string (if any).
Checks whether the value of the
expr expression is
equal?
to any of the values produced by the
expected-exprs.
It is an error for expr or any of the expected-exprs
to produce a function value or an inexact number.
Checks whether value of expr is between the values of
min-expr and max-expr inclusive.
Runs all of the tests specified by check forms in the current module
and reports the results. When using the gui module, the results are
provided in a separate window, otherwise the results are printed to
the current output port.
A parameter that stores a boolean, defaults to #f, that can be used to
suppress the printed summary from test.
A parameter that stores a boolean, defaults to #t, that can be used to
suppress evaluation of test expressions.
2Running Tests and Inspecting Test Resultsπ i
This module defines language-agnostic procedures for running test code
to execute checks, and recording and inspecting their results.
A test is a piece of code run for testing, a check
is a single assertion within that code: Typically the tests are first
registered, then they are run, and then their results are inspected.
Both tests and the results of failed checks are recorded in a data
structure called a test object. There is always a current
test object associated with the current namespace.
successful-tests
failed-checks
signature-violations))
failed-checks:(listoffailed-check?)
signature-violations:(listofsignature-violation?)
The four components of a test-object are all in reverse order:
The first one is the list of tests (each represented by a thunk), the
others are succeeded tests, failed checks and signature violations, respectively.
The thunks are expected to always run to completion. They shouöd
return #t upon success, and #f upon failure.
( empty-test-object)→test-object?
Creates an empty test object.
( current-test-object)→test-object?
Returns the current test object.
( initialize-test-object!)→any
Initializes the test object. Note that this is not necessary before
using current-test-object and the various other functions
operating on it: These will automatically initialize as necessary.
Use this function to reset the current test object.
Register a test, represented by a thunk. The thunk, when called, is
expected to call add-failed-check! and
add-signature-violation! as appropriate.
( add-failed-check!failed-check)→any
failed-check:failed-check?
Record a test failure.
( add-signature-violation!violation)→any
violation:signature-violation?
Record a signature violation.
( run-tests!)→test-object?
Run the tests, calling the thunks registered via add-test! in
the order they were registered.
(struct failed-check(reasonsrcloc?))
reason:fail-reason?
This is a description of a failed check.
The source location, if present, is from an expression that may have caused the failure,
possibly an exception.
Common supertype of all objects describing a reason for a failed check.
The
srcloc is the source location of the check.
(struct unexpected-errorfail-reason(srclocexpectedexn))
expected:any/c
An error happened instead of regular termination.
(struct unexpected-error/markupunexpected-error ( srcloc expected
exn
error-markup))
expected:any/c
error-markup:markup?
An error happened instead of regular termination. This also contains markup
describing the error.
(struct unexpected-error/check-*unexpected-error/markup ( srcloc expected
exn
error-markup
form-name))
expected:any/c
error-markup:markup?
An error happened instead of regular termination. This also contains markup
describing the error and the name of the check form.
(struct unexpected-error/rangeunexpected-error/markup ( srcloc expected
exn
error-markup
min
max))
expected:any/c
error-markup:markup?
An error happened instead of regular termination in a
check-range form.
This also contains markup describing the error.
(struct unexpected-error/memberunexpected-error/markup ( srcloc expected
exn
error-markup
set))
expected:any/c
error-markup:markup?
set:any/c
An error happened instead of regular termination in a
check-member-of form.
This also contains markup describing the error.
(struct unequalfail-reason(srclocactualexpected))
actual:any/c
expected:any/c
A value was supposed to be equal to another, but wasn’t.
Generated by
check-expect .
(struct not-withinfail-reason(srclocactualexpectedrange))
actual:any/c
expected:any/c
A value was supposed to be equal to another within a certain range, but wasn’t.
Generated by
check-within .
(struct incorrect-errorfail-reason(srclocexpectedexn))
expected:any/c
An exception was expected, but a different one occurred.
Generated by
check-error .
(struct incorrect-error/markupincorrect-error ( srcloc expected
exn
error-markup))
expected:any/c
error-markup:markup?
An exception was expected, but a different one occurred.
Also includes markup describing the error.
Generated by
check-error .
(struct expected-errorfail-reason(srclocmessagevalue))
value:any/c
An error was expected, but a value came out instead.
Generated by
check-error .
(struct not-memfail-reason(srclocactualset))
actual:any/c
set:(listofany/c)
The value produced was not part an the expected set.
Generated by
check-member-of .
(struct not-rangefail-reason(srclocactualminmax))
The value produced was not part an the expected range.
Generated by
check-range .
(struct satisfied-failedfail-reason(srclocactualname))
actual:any/c
The value produced did not satisfy a predicate.
The
name field is the name of the predicate.
Generated by
check-satisfied .
(struct unsatisfied-errorfail-reason(srclocnameexn))
A value was supposed to satsify a predicate, but an error happened
instead. The
name field is the name of the predicate.
Generated by
check-satisfied .
(struct unsatisfied-error/markupunsatisfied-error ( srcloc name
exn
error-markup))
error-markup:markup?
A value was supposed to satsify a predicate, but an error happened
instead. The
name field is the name of the predicate.
Also includes markup describing the error.
Generated by
check-satisfied .
(struct violated-signaturefail-reason ( srcloc obj
signature
blame-srcloc))
obj:any/c
signature:signature?
A signature was violated, and this was communicated via an exception.
Note that signature violations should really be (and usually are)
communicated via add-signature-violation!.
The value that violated the signature.
(struct signature-violation ( obj signature
message
srcloc
blame-srcloc))
obj:any/c
signature:signature?
message:
(or/cstring? signature-got?)
Signature
signature was violated by object
obj.
The
srcloc field is the location of the signature.
The optional
blame-srcloc points at the source code to blame
for the violation.
(struct property-failfail-reason(srclocresult))
result:check-result?
A counterexample for a property was found, described in the result field.
(struct property-errorfail-reason(srclocexn))
A property check produced an unexpected exception.