File: constant-table-check.scm

package info (click to toggle)
scheme48 1.9-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 18,276 kB
  • ctags: 16,390
  • sloc: lisp: 88,906; ansic: 87,511; sh: 3,224; makefile: 766
file content (37 lines) | stat: -rw-r--r-- 1,155 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
; Part of Scheme 48 1.9.  See file COPYING for notices and license.

; Authors: Mike Sperber

(define-test-suite constant-tables-tests)

(define (check-table entries hash-function)
  (let ((table (make-constant-table entries hash-function)))
    (for-each (lambda (p)
		(check (constant-table-lookup table (car p))
		       => (cdr p)))
	      entries)))
	    
(define-test-case simple constant-tables-tests
  (check-table '((foo . 1) (bar . 2) (baz . 3) (bala . 4))
	       symbol-hash))

(define-test-case not-present constant-tables-tests
  (let ((table (make-constant-table '((foo . 1) (bar . 2) (baz . 3) (bala . 4)) 
				    symbol-hash)))
    (check-that (constant-table-lookup table 'yellow)
		(is-false))
    (check-that (constant-table-lookup table 'balab)
		(is-false))
    (check-that (constant-table-lookup table 'foobar)
		(is-false))
    (check-that (constant-table-lookup table 'foobarbaz)
		(is-false))))

(define-test-case bigger constant-tables-tests
  (let loop ((i 0) (entries '()))
    (if (= i 1000)
	(check-table entries symbol-hash)
	(loop (+ 1 i)
	      (cons (cons (string->symbol (number->string i))
			  i)
		    entries)))))