; ; Verifying the sfht package ; (require-extension test random-swb iset typeclass sfht) (import typeclass test random-swb iset sfht) (define (++ x) (fx+ 1 x)) (define (-- x) (fx- x 1)) (define min-key 1) (define max-key 100) (define (compute-assoc key) (cons key (++ key))) (let ((m (sfht-map 100000 0.0001 (lambda (i) (make-swb-random-state i (fx+ i 17))) swb:random! integer->bit-vector (compose (lambda (x) (if x 1 0)) bit-vector-ref) bit-vector-length))) (with-instance (( m)) (let ((t (empty))) (test-group "sfht test" (test-assert (empty? t)) (test-assert (zero? (size t))) (print "(compute-assoc 0) = " (compute-assoc 0)) (do ((i min-key (++ i))) ((> i max-key)) (test-assert (not (put! t i (cdr (compute-assoc i))))) (test (compute-assoc i) (get t i))) (test (++ (- max-key min-key)) (size t)) (test-assert (not (empty? t))) (test (compute-assoc (++ min-key)) (get t (++ min-key))) (test (compute-assoc (++ min-key)) (get t (++ min-key) #f)) (test-assert (not (get t (-- min-key) #f))) (clear! t) (test-assert (empty? t)) (test-assert (zero? (size t))) (do ((i max-key (-- i))) ((< i min-key)) (test-assert (not (put! t i (cdr (compute-assoc i))))) (test (compute-assoc i) (get t i) ) (test-assert (delete! t i))) (test-assert (zero? (size t))) (do ((i min-key) (j max-key) (direction #t (not direction))) ((< j i)) (cond (direction (test-assert (not (put! t i (cdr (compute-assoc i))))) (set! i (++ i))) (else (test-assert (not (put! t j (cdr (compute-assoc j))))) (set! j (-- j))))) (do ((i min-key (++ i))) ((> i max-key)) (test (compute-assoc i) (get t i) )) )) )) (test-exit)