test new sort, test stableness

svn: r2568
This commit is contained in:
Eli Barzilay 2006-04-01 08:52:31 +00:00
parent 89de8a2e02
commit f7c14a5b67

View File

@ -57,9 +57,32 @@
(err/rt-test (assf string? '((1) (2) (3) . 4)) exn:application:mismatch?)
(test '("a" "b" "c" "c" "d" "e" "f")
quicksort
sort
'("d" "f" "e" "c" "a" "c" "b")
string<?)
(let ()
(define (random-list n)
(let loop ([n n] [r '()])
(if (zero? n) r (loop (sub1 n) (cons (random 1000000) r)))))
(define (test-sort sort len times)
(or (zero? times)
(and (let* ([rand (random-list len)]
[sorted (sort rand <)]
[same (sort rand (lambda (x y) #f))])
(and (= (length sorted) (length rand))
;; sorted?
(andmap <=
(reverse! (cdr (reverse sorted)))
(cdr sorted))
;; stable?
(equal? rand same)))
(test-sort sort len (sub1 times)))))
(test #t test-sort sort 1 10)
(test #t test-sort sort 2 10)
(test #t test-sort sort 10 100)
(test #t test-sort sort 100 100)
(test #t test-sort sort 1000 100))
(let ([s (let loop ([n 1000])
(if (zero? n)
'()