constant-table-check.scm 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. ; Part of Scheme 48 1.9. See file COPYING for notices and license.
  2. ; Authors: Mike Sperber
  3. (define-test-suite constant-tables-tests)
  4. (define (check-table entries hash-function)
  5. (let ((table (make-constant-table entries hash-function)))
  6. (for-each (lambda (p)
  7. (check (constant-table-lookup table (car p))
  8. => (cdr p)))
  9. entries)))
  10. (define-test-case simple constant-tables-tests
  11. (check-table '((foo . 1) (bar . 2) (baz . 3) (bala . 4))
  12. symbol-hash))
  13. (define-test-case not-present constant-tables-tests
  14. (let ((table (make-constant-table '((foo . 1) (bar . 2) (baz . 3) (bala . 4))
  15. symbol-hash)))
  16. (check-that (constant-table-lookup table 'yellow)
  17. (is-false))
  18. (check-that (constant-table-lookup table 'balab)
  19. (is-false))
  20. (check-that (constant-table-lookup table 'foobar)
  21. (is-false))
  22. (check-that (constant-table-lookup table 'foobarbaz)
  23. (is-false))))
  24. (define-test-case bigger constant-tables-tests
  25. (let loop ((i 0) (entries '()))
  26. (if (= i 1000)
  27. (check-table entries symbol-hash)
  28. (loop (+ 1 i)
  29. (cons (cons (string->symbol (number->string i))
  30. i)
  31. entries)))))