; Author: Juergen Lorenz ; ju (at) jugilo (dot) de (require 'tuples) (import tuples) ;;; (run xpr0 xpr1 ...) ;;; ------------------- (define (run . xprs) (let loop ((xprs xprs)) (if (null? xprs) (print "All tests passed!") (if (car xprs) (loop (cdr xprs)) (error 'run "#### Some test failed! ####"))))) (let ( (tup (tuple 0 1 2 3)) (sg (single 1)) (cpl (couple 1 2)) (trp (triple 1 2 3)) ) (run (equal? (tuple->list tup) '(0 1 2 3)) (eq? (tuple? tup) #t) (= (tuple-length tup) 4) (= (tuple-ref tup 2) 2) (eqv? (tuple-find tup 2 =) 2) (eqv? (tuple-find tup 4 =) #f) (equal? (tuple->list (tuple-map add1 tup)) '(1 2 3 4)) (equal? (let ((result '())) (tuple-for-each (lambda (x) (set! result (cons x result))) tup) result) '(3 2 1 0)) (equal? (tuple->list (tuple-copy tup)) '(0 1 2 3)) (equal? (tuple->list (tuple-copy tup 2 3)) '(2)) (equal? (tuple->list (tuple-copy tup 2)) '(2 3)) (equal? (tuple->list (tuple)) '()) (eq? ((tuple-of? even?) (tuple)) #t) (eq? ((tuple-of? even?) (tuple 1 2 3)) #f) (eq? ((tuple-of? even?) (tuple 2 4 6)) #t) (eq? (tuple? 3) #f) (= (tuple-length (tuple)) 0) (eqv? (tuple-find (tuple) 3 =) #f) (equal? (tuple->list (tuple)) '()) (equal? (tuple->list (list->tuple '(0 1 2))) '(0 1 2)) (equal? (tuple->list (list->tuple '())) '()) (equal? (tuple->list (tuple-map add1 (tuple))) '()) (equal? (tuple->list (tuple-append (tuple 0 1 2) (tuple 3) (tuple 4 5))) '(0 1 2 3 4 5)) (equal? (tuple->list (tuple-append)) '()) (eq? (empty? (empty)) #t) (eq? (empty? (tuple 1 2)) #f) (eq? (empty? 3) #f) (eq? (single? (empty)) #f) (eq? (single? (single 1)) #t) (eq? (single? 3) #f) (= (single-ref sg) 1) (= (begin (single-set! sg 2) (single-ref sg)) 2) (eq? (couple? cpl) #t) (eq? (triple? cpl) #f) (= (couple-left cpl) 1) (= (couple-right cpl) 2)) (eq? (couple? trp) #f) (eq? (triple? trp) #t) (= (triple-left trp) 1) (= (triple-middle trp) 2) (= (triple-right trp) 3))