Skip to content

check-random-within - #95

Merged
mfelleisen merged 2 commits into
racket:masterfrom
samth:random-within
Sep 30, 2026
Merged

mfelleisen merged 2 commits into
racket:masterfrom
samth:random-within

Conversation

@samth

@samth samth commented Feb 15, 2020

Copy link
Copy Markdown
Member

No description provided.

@mfelleisen

Copy link
Copy Markdown
Contributor

@samth I never noticed this PR. There are no tests and no docs. If you add those, we can marge it in.

samth added a commit to samth/htdp that referenced this pull request Jun 29, 2026
check-random-within combines check-random and check-within: the test
and expected expressions are evaluated with the same freshly-seeded
pseudo-random generator (like check-random), and the two results are
then compared up to a tolerance (like check-within). This is the form
to use when a random computation produces inexact numbers, which
check-random refuses to compare.

- test-engine/racket-tests: add the check-random-within syntax and
  do-check-random-within, and provide it.
- lang/htdp-{beginner,beginner-abbr,intermediate,intermediate-lambda,
  advanced}: export check-random-within to the student languages.
- typed/test-engine/type-env-ext: give do-check-random-within a type.
- htdp-doc .../prim-ops: document the new form.
- htdp-test .../test-engine/racket-tests: test pass, failure, and the
  non-number-tolerance error.

Supersedes the stale draft in racket#95, which predated the rewrite of
check-random into do-check-random.  (Grammar BNF listing in
std-grammar.rkt + per-language .scrbl is a remaining follow-up.)
@mfelleisen

Copy link
Copy Markdown
Contributor

@samth Should we merge this?

@samth
samth marked this pull request as ready for review September 29, 2026 13:59
@samth

samth commented Sep 30, 2026

Copy link
Copy Markdown
Member Author

If you think this is good, I think it's ready to be merged.

@mfelleisen
mfelleisen merged commit 6f42afa into racket:master Sep 30, 2026
1 check passed
@samth
samth deleted the random-within branch September 30, 2026 22:26
@shhyou

shhyou commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

Would it be better if there is a version bump & history notes?

;; with the same freshly-seeded pseudo-random generator; like check-within,
;; the two results are compared up to the `within` tolerance.
(define (do-check-random-within test expected-thunk within src)
(error-check number? within CHECK-WITHIN-INEXACT-FMT #t)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The string CHECK-WITHIN-INEXACT-FMT says "check-within: ...". Probably need a new string here (or change the string to ~a and add a format).

(let ((expected (parameterize ([current-pseudo-random-generator rng])
(random-seed k)
(expected-thunk))))
(error-check (lambda (v) (not (procedure? v))) expected CHECK-WITHIN-FUNCTION-FMT #t)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto. CHECK-WITHIN-FUNCTION-FMT says "check-within cannot ...

@shhyou shhyou linked an issue Oct 7, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Need check-random-within

3 participants