From f35be3c83e77370ea765c9b8b6866e260f74ec00 Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Fri, 2 Nov 2012 17:35:39 +0000 Subject: [PATCH] New test case for weak hash tables (doesn't pass yet). Copied from Perforce Change: 180291 ServerID: perforce.ravenbrook.com --- mps/example/scheme/test-weak.scm | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 mps/example/scheme/test-weak.scm diff --git a/mps/example/scheme/test-weak.scm b/mps/example/scheme/test-weak.scm new file mode 100644 index 00000000000..1805c11e475 --- /dev/null +++ b/mps/example/scheme/test-weak.scm @@ -0,0 +1,30 @@ +;;; test-weak.scm -- weak hashtable tests for the MPS toy Scheme interpreter + +(load "test-common.scm") + +;; First, check that all the hash tables behave as expected. + +(define (ht-test ht-fun hash-fun cmp-fun key) + (let* ((ht (ht-fun hash-fun cmp-fun)) + (f (lambda (n) (equal? (hashtable-ref ht (key n) #f) n))) + (g (lambda (n) (hashtable-set! ht (key n) n))) + (r (range 25))) + (for-each g r) + (all (map f r)))) + +(define (stringify n) (make-string n #\b)) +(check '(ht-test make-hashtable string-hash string=? stringify) #t) +(check '(ht-test make-weak-key-hashtable string-hash string=? stringify) #t) +(check '(ht-test make-weak-value-hashtable string-hash string=? stringify) #t) +(check '(ht-test make-doubly-weak-hashtable string-hash string=? stringify) #t) +(define (symbolize n) (string->symbol (make-string n #\a))) +(check '(ht-test make-hashtable eq-hash eq? symbolize) #t) +(define (identity n) n) +(check '(ht-test make-hashtable eqv-hash eqv? identity) #t) + + +;; The MPS doesn't actually guarantee promptness of splatting. But we +;; have to test it somehow! + +(write-string "All tests pass.") +(newline)