(import (scheme base) (only (csc testing) define-test errorf) (csc sort)) (define-test (test-sort t) (define-record-type (test-case desc xs want) test-case? (desc desc) (xs xs) (want want)) (let ((tests (list (test-case "ten elem" '(9 4 5 100 3 2 4 6 0 -2) '(-2 0 2 3 4 4 5 6 9 100)) (test-case "empty" '() '()) (test-case "singleton" '(1) '(1)) (test-case "two" '(2 1) '(1 2)) (test-case "reversed" '(20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1) '(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20)) (test-case "already sorted" '(1 2 3 4 5 6 7 8 9 10) '(1 2 3 4 5 6 7 8 9 10))))) (for-each (lambda (tc) (let ((got (sort (lambda (x1 x2) (< x1 x2)) (xs tc)))) (unless (equal? got (want tc)) (errorf t "(sort {}) = {}, want {}." (xs tc) got (want tc))))) tests)))