(declare (usual-integrations))
\f
-(define (make-template name pattern)
- (make-predicate-template name pattern (lambda args args any-object?)))
-
(define-test 'parametric-predicate-one-parameter
(lambda ()
(let ((pattern '((? base))))
- (let* ((template (make-template 'template pattern))
+ (let* ((template
+ (make-predicate-template 'template pattern make-flat-test))
(constructor (predicate-template-constructor template)))
(test-template-operations template 'template pattern)
(define-test 'parametric-predicate-two-parameters
(lambda ()
(let ((pattern '((?* domains -) (? base))))
- (let* ((template (make-template 'template pattern))
+ (let* ((template
+ (make-predicate-template 'template pattern
+ make-function-like-test))
(constructor (predicate-template-constructor template)))
(test-template-operations template 'template pattern)
(define-test 'covariant-ordering
(lambda ()
- (let* ((template (make-template 'foo '((? a))))
+ (let* ((template
+ (make-predicate-template 'template '((? a)) make-flat-test))
(constructor (predicate-template-constructor template)))
(let ((p1 (constructor (disjoin string? symbol?)))
(p2 (constructor string?))
\f
(define-test 'contravariant-ordering
(lambda ()
- (let* ((template (make-template 'foo '((? a -))))
+ (let* ((template
+ (make-predicate-template 'template '((? a -)) make-flat-test))
(constructor (predicate-template-constructor template)))
(let ((p1 (constructor (disjoin string? symbol?)))
(p2 (constructor string?))
(define-test 'mixed-ordering
(lambda ()
- (let* ((template (make-template 'foo '((? a -) (? b))))
+ (let* ((template
+ (make-predicate-template 'template '((? a -) (? b)) make-flat-test))
(constructor (predicate-template-constructor template)))
(let ((p1 (constructor (disjoin string? symbol?)
(disjoin string? symbol?)))
(assert-simple-error (lambda () (match-numbers '((?* a) (? b -)) '(1 2))))
(assert-simple-error (lambda () (match-numbers '((?+ a -) (? b)) '(1 2))))))
+(define (make-flat-test . predicates)
+ (lambda (object)
+ (and (list? object)
+ (= (length predicates) (length object))
+ (every (lambda (predicate object)
+ (predicate object))
+ predicates
+ objects))))
+
+(define (make-function-like-test domains codomain)
+ (lambda (object)
+ (and (pair? object)
+ (codomain (car object))
+ (list? (cdr object))
+ (= (length domains) (length (cdr object)))
+ (every (lambda (domain object)
+ (domain object))
+ domains
+ objects))))
+
(define (test-template-operations template name pattern)
(assert-true (predicate-template? template))
(assert-false (predicate? template))
(assert-eqv (predicate-template-name template) name)
- (assert-equal pattern (predicate-template-pattern template))
+ (assert-equal (predicate-template-pattern template) pattern)
(assert-lset= eq?
(predicate-template-parameter-names template)
(map template-pattern-element-name pattern))