;;; Procedures for testing
;;; John David Stone
;;; Department of Computer Science
;;; Grinnell College
;;; created July 8, 1998
;;; last revised January 12, 2017
(define-library (support testing-procedures)
(export integer->char char->integer real? exact-integer? exact-rational?
true? match? source? display newline guard error-object? raise)
(import (scheme base)
(scheme write))
(begin
;; ===== exact-rational? ==============================================
;; The exact-rational? predicate determines whether its argument is an
;; exact rational number.
(define exact-rational?
(lambda (something)
(and (rational? something)
(exact? something))))
;; ===== true? ========================================================
;; The true? predicate determines whether its argument is specifically
;; the affirmative Boolean value, #t.
(define (true? something)
(eq? something #t))
;; ===== match? =======================================================
;; The match? predicate takes at least one argument, of which the first
;; must be a binary equivalence predicate, and returns a procedure that
;; takes any number of arguments and matches them, one by one, against
;; the remaining values that match received, using the equivalence
;; predicate as the matching criterion.
(define (match? equivalent? . expected)
(lambda actual
(let loop ((rest-of-actual actual)
(rest-of-expected expected))
(if (null? rest-of-actual)
(null? rest-of-expected)
(and (not (null? rest-of-expected))
(equivalent? (car rest-of-actual)
(car rest-of-expected))
(loop (cdr rest-of-actual) (cdr rest-of-expected)))))))
;; ===== source? ======================================================
;; There is no satisfactory way to test whether a given value is a
;; source, in the implementation that we're using. However, such a
;; value must at least be a procedure, so the following definition
;; comes as close as we can get, and never delivers a false negative.
(define source? procedure?)))
;;; copyright (C) 2011, 2016 John David Stone
;;; This program is free software. You may redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation -- either version 3 of the License, or (at
;;; your option) any later version. A copy of the GNU General Public
;;; License is available on the World Wide Web at
;;;
;;; http://www.gnu.org/licenses/gpl.html
;;;
;;; This program is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY -- without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;;; General Public License for more details.