#lang scheme (require "checks.ss" "../dict.ss") (provide test-dict) (define test-dict (test-suite "dict.ss" (test-suite "dict-ref!" (test-ok (define d (make-hash)) (check-equal? (dict-ref! d 1 'one) 'one) (check-equal? (dict-ref! d 1 'uno) 'one) (check-equal? (dict-ref! d 2 (lambda () 'two)) 'two) (check-equal? (dict-ref! d 2 (lambda () 'dos)) 'two)) (test-bad (dict-ref! '([1 . one] [2 . two]) 1 'uno))) (test-suite "dict-ref/check" (test-ok (check-equal? (dict-ref/check '([1 . one] [2 . two]) 1) 'one)) (test-bad (dict-ref/check '([1 . one] [2 . two]) 3))) (test-suite "dict-ref/identity" (test-ok (check-equal? (dict-ref/identity '([1 . one] [2 . two]) 1) 'one)) (test-ok (check-equal? (dict-ref/identity '([1 . one] [2 . two]) 3) 3))) (test-suite "dict-ref/default" (test-ok (check-equal? (dict-ref/default '([1 . one] [2 . two]) 1 '?) 'one)) (test-ok (check-equal? (dict-ref/default '([1 . one] [2 . two]) 3 '?) '?))) (test-suite "dict-ref/failure" (test-ok (define x 7) (define (f) (set! x (+ x 1)) x) (check-equal? (dict-ref/failure '([1 . one] [2 . two]) 1 f) 'one) (check-equal? x 7) (check-equal? (dict-ref/failure '([1 . one] [2 . two]) 3 f) 8) (check-equal? x 8))) (test-suite "dict-has-key?" (test-ok (check-equal? (dict-has-key? '([1 . one] [2 . two]) 1) #t)) (test-ok (check-equal? (dict-has-key? '([1 . one] [2 . two]) 3) #f))) (test-suite "dict-domain" (test-ok (check-equal? (dict-domain '([1 . one] [2 . two])) '(1 2)))) (test-suite "dict-range" (test-ok (check-equal? (dict-range '([1 . one] [2 . two])) '(one two)))) (test-suite "dict-union" (test-ok (dict-union '([1 . one] [2 . two]) '([3 . three] [4 . four])) '([4 . four] [3 . three] [1 . one] [2 . two]))) (test-suite "dict-union!" (test-ok (define d (make-hash)) (dict-union! d '([1 . one] [2 . two])) (dict-union! d '([3 . three] [4 . four])) (check-equal? (hash-copy #hash([1 . one] [2 . two] [3 . three] [4 . four])) d))) (test-suite "dict/c")))