;;;; lookup-table-test-body.scm (use test srfi-1) ;;; ;; (define (dict-alist-test al tst) (let ((foodat (alist-ref 'foo al)) (bazdat (alist-ref 'baz al)) (allen (length al))) (let ((tbl1 (alist->dict (list-copy al) tst))) (test-assert (dict? tbl1)) (test tst (dict-equivalence-function tbl1)) (test-assert (tst foodat (dict-ref tbl1 'foo))) (test-assert (begin (dict-delete! tbl1 'foo) #t)) (test-assert (not (dict-ref tbl1 'foo))) (test '() (dict-update! tbl1 'foo (lambda () '()))) (test '(1) (dict-update! tbl1 'foo void (lambda (x) (append x '(1))))) (test '() (dict-update-list! tbl1 'list)) (test '(1 2) (dict-update-list! tbl1 'list 1 2)) (let ((tbl2 (dict-update-dict! tbl1 'dict))) (test-assert (dict? (dict-ref tbl1 'dict))) (test tbl2 (dict-ref tbl1 'dict)) (test tbl2 (dict-update-dict! tbl1 'dict)) ) ) (let ((tbl (alist->dict (list-copy al) tst))) (test-assert (begin (dict-merge! tbl (alist->dict '((off . rab) (baz . pob)) tst)) #t)) (test (+ allen 1) (dict-count tbl)) (test foodat (dict-ref tbl 'foo)) (test 'pob (dict-ref tbl 'baz)) (test 'rab (dict-ref tbl 'off)) ) ) ) ;; (define (dict-ht-test) ; make sure not a hash-table rep initially (let ((tbl1 (make-dict equal? 0))) (do ([i 0 (add1 i)]) ([> i 54]) (if (odd? i) (dict-set! tbl1 i (->string i)) (dict-set! tbl1 (->string i) i))) (test 20 (dict-ref tbl1 "20")) (test-assert (begin (dict-delete! tbl1 "20") #t)) (test-assert (not (dict-ref tbl1 "20"))) (test-assert (begin (dict-merge! tbl1 (alist->dict '((foo . bar) (baz . bop)) equal?)) #t)) (test 'bop (dict-ref tbl1 'baz)) (test 'bar (dict-search tbl1 (lambda (key val) (eq? key 'foo)))) (test-assert (with-output-to-string (lambda () (dict-print tbl1)))) ) ) ;;; (newline) (print "** Alist Test (eq?) **") (newline) (dict-alist-test '((foo . bar) (baz . bop)) eq?) (newline) (print "** Alist Test (equal?) **") (newline) (dict-alist-test '((foo . bar) (baz . bop) (2 . 3)) equal?) (newline) (print "** HT Test () **") (newline) (dict-ht-test) (test-exit)