test new sort, test stableness
svn: r2568
This commit is contained in:
parent
89de8a2e02
commit
f7c14a5b67
|
@ -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)
|
||||
'()
|
||||
|
|
Loading…
Reference in New Issue
Block a user