Add basic BST tests.
This commit is contained in:
parent
8d6ca4697c
commit
f9a2fdbcdf
1 changed files with 29 additions and 2 deletions
|
@ -22,6 +22,8 @@
|
|||
;;kvv-filter
|
||||
|
||||
;;bst-balance
|
||||
|
||||
util-bst-tests!
|
||||
)
|
||||
|
||||
(import scheme
|
||||
|
@ -29,8 +31,8 @@
|
|||
testing)
|
||||
|
||||
;; Unique tags
|
||||
(define TAG-BST (make-tag 'bst))
|
||||
(define TAG-KVV (make-tag 'kvv))
|
||||
(define TAG-BST (make-tag bst))
|
||||
(define TAG-KVV (make-tag kvv))
|
||||
|
||||
(define/doc (make-bst subtag EQ? <?)
|
||||
("Creates empty BST with given comparators")
|
||||
|
@ -60,10 +62,35 @@
|
|||
("Returns #t if given BST is empty.")
|
||||
(not (bst-root bst)))
|
||||
|
||||
;; Wrapper to setup comparators
|
||||
(define-syntax define-bst-proc
|
||||
(syntax-rules ()
|
||||
((_ EQ? <? (name bst . args) expr ...)
|
||||
(define (name bst . args)
|
||||
(let ((EQ? (bst-eq? bst))
|
||||
(<? (bst-<? bst)))
|
||||
expr ...)))))
|
||||
|
||||
;; Module self-tests
|
||||
(define (util-bst-tests!)
|
||||
(run-tests
|
||||
util-bst
|
||||
(test-equal? make-bst
|
||||
(make-bst 'fixnum eq? <)
|
||||
`(,TAG-BST
|
||||
. ((#f . 0)
|
||||
. (fixnum . (,eq? . ,<)))))
|
||||
(test-true bst?
|
||||
((bst? 'fixnum) (make-bst 'fixnum eq? <)))
|
||||
(test-false bst?
|
||||
((bst? 'fixnum) (make-bst 'string eq? <)))
|
||||
(test-false bst?
|
||||
((bst? 'fixnum) "string"))
|
||||
(test-true bst-empty?
|
||||
(bst-empty? (make-bst 'fixnum eq? <)))
|
||||
))
|
||||
|
||||
)
|
||||
|
||||
(import util-bst)
|
||||
(util-bst-tests!)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue